fix(kernel): legal entity names and codes are personal data, kept by law unless the entity is the org (#1312) #1326
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #1326"
general
weight: 0.35
claude[bot]
Closes #1312
What
crove_kernel.legal_entity.nameis registered in the personal-data registry (kindname).legal_entity.nameandlegal_entity.tax_codearekeep_legal, with a per-row override: the org's default entity (is_default) stayskeep_org. A registry entry may now carryoverride: { when, handling, reason }, applied byrowHandling()to each matched row.kernel.personal_data.find) reports each row's own handling and reason, so a household found by its 12-digit code (its owner's national ID number) shows as kept by law, with its name in the exported row, and the default entity as the org's own.kernel.personal_data.erase) does not change entities (both handlings keep). Itskeptlist now groups by column and reason, so rows of one column kept for different reasons are reported separately; the audit row still holds counts per column only.docs/runbooks/personal-data-requests.mdlists legal entities under "Kept by law".Not changed
tools/ci/protected-paths.mjs: none), no invariant file. The name pattern of the invariant registry test does not match a barename, so it needs no change.Decisions
Tests (local, Windows, own PostgreSQL 17)
apps/kernel/test/personal-data.test.ts(new, unit): registry entries,rowHandlingfor default and non-default rows, the 12-digit probe.apps/kernel/test/personal-data.db.test.ts: a household entity (12-digit code) and a non-default company found askeep_legalwith their names, not seen from another org; the default entity's code found askeep_orgnext to the tenant's; erasing by the ID number keeps the entity and reports it; every override names a boolean column. 7/7 passed;legal-entities.db.test.tspassed.pnpm lint,pnpm typecheck,pnpm docs:checkpassed.pnpm vitest run --project unit: only the known Windows-only failures (STATUS_FILE,C:\paths, backup lib shell, i18n runtime, migrate copies);mst-fixture-guardpasses with a checksum-invalid synthetic code.--no-file-parallelism: 1036 passed, 2 failed inroute-coverage.test.ts(STATUS_FILE, Windows only).🤖 Generated with Claude Code
---
<!-- dos-pr-summary -->
📌 TL;DR
This PR refines the personal data erasure and search logic to correctly handle legal entities, distinguishing between the organization's default entity (kept as org data) and external entities like households or clients (kept by law). It introduces a row-level handling override mechanism to ensure that 12-digit national ID numbers linked to household businesses are preserved with appropriate legal reasoning during data subject requests.
🎯 Type of Change
🔍 Changes Walkthrough
| File | Summary of Changes |
| :--- | :--- |
|
packages/kernel/src/personal-data.ts| Core logic update. Addedoverridesupport toPersonalDataColumnto allow row-specific handling (e.g.,is_defaultflag). Updatedlegal_entitycolumns to usekeep_legalby default with an override tokeep_orgfor the default entity. RefactoredfindPersonalDataandpersonalDataEraseto applyrowHandlingper row and group "kept" results by both column and reason. ||
apps/kernel/test/personal-data.test.ts| New unit tests verifying the registry configuration for legal entities, therowHandlinglogic for default vs. non-default entities, and the probe normalization for 12-digit ID numbers. ||
apps/kernel/test/personal-data.db.test.ts| Integration tests verifying end-to-end behavior: finding legal entities by ID number, ensuring cross-org isolation, verifying that erasure keeps legal entities with the correct "kept by law" reason, and validating that override columns exist in the database schema. ||
docs/runbooks/personal-data-requests.md| Updated documentation to clarify that legal entities (clients, households) are kept by law, while the default entity is treated as the org's own data. |📊 Architectural Flow
<!-- /dos-pr-summary -->