Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 4, 18:00 UTC
codex/aram-same-flush-fiscal-lock-20261030
add-index-html-10623938925177053894
arena/094f314c-aram
arena/2d4eda07-aram
chatgpt-phase1b2-autopilot
codex/adr-future-connectors-pi-v1
codex/aram-account-note-source-trace-20261031
codex/aram-actions-node24-maintenance-20261031
codex/aram-analyst-review-workbook-20261031
codex/aram-bs-candidate-statement-20261031
codex/aram-cash-flow-direct-candidate-20261031
codex/aram-clean-reference-year-integrity-20261030
codex/aram-cross-statement-controls-20261031
codex/aram-equity-changes-candidate-20261031
codex/aram-five-statement-cli-20261031
codex/aram-five-statement-integration-20261031
codex/aram-five-statement-orchestrator-20261031
codex/aram-gate3-coverage-target-guard-20261030
codex/aram-gate3-hidden-xlsx-guard-20261030
codex/aram-gate3-integration-validation-20261030
codex/aram-gate3-mapping-change-preview-20261030
codex/aram-gate3-stale-note-guard-20261030
codex/aram-income-statement-candidate-20261031
codex/aram-manifest-referential-integrity-20261031
codex/aram-mapping-source-parser-20261101
codex/aram-multidimensional-mapping-20261101
codex/aram-multistatement-mapping-20261031
codex/aram-pipeline-manifest-schema-20261031
codex/aram-readonly-mapping-coverage-20261031
codex/aram-reconciliation-review-gate-20261031
codex/aram-same-flush-fiscal-lock-20261030
codex/aram-synthetic-windows-demo-20261031
codex/aram-trial-balance-diagnostic-20261031
codex/aram-windows-background-detail-search-20261031
codex/aram-windows-detail-review-20261031
codex/aram-windows-five-statement-pilot-20261031
codex/aram-windows-statement-figures-20261031
codex/gate-2a-pilot-workbook
codex/gate-2a-pilot-workbook-6864754244772568979
codex/gate3-authenticated-principal-boundary-20261030
codex/gate3-authored-draft-staging-20261030
codex/gate3-carry-forward-preview-20261023
codex/gate3-draft-staging-audit-20261030
codex/gate3-mapping-batch-freshness-20261030
codex/gate3-mapping-batch-review-20261030
codex/gate3-mapping-core
codex/gate3-mapping-coverage-20261023
codex/gate3-mapping-excel-20261023
codex/gate3-note-mapping-review-20261023
codex/gate3-signed-year-scope-20261030
codex/gate3-unapproved-proposal-storage-20261030
codex/payvast-mapping-discovery-20261023
codex/phase-2a-backend-foundation
codex/phase-2b-post-merge-record
codex/phase-2b-source-registration
codex/phase-2b-source-registration-12955190277775369594
codex/post-gate2a-control-reconciliation
codex/post-pr18-acceptance-record
codex/project-control-foundation
codex/t1-repo-hygiene-20261023
codex/t2-ci-hardening-20261023
codex/t3-explicit-migrations-20261023
codex/t6a-readonly-diagnostics-20261023
codex/v1-01-safety-gate-hardening
codex/v1-year-isolation-followup-20261023
codex/windows-native-pilot-shell-20261030
dependabot/github_actions/actions/setup-node-6
dependabot/github_actions/actions/setup-python-7
dependabot/github_actions/actions/upload-artifact-7
dependabot/npm_and_yarn/frontend/eslint-plugin-react-hooks-7.1.1
dependabot/npm_and_yarn/frontend/vite-8.4.0
dependabot/npm_and_yarn/frontend/vitest-5.1.2
docs/aram-master-control-plan-20261111
docs/aram-roadmap-dashboard-20261030
docs/financial-statement-reconciliation-1402-1404-20261110
feat/gate3-governed-mapping-20261101
feat/gate3-package9-1-security-20261103
feat/gate3-package9-isolated-20261103
fix/password-unicode-validation-20261111
governance/aram-5-1-3-controls-20261030
governance/role-based-operating-model
jules-1168663913887856558-73b8a885
jules-gate-2b-mapping-workflow-foundation-4137724387867065330
phase-1b1-audit-report-7365389436990903239
phase-2a-backend-foundation-10237597358138521261
phase1b2-postmerge-metadata-fix
refactor/drg-parent-year-id-15088443704684163304
source-data-cleanup
| 1 | # Fiscal-year Unit-of-Work and Graph Integrity — 2026-10-30 |
| 2 | |
| 3 | - **Status:** Proposed implementation, pending independent review. |
| 4 | - **Authority:** [Issue #36](https://github.com/davoodmehraban89/Aram/issues/36). |
| 5 | - **Exact base:** unmerged [PR #32](https://github.com/davoodmehraban89/Aram/pull/32) `codex/v1-year-isolation-followup-20261023@28d1c57882ec20fc17c2c133bbe62ff56e12973f`. |
| 6 | - **Candidate:** [Draft PR #35](https://github.com/davoodmehraban89/Aram/pull/35), consolidated from initial separate Drafts #35 and #41; #41 is superseded by this candidate. |
| 7 | - **Accepted branch:** `source-data-cleanup@7dc864fd032f0c4ae4d650d89304a01286a6d914`, not modified. |
| 8 | |
| 9 | ## Purpose and threat model |
| 10 | |
| 11 | Financial-year integrity is not merely a row-level constraint. SQLAlchemy's `Session.before_flush` inspects pending changes before SQL has been emitted, and persisted status may still be Draft even though the in-memory FiscalYear object is already Approved. Separately, moving a fiscal-year parent can invalidate already-persisted clean mapping/statement dependencies that are absent from the Session's dirty set. |
| 12 | |
| 13 | These are reproduced defects in an **ORM application boundary**. This change does **not** claim to implement database-level invariants, row locks, concurrent-session isolation, custom permissions, PostgreSQL/SQL Server triggers, external writer restrictions, or customer data validation. Those require separate scoped designs and provider-specific evidence. |
| 14 | |
| 15 | ## Invariant S1 — Same-flush approval is atomic |
| 16 | |
| 17 | When an existing FiscalYear transitions Draft → Approved in a Session, no creation, modification or deletion of an associated year-owned record, `NoteRow`, or `StatementLine` is permitted in that same flush. Modification of the associated Company is also forbidden. The same rules apply to Locked status. |
| 18 | |
| 19 | Resolve **proposed effective status** from `Session.new | dirty | deleted` for a matching FiscalYear identity, then consult persisted status for all other years. A database query alone is inadequate before SQLAlchemy flushes the transition. |
| 20 | |
| 21 | - **Reject:** Draft → Approved plus edit of AccountVersion, SourceDocument, NoteDefinition, FinancialStatement, MappingRule, NoteRow or StatementLine in one commit. |
| 22 | - **Reject:** Draft → Approved plus new SourceDocument, or an existing Company change in the same transaction. |
| 23 | - **Permit:** ordinary Draft edits committed separately before an approval-only transition, and valid Draft→Approved/Approved→Locked transitions without concurrent data mutation. |
| 24 | - **Rollback:** rejected transaction must persist neither the status transition nor the affected record change. |
| 25 | |
| 26 | ## Invariant S2 — Re-evaluate clean graph references |
| 27 | |
| 28 | When a **persisted** `NoteDefinition.year_id` changes between Draft years, inspect persisted `MappingRule` and `StatementLine` rows whose target_note_id points to it, even if they are not in `Session.dirty`. Re-evaluate each dependent's effective in-session mapping year or financial-statement year against the effective target note's year. |
| 29 | |
| 30 | When a **persisted** `FinancialStatement.year_id` changes between Draft years, inspect persisted linked StatementLine rows, even when unchanged; reject any non-null target note whose effective year disagrees with its financial statement's effective year. |
| 31 | |
| 32 | - **Reject:** moving a Draft note while a clean mapping or note-linked statement line would remain tied to the old year, whether the years belong to the same Company or different Companies. |
| 33 | - **Reject:** moving a Draft statement while a clean note-linked statement line remains tied to a note in the old year. |
| 34 | - **Permit:** moving a previously unreferenced Draft note; moving a Draft statement whose existing lines have no target note. |
| 35 | - **Permit when internally consistent:** coordinated in-Session movement of a Draft note and the mapping owner, coordinated movement of a Draft note and statement parent, or an explicit reference retarget to a different note in the original Draft year. |
| 36 | - **Reject** any outcome still containing cross-year mapping/statement-note references. If the requested accounting operation cannot be independently reviewed and justified, prefer a **separate authorized transaction**: detach/review old references, commit, then move/rebuild the parent; do not silently carry hidden dependencies. |
| 37 | - **Rollback:** database reload after rejected commit shows original fiscal years and persistent references. |
| 38 | |
| 39 | ## Implementation boundary |
| 40 | |
| 41 | Use one existing synchronous SQLAlchemy `before_flush` event. Add narrowly scoped helper(s) to inspect pending status and affected persisted references. Do **not** mutate accounting data, auto-repair links, rewrite note numbers, infer mapping decisions, or make an unauthorized mapping transfer. Parent graph checks run only when a persisted note/statement has actually changed `year_id`. |
| 42 | |
| 43 | This is application-level prevention within a Session using the ORM. It does not eliminate race conditions: another Session can change the linked rows after the check without database enforcement. The target-note relations may be unindexed in the current schema; synthetic-scale performance profiling and an independently reviewed migration may be necessary before deployment. |
| 44 | |
| 45 | ## Acceptance tests and evidence |
| 46 | |
| 47 | - RED: run newly added regressions on unchanged PR #32; demonstrate nine same-flush bypass failures and six clean-reference bypass failures (the latter reproduced after first fix; all failures must be for the intended missing ValueError). |
| 48 | - GREEN: full test suite verifies allowed Draft operations as well as prohibited transitions, rollback and relationship isolation. Final-head GitHub Actions must show all tests, isolated Alembic upgrade/downgrade and compileall success. |
| 49 | - Exact changed-file allowlist: `backend/src/aram_backend/models.py`, `backend/tests/test_models.py`, this spec, its companion plan, `docs/PROJECT_LOG.md`, `docs/handoff/LATEST_HANDOFF.md`. |
| 50 | - No `PROJECT_STATUS.md` change relative to parent #32; no migration, database, `data/`, canonical XLSX/PDF, dependency, workflow, binary, secret or release change. |
| 51 | - All source-to-report financial integrity and owner accounting approvals beyond these invariants remain unverified. |
| 52 | |
| 53 | ## Reviewer separation and release safety |
| 54 | |
| 55 | C1 technical/security, C2 financial/data integrity, and C3 acceptance/release must be three separate, verifiable, non-author reviewer identities. An author-run three-pass audit is not independent evidence. The proposal stays Draft/unmerged when any gate is missing. Rebase on an **accepted** parent SHA only after #32 itself passes its acceptance gates; then rerun all checks. |
| 56 | |
| 57 | Rollback before merge: close Draft PR. After a properly authorized merge: independently reviewed revert PR; never force-push, modify protected canonical financial sources, or misstate unmerged code as accepted. |