Skip to content

fix(close): freeze hard-close trial balance evidence - #53

Draft
seonghobae wants to merge 226 commits into
feat/reconciliation-exception-resolution-commandfrom
fix/trial-balance-snapshot-immutability
Draft

fix(close): freeze hard-close trial balance evidence#53
seonghobae wants to merge 226 commits into
feat/reconciliation-exception-resolution-commandfrom
fix/trial-balance-snapshot-immutability

Conversation

@seonghobae

@seonghobae seonghobae commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Accounting-control scope

trial_balance_snapshot / trial_balance_line are retained Period Close evidence. This Draft owns the PostgreSQL Period Close foundation for one-population identity, retained-evidence immutability, tenant/legal-entity/book/reporting-currency/chart-account scope, exact monetary conservation, close-command authority, journal-population freshness, open-period posting concurrency, commit-time snapshot/status pairing, and historical posted role/account identity. Accounting Information Platform remains authoritative for journal/account/period/posting/reconciliation/financial-control truth. Billing and other foreign systems gain no posting, close, policy, reconciliation, or reporting authority.

Live stack authority — 2026-09-09

Current PR head is 9c3dba6f12aa58062faa6ba11537aabef91486d8. The stored GitHub base is still feat/reconciliation-exception-resolution-command@6f81b258de94cf14d6af4258173d5eabc8ebad26, so this PR is Draft and mergeable=false.

The live prerequisite is no longer the body-pinned historical #43/#47 generation. Current stack authority is:

#29@12e1a4bb9d8de5e4b6c72e2893107b07c515416b -> #47@263e4ffb79607dccee715686d0aa451981c2eeb8 -> #53

#43 is merged history, not a separate live parent. #47 is Ready/mergeable with exact-head Accounting Foundation GREEN but still lacks a qualifying independent APPROVED review. Therefore #53 must not be prematurely retargeted/restacked. After #47 normally integrates into #29, derive the resulting parent exact head, read every intervening delta, then rebuild #53 as an ordinary non-force descendant and reacquire all current-head evidence. No predecessor check or review transfers.

Implemented Period Close foundation

Migrations 0029–0031 establish one retained trial-balance population per tenant/book/period, freeze retained header/line facts, own snapshot system time in PostgreSQL, enforce legal-entity -> accounting-book -> reporting-currency -> chart-account scope, and validate exact numeric(38,6) debit/credit/net conservation.

Migrations 0032/0033 protect journal-population freshness under REPEATABLE READ/SERIALIZABLE: ordinary open-period journals update one of 64 pre-existing fence rows and period transitions lock all 64 in deterministic order. Weak isolation fails closed. SQLSTATE 40001 is coordination failure, not accounting evidence; retry the complete immutable command from a fresh transaction.

Migration 0034 owns post-install book-period control materialization. New open periods and active books seed only literal open controls plus all 64 freshness rows. Missing non-open pairs remain absent. Shared fiscal_period.period_status_code is only a compatibility projection and is never substituted for per-book close authority. Runtime seeding requires the exact tenant binding while the migration-owner backfill remains a separate bounded path.

Migrations 0035/0036 enforce the bidirectional hard_closed <-> retained trial_balance_snapshot commit pair, including fail-closed upgrade preflight for legacy one-sided states under FORCE RLS. Migration 0037 requires soft-close command identity, immutable source payload hash, and source-journal-count evidence.

These controls are repository-owned DDD/database mechanisms; IFRS does not prescribe these PostgreSQL implementation details.

Historical account identity and close authority

The first temporal-authority repair moved historical revenue/expense classification from mutable current account_role_mapping to immutable posted journal_entry_line.account_role_code.

Real-PostgreSQL expiry/code-reuse REDs then established the stronger Entity boundary: Period Close must clear the exact immutable posted journal_entry_line.chart_account_id, not re-resolve a reused account code against the current catalog. Production candidate 3832cf72110ebc39d3978135400e0fb9378c34ac carries the posted account UUID only for AIS-generated historical P&L clearing lines; ordinary _insert_journal() continues to require an active account, retained earnings remains a current close-time policy destination, and Reporting projection completeness is not allowed to become a second hard-close authority. Snapshot evidence now binds the exact account Entity. Doctoring successor 7c75e05626fa8c7477089c1272bb43719d66bb17 records that boundary.

