Skip to content

REQ-CORE-006: Typed ledger/flow records and phase-level invariant hooks - #198

Closed
zendev-author[bot] wants to merge 2 commits into
masterfrom
claude/issue-192-ledger-invariants
Closed

zendev-author[bot] wants to merge 2 commits into
masterfrom
claude/issue-192-ledger-invariants

Conversation

@zendev-author

@zendev-author zendev-author Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements M2 typed ledger and diagnostic projection with phase-level invariant hooks:

  • Typed ledger flows (MONEY, GOOD, PHYSICAL_LOSS) with tick/phase/reason/owner attribution
  • Zero-flow reconciliation using configurable SimulationConfig.numeric tolerance
  • Phase-level invariant hooks (conservation, finite-value checks)
  • Deterministic normalized diagnostic projection for analytics

Test plan

  • ledgerFlow.test.ts: 22 tests covering flow creation, aggregation, ownership
  • reconciliation.test.ts: 16 tests covering zero-flow verification and diagnostics
  • invariantHooks.test.ts: 21 tests covering registration and execution
  • All 267 tests pass; typecheck clean; build succeeded
  • Legacy .NET 9 build/tests remain green (REQ-MIGRATION-003)

Changed artifacts

docs/spec/IMPLEMENTATION_STATUS.md
docs/spec/implementation_status.csv
src/simulation/index.ts
src/simulation/invariantHooks.test.ts
src/simulation/invariantHooks.ts
src/simulation/ledgerFlow.test.ts
src/simulation/ledgerFlow.ts
src/simulation/reconciliation.test.ts
src/simulation/reconciliation.ts
src/simulation/tickOrchestrator.ts

Acceptance criteria

  • Typed ledger flows expose MONEY and GOOD signed deltas with tick/phase/reason/owner
  • PHYSICAL_LOSS records attributed without balancing credit
  • Zero-flow reconciliation passes within SimulationConfig.numeric.reconciliationRelativeTolerance
  • Diagnostic projection deterministic and independent of iteration order
  • Phase-level invariant hooks with conservation and finite-value checks
  • Test-only unmatched delta fails deterministically with category/key/residual
  • No M2-local epsilon or undocumented mutation paths

Checks

  • TypeScript typecheck: passed
  • Unit tests (267/267): passed
  • Build (Vite): passed
  • Legacy C# (.NET 9): passed (45/45 tests, build clean)

Blocks

None. REQ-CORE-006 acceptance criteria fully satisfied.

🤖 Generated with Claude Code

github-actions Bot and others added 2 commits September 6, 2026 07:16
Implement M2 diagnostic projection with typed MONEY and GOOD signed deltas
plus PHYSICAL_LOSS attribution. Add phase-level invariant hooks for
deterministic reconciliation with configurable tolerance.

- ledgerFlow.ts: Define MoneyFlow, GoodFlow, PhysicalLoss records with
  tick/phase/reason attribution and StockOwner references
- reconciliation.ts: Implement reconcileTickFlows() and
  buildDiagnosticProjection() for zero-flow verification and analytics
- invariantHooks.ts: Phase-level invariant registration and execution with
  conservation and finite-value checks for M2
- Update TickContext to include RuntimeLedger for flow accumulation
- 69 comprehensive tests: ledgerFlow, reconciliation, invariantHooks

All acceptance criteria met: typed ledger flows, deterministic projection,
zero-flow reconciliation within SimulationConfig.numeric tolerance,
conservation and finite-value invariants, fail-fast diagnostics.

Verification: npm ci, npm run typecheck, npm test (267/267 passed),
npm run build succeeded. TypeScript canonical.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
PR #198 completes REQ-CORE-006 acceptance criteria: typed ledger flows,
zero-flow reconciliation, phase-level invariant hooks, diagnostic
projection. Ledger row added with evidence from 69 new tests across three
modules (ledgerFlow, reconciliation, invariantHooks); 267 total tests pass.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@drevendev

Copy link
Copy Markdown
Owner

OPERATOR decision: closed, not merged. Gate M1 reopened today (REQ-CONFIG-003 and REQ-CONFIG-004 back to PARTIAL, repairs #200 and #201), and this M2 branch now conflicts with master on the ledger files; the AUTHOR run at 07:40Z looked at it and could not proceed. Per EXECUTION_ORDER, M2 waits for the M1 repairs. Issue #192 returns to status:blocked naming that gate; the commits stay reachable from this pull request, and the QA findings on #193 (StockLocation must carry monetaryAuthorityId) remain the work packet.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant