@davoodmehraban89 / Aram-2 Mirror · read-only / commits / 06629bf
Fork 0

Mirrored from https://github.com/davoodmehraban89/Aram.git

Synced Dec 3, 18:15 UTC

docs(mapping): specify fail-closed read-only bulk review semantics

davoodmehraban89 committed Oct 30, 2026 at 19:02 UTC 06629bfa15fcffc05b87da3c3a772a2efc438956
1 file changed +38
docs/superpowers/specs/2026-10-30-gate3-mapping-batch-review.md new
+38
@@ -0,0 +1,38 @@
1 +# Gate 3 — read-only batch Mapping change classification
2 +
3 +**Proposed Draft PR #51**, child of **unmerged Draft PR #50** at exact SHA `f79947a8624adbd8e84c3f8247ac3ca4a7bd4240`; ultimately depends on Draft #26 and accepted base `source-data-cleanup@7dc864fd032f0c4ae4d650d89304a01286a6d914`.
4 +
5 +**Problem:** a five-column Excel import currently calls `save_mapping_rule` directly, and a manual preview only evaluates one mapping. Bulk review must not silently use first/last matching row or apply one good row while hiding another conflicting/invalid row. This PR introduces a READ-ONLY, provider-neutral proposal classifier, **not** an approved Excel importer or an authorization change.
6 +
7 +## Canonical input, classification and safe boundary
8 +
9 +`ProposedMappingRow` carries explicit source locator, rule key, literal account code, actual in-scope note ID, mapping type, and expected persisted base version. Future Excel/manual/connector adapters must provide a validated row locator and exact scope; no source system table/column is invented.
10 +
11 +A batch preview is bounded to **1–10,000** typed rows with unique, nonblank, trimmed, bounded source locators. It validates the year ID and requires the specified year to be Draft. It checks that no related financial-domain ORM edits are pending; uses `Session.no_autoflush` and does not commit or write.
12 +
13 +For each scoped `rule_key`:
14 +- **new:** no saved version; proposed version one; captures full old/new preview.
15 +- **changed:** an existing rule is modified with exact current expected version; shows persisted old values and next proposed version.
16 +- **unchanged:** current persisted rule is exactly the proposed content; no new version is produced, and no fake review decision is counted.
17 +- **coalesced:** repeated identical input for the same rule key, including expected version; preserve the original and additional row locators, count at most one new/changed proposal.
18 +- **conflict:** two or more rows for a rule key have different target/account/mapping-type/expected-base content; **every conflicting row** receives a conflict result. No silent first/last wins.
19 +- **invalid:** nonexistent or stale account/note, cross-year target, wrong expected version, invalid input, or an identical repeat of an invalid first proposal.
20 +
21 +Any conflict or invalid item sets `ready_for_review=False` **for the entire batch**, even if other rows are valid. An entirely unchanged batch is not an approvable change. A read-only preview never applies rules; omitted existing rules are not deletion instructions.
22 +
23 +Outputs include per-row reason, stable locators, optional `MappingChangePreview`, deterministic review checksum and counts. This checksum is UNSIGNED: no actor identity, audit event, authenticated review, verified authorization, transaction lock or approval is encoded. An external apply service would still need transactionally re-validate the entire batch; there is deliberately **no apply function** here.
24 +
25 +## Known limits and gates
26 +
27 +- `mapping_change_preview.py` raises a typed `MappingNoChange` (subclass of the existing validation error) for valid no-ops; avoids unsafe error-message parsing. Existing public error semantics are preserved.
28 +- Current `mapping_excel.import_mapping_workbook` is **unchanged** and can still save without this batch preview. It must be routed through a future approved common proposal/apply service; this PR does not claim bypass elimination.
29 +- Source locator labels are presentation-only; an input adapter must attest actual source file SHA, sheet, and row. This batch preview is not a financial-source reconciliation.
30 +- Different rule keys that overlap on a ledger account are not resolved by rule-key duplicate detection. Accounting owners must approve full account hierarchy, source predicate, multi-match precedence and note/subnote semantics before such overlap can be safely classified.
31 +- The method is read-only but does not provide a cross-database transactionally consistent snapshot under all isolation levels. External SQL writers may mutate facts after preview; Issue #43 requires provider-level enforcement and concurrency controls.
32 +- Genuine C1/C2/C3 independent reviewers and branch protection remain Issue #39; full durable Draft→Reviewed→Approved and audit remain Issue #49. Do not merge Draft #51 until parents and reviews are accepted.
33 +
34 +## Acceptance harness
35 +
36 +Synthetic cases: first-time batch without writes; identical duplicates coalesced; conflicting duplicates poison every row; valid old/new diff and no-op; stale version rejects only affected row and blocks all approval; foreign-year and unknown accounts; obsolete same-year target; all-noop no approval delta; deterministic digest and unrelated no-autoflush; pending dirty MappingRule rejected; empty/malformed/oversized batch; repeated locator; Approved/Locked year; malformed row fail closed. Exact-final-SHA remote GitHub CI, migration round-trip and compile needed. Do not read/change canonical financial XLSX/PDF, `data/`, customer databases, migrations, dependencies, workflows or releases.
37 +
38 +Rollback: close this unmerged Draft, or use an independently reviewed revert after authorized merge.