Current evidence-audit RED

Fresh review found one remaining identity gap in the closing-journal command evidence. _post_closing_journal() already carries historical_chart_account_ids into the actual closing journal, and _canonical_snapshot_hash() binds chart_account_id; however _canonical_closing_hash() still serializes only account code, role, exact amounts and line number. Two legally distinct historical account Entities that reuse the same code can therefore produce the same journal_proposal_record.source_payload_hash even though the actual clearing line is intentionally Entity-specific.

Exact RED head 9c3dba6f12aa58062faa6ba11537aabef91486d8 extends the real PostgreSQL code-reuse scenario and requires the stored closing-journal source hash to include the exact historical chart_account_id for historical P&L lines while excluding it from the current retained-earnings destination.

Selected narrow GREEN: pass the existing historical_chart_account_ids mapping into _canonical_closing_hash() and serialize chart_account_id only for mapped historical lines. Preserve canonical serialization, exact Decimal formatting, ordinary active-account admission, retained-earnings current mapping, snapshot-hash identity and the no-posting/no-close foreign-system boundary. Do not relax account admission globally or invent a second Reporting/Period Close authority.

Exact-head COMMENT review 5147490036 records this causal finding. Codex execution handoff 5592475501 failed before source work with connector response 5592476807 (Codex usage limits), so it produced no descendant and is not an active writer. Current source-writer fallback is /opencode comment 5592533532, continuing the same single-writer lane. It must re-read the live head, ordinary-adopt any intervening descendant, and never force-push/rebase.

Verification state

Current exact head 9c3dba6f12aa58062faa6ba11537aabef91486d8 has 0 pull-request workflow runs. This is not GREEN and not runner-queue evidence. The PR remains merge-conflicted against its stale stored parent. Preserve the checked-in RED and reacquire hosted Accounting Foundation, exact 100% production statement/branch coverage, repository contracts, security/SAST/dependency/package/SBOM/provenance/recovery evidence only after the stack is conflict-free.

Current inline review threads are resolved at source level, but resolved threads and COMMENT review do not substitute for exact-head GREEN or independent approval. Keep Draft. Do not merge, auto-merge, self-approve, bypass protection, manufacture status/no-op commits, force-push, destructively rebase, tag, or release while required evidence is absent or non-terminal.

Documentation and downstream ownership

Canonical CHANGELOG.md, docs/doctoring/STANDARD_TRACEABILITY.md, docs/product-technical-gap-baseline.md, README/public product wording and their contracts remain PR #37's single-writer responsibility. #37 must reconstruct the durable invariant only after protected integration: effective-dated account-role/chart-account changes cannot retrospectively change, strand, redirect, or provenance-alias immutable historical account identity used by Period Close.

PR #52 consumes this foundation only after normal integration and non-force restack. Reporting must not synthesize close control/snapshot/freshness/currency/calculation authority, infer book state from shared fiscal_period, reconstruct historical account identity from current catalogs when immutable journal/snapshot evidence exists, or veto a valid hard close because a buyer projection is incomplete.

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

이번 변경은 trial-balance snapshot의 단일성·불변성·범위·산술 검증을 추가합니다. 기간 저널 모집단 펜스와 장부-기간 권한 시드를 도입합니다. Soft-close 및 hard-close 증거 페어링을 커밋 시점에 검증합니다. 애플리케이션 조회와 설치·운영 문서를 갱신합니다.

Changes

기간 마감 증거 무결성

Layer / File(s) Summary
스냅샷 모집단 및 불변성
database/migrations/0029*, database/migrations/0030*, database/migrations/0031*, tests/test_postgres_trial_balance_snapshot_*, tests/test_trial_balance_snapshot_*
장부·기간별 단일 snapshot, 범위 일치, 잔액 보존, 권한 검증 및 snapshot/line 불변성 제약을 추가합니다.
저널 모집단 신선도 펜스
database/migrations/0032*, database/migrations/0033*, tests/test_postgres_open_period_*, tests/test_postgres_period_close_*serialization*, tests/test_postgres_period_transition_isolation_red.py
Open 및 soft-closed 기간의 저널 삽입을 제어합니다. 64개 펜스와 revision 검증으로 stale hard-close를 SerializationFailure로 처리합니다.
장부-기간 권한 시드 및 fail-closed 조회
database/migrations/0009*, database/migrations/0034*, src/accounting_information_platform/persistence.py, tests/test_book_period_*, tests/test_postgres_book_*
활성 장부와 open 기간에 control/fence 행을 시드합니다. Forced RLS를 복원합니다. 누락된 장부-기간 권한은 공유 달력 상태로 대체하지 않고 거부합니다.
Hard-close와 snapshot 커밋 페어링
database/migrations/0035*, database/migrations/0036*, tests/test_postgres_hard_close_snapshot_pair_red.py, tests/test_postgres_trial_balance_snapshot_commit_pair_red.py, tests/test_trial_balance_snapshot_commit_pair_contract.py
Snapshot 없는 hard_closed 전환과 hard_closed가 아닌 상태의 snapshot 커밋을 지연 제약 트리거로 거부합니다. 기존 편측 상태는 업그레이드 사전 검사에서 거부합니다.
Soft-close 명령 증거 페어링
database/migrations/0037*, tests/test_postgres_soft_close_command_evidence_pair_red.py, tests/test_soft_close_command_evidence_pair_contract.py, docs/doctoring/SOFT_CLOSE_COMMAND_EVIDENCE_PAIR_TRACEABILITY.md
soft_closed 행에 명령 식별자, 원본 payload hash 및 원본 journal count가 없으면 커밋과 업그레이드를 거부합니다.
애플리케이션 및 운영 추적성
src/accounting_information_platform/migration_install.py, src/accounting_information_platform/persistence.py, docs/ARCHITECTURE.md, docs/OPERABILITY.md, docs/adr/*, docs/doctoring/*
설치 순서를 0037까지 확장합니다. 기간 잠금 키와 장부별 상태 조회를 조정합니다. 마감 분개가 게시된 계정 ID와 역할 코드를 사용하도록 변경하고 관련 추적성 문서를 추가합니다.

Estimated code review effort: 5 (Critical) | ~120 minutes

Merge Risk: 🟡 Moderate · up to 38076

Manual deployments can omit the soft-close evidence guard, and unresolved close-path identity and reporting dependencies still risk failed or inaccurate closes. Resolve these before merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 84.34% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 166 functions across 33 files. (4 skipped: …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목은 hard-close 시산표 증거를 고정하는 핵심 변경을 간결하고 명확하게 설명하며, 주요 변경 내용과 일치합니다.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/trial-balance-snapshot-immutability

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

현재 exact head에서 stale REPEATABLE READ transaction이 authority-row lock을 기다린 뒤에도 fixed snapshot 때문에 concurrent snapshot population을 보지 못하는 경로를 추가로 수리했습니다. 새 real-PostgreSQL regression은 physical unique constraint까지 함께 검토해 주세요.

Copy link
Copy Markdown
Contributor Author

Stack handoff correction — 2026-09-08

The PR body still names stale parent #47@f6d6d5c38acfae8ca9cc2db72924b5253340e6fb and old #29 -> #43 -> #47 -> #53 order. Current live dependency is #29@12e1a4bb9d8de5e4b6c72e2893107b07c515416b -> #47@57d107b561221a613292d73cafdfd7de6d88d19c -> #53; #43 is already merged history in #29.

Do not restack this Period Close branch yet. #47 predecessor 31251e... has retained real-PostgreSQL RED evidence from Foundation 34181501661 / Accounting 101921362236 (1294 tests / 24 failures / 20 errors). Current #47 descendants repair isolated test-contract drift and the PostgreSQL 63-byte recording-time trigger-name defect, but require unchanged-head hosted GREEN and current review before this child may adopt them. Preserve every valid #53 Period Close delta and use an ordinary non-force descendant when that parent prerequisite is satisfied; parent/predecessor checks never transfer.

Copy link
Copy Markdown
Contributor Author

Current stack handoff update — 2026-09-08

Live parent has advanced normally/non-force to #47@ac8da26ab149fb65f5dc71b11b43effbdcfdcf31; effective order is #29@12e1a4bb9d8de5e4b6c72e2893107b07c515416b -> #47@ac8da26ab149fb65f5dc71b11b43effbdcfdcf31 -> #53. #43 remains merged history inside #29.

Do not restack this Period Close branch yet. The last executed #47 predecessor 31251e... is real-PostgreSQL RED (Foundation 34181501661 / Accounting 101921362236, retained artifact 10039320625, 1294 tests / 24 failures / 20 errors). Subsequent #47 descendants repair classified restack contracts, explicit PostgreSQL <=63-byte recording-time trigger identity, and non-BYPASSRLS fixture tenant binding. Exact current #47 Foundation 34186371539 is still queued before runner assignment, so none of that predecessor evidence transfers.

When #47 reaches one unchanged terminal hosted GREEN/current-review-clean successor, preserve every valid #53 delta and adopt that parent through ordinary non-force composition only; do not reuse parent checks or repair migration collisions by force-push/destructive rebase.

Copy link
Copy Markdown
Contributor Author

Dependency handoff correction — 2026-09-08: the live maker-checker parent is now #47@636ad045b1eaa135de155e3cb522423aa214c44c on #29@12e1a4bb9d8de5e4b6c72e2893107b07c515416b. #43 is merged history inside #29, so the effective stack is #29 -> #47 -> #53. #47's exact-head Foundation run 34190300382 is still before runner assignment (Accounting 101946817341, Security 101946817336, SAST 101946817424, dependency diff 101946817430, all runner_id=0/no steps). Do not restack this Period Close branch or transfer predecessor evidence until one unchanged #47 successor has terminal PostgreSQL/Foundation evidence and current review disposition. Preserve this branch's existing Period Close delta and migrate it by ordinary non-force composition only.

Copy link
Copy Markdown
Contributor Author

Dependency handoff correction: live parent #47 is now exact 00582b2089aa9bbfa707c4ca488614a1ff5fbcea on #29@12e1a4bb9d8de5e4b6c72e2893107b07c515416b. The three new ordinary descendants are test/fixture repairs for the predecessor 1297/2/8 RED; current Foundation 34198066601 is queued and no GREEN transfers. Keep this #53 head/bytes untouched and dependency-blocked until one unchanged #47 successor is terminal PostgreSQL/Foundation GREEN and current-review clean. Effective stack is #29 -> #47@00582b208... -> #53; #43 is merged history. Do not restack from the stale stored base or old f6d6d5c... parent.

Copy link
Copy Markdown
Contributor Author

Stack handoff correction — 2026-09-08: live maker-checker parent is now #47@84ed35da471f46ca14961f7125ce5f4c34293f7b on #29@12e1a4bb9d8de5e4b6c72e2893107b07c515416b; #43 is merged history inside #29. Current #47 Foundation 34198496083 has started real execution (dependency diff GREEN; Accounting runner assigned/in progress) but is not current-head GREEN or review-approved yet. Keep this #53 head 7c75e05626fa8c7477089c1272bb43719d66bb17 Draft and do not restack from stale f6d6d5c... or 6f81b258.... When #47 has one unchanged hosted-GREEN/current-review-clean successor, adopt that exact parent through ordinary non-force composition while preserving all valid Period Close RED/test/fixture/contract/evidence deltas. No predecessor evidence transfers.

Copy link
Copy Markdown
Contributor Author

Parent-state correction: #47@84ed35da471f46ca14961f7125ce5f4c34293f7b Foundation 34198496083 has now finished Accounting RED, not in-progress. Retained behavior artifact 10045527460 (sha256:607f56223c0985f3e0319aae9117ef0f58cfa2090df033cad72626c98b34adf8) is 1297 tests / 6 failures / 4 errors; sibling dependency/SAST/security are GREEN. The RED is currently isolated to three parent test-contract defects (SQL placeholder, stale migration-name contract, obsolete outbox marker), owned by existing #47 single writer. Keep #53 Draft and do not restack until a subsequent unchanged #47 head is hosted GREEN/current-review clean. The earlier live-parent correction to 84ed35da... still stands; only its execution state changed.

Copy link
Copy Markdown
Contributor Author

Dependency handoff refresh: live parent is now #47@886100a5315ca41b7a8709dd7594df7b7e5b6dd7 on #29@12e1a4bb9d8de5e4b6c72e2893107b07c515416b. The parent is an ordinary tests-only successor of retained 84ed35da... PostgreSQL RED and its Foundation 34202632635 is not yet terminal current-head evidence. Preserve every valid #53 delta and stale stored ancestry as a repair finding; do not restack #53 until one unchanged #47 ordinary successor is terminal hosted GREEN and current-review clean. When that prerequisite is met, compose non-force and keep root 0019/0020/0021 plus #47 0022..0030 authoritative before renumbering only #53-owned migrations.

Copy link
Copy Markdown
Contributor Author

Stack handoff refresh — 2026-09-08: live parent #47 is now exact 4527ca02ff385f3c211976fcf356124e9419c2b1 on #29@12e1a4bb9d8de5e4b6c72e2893107b07c515416b. Predecessor #47@886100a... reached real PostgreSQL and passed behavior plus coverage execution, but its strict coverage-denominator gate failed at 6209/6210 statements and 2331/2332 branches because the post-retry-loop AssertionError in resolve_reconciliation_exception() was structurally unreachable. Ordinary successor 4527ca02... removes only that dead exit while preserving three SQLSTATE 40001 attempts and all accounting authority. Current Foundation 34207629271 is queued on 4527ca02...; no predecessor evidence transfers. Keep this #53 head unchanged and dependency-blocked until one unchanged #47 successor is terminal hosted GREEN and current-review clean; then adopt it by ordinary non-force composition. The effective order is #29 -> #47@4527ca02... -> #53.

Copy link
Copy Markdown
Contributor Author

Stack handoff refresh: live parent is now #47@4527ca02ff385f3c211976fcf356124e9419c2b1 on #29@12e1a4bb9d8de5e4b6c72e2893107b07c515416b; #43 is merged history inside #29. #47 Accounting Foundation 34207629271 is terminal GREEN on the unchanged head, including real PostgreSQL behavior/repository, strict complete coverage, contracts, compile/import, reproducible package evidence, security/SAST/dependency diff. #47 has been promoted to Ready for fresh independent review, but no qualifying APPROVED review is present yet. Keep #53 Draft and do not restack or reuse parent evidence until #47 is normally integrated into #29 and the resulting parent exact head is reverified. When that prerequisite is satisfied, adopt it by ordinary/non-force descendant composition while preserving every valid Period Close RED/test/fixture/contract/evidence delta.

Copy link
Copy Markdown
Contributor Author

Live parent handoff correction only; no #53 source restack yet. Current parent is #47@6c3a92fdc4d0b143e9e2da07f263661fe58357cd, open/Draft/mergeable after fresh P1 review. #47 source-addresses the stacked-session/xact-lock ambiguity and lifecycle-lease FORCE-RLS gap; retained-evidence composite referential scope in migration 0022 remains under the existing #47 single writer and its current Foundation is still executing. This child remains exact 7c75e05626fa8c7477089c1272bb43719d66bb17 with stale stored base ancestry. Do not restack until #47 reaches an unchanged verified successor and is normally integrated into #29; predecessor #47 GREEN does not transfer.

Copy link
Copy Markdown
Contributor Author

Parent exact-head update only: live parent is now #47@27309ca78c59608ff2ee6dce4d5f001f10c4f875, still Draft. Hosted 6c3a92... verified the stacked-session and lifecycle-lease RLS repairs but remained RED on the composite retained-evidence FK plus a stale static matcher; 27309ca... fixes only that static matcher. Migration 0022 composite referential scope remains active under #47's existing single writer. This #53 head remains 7c75e05626fa8c7477089c1272bb43719d66bb17 with stale stored base and must not restack until #47 reaches an unchanged verified successor and is normally integrated into #29.

Copy link
Copy Markdown
Contributor Author

Stack handoff correction — do not use the stale parent SHA in the PR body as current authority. Live parent is now #47@6f8749c569a60fbd9777b630f53d63df37a12937 on #29@12e1a4bb9d8de5e4b6c72e2893107b07c515416b. #47 exact-head Accounting Foundation 34221269652 is repository-owned GREEN (1,314 real-PostgreSQL tests; 6,211/6,211 statements; 2,330/2,330 branches; dependency/security/SAST GREEN) and all fresh P1 threads are resolved, so #47 has moved to Ready for independent review. It is not integrated and still lacks a qualifying independent current-head APPROVED review / applicable central workflow settlement. Therefore #53 remains Draft/dependency-blocked at 7c75e05626fa8c7477089c1272bb43719d66bb17; do not restack onto mutable #47 yet and do not transfer #47 GREEN. Once #47 is normally integrated into #29, preserve every valid #53 delta by ordinary non-force descendant composition and reacquire exact-head PostgreSQL/Foundation/review evidence.

Copy link
Copy Markdown
Contributor Author

Live parent handoff correction — 2026-09-08: #47 is now 263e4ffb79607dccee715686d0aa451981c2eeb8, open/Ready/mergeable after Accounting Foundation 34237450022 terminal GREEN and fresh exact-head review with no actionable defect in the requested lifecycle/accounting-authority boundaries. This does not authorize #53 restack yet: #47 still lacks qualifying independent approval and must integrate normally into the #29 stack first. #53's stored base SHA and body parent pointer remain historical/stale; derive the new parent exact SHA only after that normal integration, then restack non-force and reacquire all #53 evidence. No child source write requested in this handoff.

Copy link
Copy Markdown
Contributor Author

Live-parent handoff correction — 2026-09-08: do not use the body-pinned #47@f6d6d5c... or stored base SHA 6f81b258... as current prerequisite authority. The current parent is #47@263e4ffb79607dccee715686d0aa451981c2eeb8, targeting #29@12e1a4bb9d8de5e4b6c72e2893107b07c515416b, Ready/mergeable with exact-head Accounting Foundation 34237450022 GREEN, but still lacking a qualifying independent APPROVED review. #53 therefore remains Draft/dependency-blocked. Restack only after #47 normally integrates into #29; derive the resulting parent exact head, read intervening delta, then perform an ordinary non-force descendant restack/renumber and reacquire all current-head PostgreSQL/security/package/review evidence. Effective dependency order is #29 -> #47@263e4ff... -> #53; #43 is merged history, not a separate live parent.

Copy link
Copy Markdown
Contributor Author

/opencode

Continue PR #53 from live exact head 9c3dba6f12aa58062faa6ba11537aabef91486d8 only. If the branch moves first, read every intervening delta and adapt by an ordinary descendant; do not reset, force-push, destructively rebase, weaken a gate, or rewrite unrelated persistence surfaces.

Fresh evidence-audit finding: candidate 3832cf7... correctly carries immutable posted journal_entry_line.chart_account_id into the actual AIS closing contra and separately binds it into _canonical_snapshot_hash(), but _canonical_closing_hash() still serializes only code/role/amount/line number. Consequently two legally distinct historical account Entities that reuse the same code can produce the same durable journal_proposal_record.source_payload_hash for the closing journal even though the posted clearing line is intentionally Entity-specific.

Test-first descendant 9c3dba6f12aa58062faa6ba11537aabef91486d8 extends the existing real-PostgreSQL code-reuse scenario. After hard close it reconstructs the closing evidence payload from the actually persisted closing lines and requires historical P&L lines to bind their exact chart_account_id; current production code is expected to fail that equality. Retained earnings remains a current close-time destination in this slice and is deliberately not reclassified as historical source identity.

Make the smallest causal production repair:

  • extend the closing-journal evidence hash so each historical P&L clearing line binds the same exact posted chart_account_id already carried in historical_chart_account_ids;
  • pass that purpose-limited mapping from _post_closing_journal() into the hash computation before writing journal_proposal_record.source_payload_hash;
  • keep ordinary _insert_journal() admission on chart_account.valid_to IS NULL; do not broaden historical-ID use beyond AIS-generated closing contra lines;
  • keep retained-earnings resolution on the current effective close-time mapping and do not change its ownership in this patch;
  • do not alter the snapshot hash compatibility rule or silently rewrite historical committed hashes.

Verify the focused real-PostgreSQL expiry/code-reuse tests first, then the complete exact-head Accounting Foundation/security/SAST/dependency/package gates. Push only a normal descendant if GREEN. Do not merge or mark Ready while the stale parent stack, current-head approval, or required evidence remains unresolved.

Copy link
Copy Markdown
Contributor Author

CI admission note for exact 9c3dba6f12aa58062faa6ba11537aabef91486d8: the branch changed a test file, so paths-ignore: docs/**, *.md is not the reason for the missing run. The PR remains mergeable=false, and the repository workflow is on: pull_request; GitHub does not run pull_request workflows while a PR has merge conflicts. Current Actions lookup for this SHA is therefore 0 runs, not GREEN and not a transient runner queue. Preserve the test-first descendant and repair the source locally/through the existing single writer, but do not manufacture evidence with a no-op commit or gate bypass. Hosted exact-head Foundation must be reacquired after the prerequisite stack yields a conflict-free parent/restack.

Copy link
Copy Markdown
Contributor Author

/opencode

Continue the existing #53 single-writer from live exact head 9c3dba6f12aa58062faa6ba11537aabef91486d8; this is a continuation of comment 5591197456, not a competing writer. Re-read the live branch before writing and ordinary-adopt any intervening delta.

Execute the already-isolated RED now: _canonical_closing_hash() must bind the exact historical chart_account_id for AIS-generated P&L clearing lines, while the retained-earnings destination remains a current close-time policy decision and should not gain historical identity. Pass the existing historical_chart_account_ids mapping from _post_closing_journal() into _canonical_closing_hash() and serialize chart_account_id only for mapped historical lines. Preserve existing canonical field names/order-by-sort_keys, exact Decimal formatting, ordinary _insert_journal() active-account admission, snapshot-hash identity, and current retained-earnings behavior. Do not make a global account-admission relaxation or edit #37-owned shared docs.

Use the checked-in real PostgreSQL regression on 9c3dba6... as RED. Make the smallest causal production change, run the focused identity/hash tests first, then applicable exact-head Foundation/security/repository gates. If merge conflict still prevents pull_request Actions, report that as workflow-admission evidence rather than manufacturing a no-op commit or weakening the gate. Commit/push only an ordinary descendant; no force-push/rebase.

Copy link
Copy Markdown
Contributor Author

@codex address that feedback

Continue the existing #53 source-writer lane from live exact head 9c3dba6f12aa58062faa6ba11537aabef91486d8; this supersedes only the stalled execution handoff in comment 5591806233, not the source/history. Before writing, re-read the live PR head. If an intervening ordinary descendant exists, adopt it and apply only the still-missing delta; do not force-push or rebase.

The verified RED is narrow: _post_closing_journal() already records exact historical posted chart_account_id values in historical_chart_account_ids and passes that mapping to _insert_journal(), while _canonical_snapshot_hash() binds account UUIDs. _canonical_closing_hash() still hashes only account code/role/amount/line, so two distinct historical Account entities reusing the same code can provenance-alias the closing journal command.

Minimal causal repair:

  • extend _canonical_closing_hash() to accept the existing historical line-number → UUID mapping;
  • for a closing line whose line_number is in that mapping, include chart_account_id as the canonical string UUID in that line's JSON object;
  • for retained earnings/current close-time policy destination, where no historical mapping exists, omit chart_account_id entirely rather than writing null/blank/current-catalog identity;
  • pass historical_chart_account_ids from _post_closing_journal() into _canonical_closing_hash();
  • preserve existing sort_keys=True, separators, exact Decimal formatting, current field semantics, ordinary _insert_journal() active-account admission, retained-earnings mapping, snapshot hash, posting/close authority, and foreign-system boundaries.

Keep the existing real-PostgreSQL code-reuse regression on 9c3dba6... as the acceptance oracle. Do not weaken/skip/xfail it, do not add a global account-admission relaxation, and do not edit #37-owned shared CHANGELOG/TRACEABILITY/product-gap docs. If the stale parent conflict prevents hosted PR CI, still make only the ordinary source descendant and report focused local verification honestly; hosted exact-head GREEN must be reacquired after a conflict-free non-force restack.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits. You can see your limits in the Codex usage dashboard.

@seonghobae seonghobae left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current exact-head evidence-audit finding on 9c3dba6f12aa58062faa6ba11537aabef91486d8: the hard-close implementation now preserves historical posted Account Entity identity in both the retained trial-balance snapshot and the actual AIS-generated closing journal line, but the command/provenance digest still drops that identity.

_post_closing_journal() groups source balances by journal_entry_line.chart_account_id, records each P&L contra line in historical_chart_account_ids, and passes that map into _insert_journal(). _canonical_snapshot_hash() likewise serializes the account UUID. _canonical_closing_hash(), however, still serializes only chart_account_code, role, exact debit/credit, and line number. If account code X is expired and later reused by a different Account entity, the correct historical clearing line can therefore receive a source-payload hash indistinguishable from a close against the replacement Entity. The stored journal fact is Entity-specific while its immutable command evidence is not.

The checked-in real-PostgreSQL code-reuse regression on this head is the RED. Narrow GREEN: pass the existing line-number→historical-UUID map into _canonical_closing_hash() and include chart_account_id only for mapped historical P&L clearing lines; omit the field for retained earnings/current close-time policy destination. Preserve canonical JSON ordering/separators, exact Decimal formatting, ordinary active-account admission, snapshot identity, and the no-foreign-posting/no-Reporting-close-authority boundaries. Do not relax the test or add a second account lookup path.

This is a COMMENT review, not approval. The PR remains Draft/merge-conflicted with zero current-head PR workflow runs, so a source descendant is not hosted GREEN; full exact-head evidence must be reacquired after the prerequisite stack is normally integrated and the branch is non-force restacked.

Copy link
Copy Markdown
Contributor Author

/opencode

Continue the existing #53 single-writer lane. The Codex handoff 5592475501 failed before execution with connector comment 5592476807 (Codex usage limits), so it produced no source descendant and is not an active competing writer. The earlier OpenCode handoff 5591806233 also produced no observed descendant; live head is still exact 9c3dba6f12aa58062faa6ba11537aabef91486d8. Before any write, re-read the live PR head. If another ordinary descendant has appeared, adopt it and apply only the still-missing delta; never force-push/rebase.

Address exact-head COMMENT review 5147490036 only. Verified RED: _post_closing_journal() already preserves line-number → historical posted chart_account_id and _insert_journal() uses it for AIS-generated P&L closing contra; _canonical_snapshot_hash() also binds account UUID. _canonical_closing_hash() still drops the Entity identity, so effective-dated account-code reuse can provenance-alias two distinct historical Account entities in journal_proposal_record.source_payload_hash.

Minimal causal GREEN:

  1. Extend _canonical_closing_hash() to receive the existing historical_chart_account_ids mapping.
  2. For each mapped historical P&L closing line, serialize chart_account_id as the canonical UUID string in that line payload.
  3. For retained earnings/current close-time policy destination, where the mapping intentionally has no entry, omit chart_account_id entirely; do not write null/blank/current-catalog identity.
  4. Pass the mapping from _post_closing_journal() into _canonical_closing_hash().
  5. Preserve sort_keys=True, existing separators/field semantics, exact Decimal formatting, ordinary _insert_journal() active-account admission, snapshot hash behavior, retained-earnings current mapping, and accounting/Reporting/foreign-system authority boundaries.

Use the checked-in real-PostgreSQL code-reuse regression on 9c3dba6... as the acceptance oracle; do not weaken/skip/xfail it. Run the focused identity/hash tests and applicable source/repository contracts. Because #53 is merge-conflicted, pull_request Actions may remain absent; do not manufacture no-op status. Commit/push only the smallest ordinary descendant and report local verification separately from hosted GREEN. Do not edit #37-owned shared baseline/CHANGELOG/TRACEABILITY.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant