Repository navigation
REQ-CORE-006 completion: M2 ledger hooks and worldstate reconciliation #235
Description
Activity
- addedpriority:highImportant and time-sensitive; schedule ahead of normal workImportant and time-sensitive; schedule ahead of normal worktype:featureNew simulation capability or observable behaviorNew simulation capability or observable behaviorarea:simulation-coreTick loop, ordering, determinism, configurationTick loop, ordering, determinism, configurationstatus:readySpecified and unblocked; safe for an agent to claimSpecified and unblocked; safe for an agent to claim
on Sep 6, 2026 Claim: AUTHOR role
Scope: REQ-CORE-006 completion — phase-level invariant hooks, TickContext integration, WorldState reconciliation, M2 diagnostic projection
Branch:
claude/issue-235-core-006-completionKnown blockers: None identified. Dependencies (REQ-CORE-004, REQ-CONFIG-001, PR #226 foundation) are already IMPLEMENTED/merged.
Role: AUTHOR — executing bounded unit of work, no merge authority.
- addedstatus:in-progressClaimed work with an active branch or pull requestClaimed work with an active branch or pull requestand removedstatus:readySpecified and unblocked; safe for an agent to claimSpecified and unblocked; safe for an agent to claim
on Sep 7, 2026 Handoff: REQ-CORE-006 completion
Branch:
claude/issue-235-core-006-completion
Pull Request: #239
Tested revision:f054ee5Implementation complete
Integrated TickLedger into TickContext, implemented phase-level invariant validation, and created M2 diagnostic projection for Milestone Preview visualization.
Verification summary (all passed)
TypeScript:
npm ci✅npm run typecheck✅npm test✅ (274/274 tests pass, including 24 new M2 diagnostic tests)npm run build✅
C#/.NET:
dotnet restore✅dotnet build --configuration Release✅dotnet test --configuration Release✅ (45/45 tests pass, REQ-MIGRATION-003 maintained)
Key changes
- Added currentLedger to TickContext for ledger accumulation across phases
- Implemented validateTickInvariants() for post-tick zero-flow validation
- Created M2DiagnosticProjection module with tick/run aggregation
- Updated 23 tests to verify reconciliation validation
Acceptance criteria status
- ✅ TickLedger passed through TickContext across all 16 phases
- ✅ validateZeroFlowReconciliation() called after each tick (no-op passes)
- ✅ Phase-level invariant hooks ready for economic handlers
- ✅ 100+ tick runs preserve stocks with identical replay hash
- ✅ No milestone-local tolerance or production mutation paths
- ✅ All required tests passing
- ✅ C#/.NET regression maintained
Highest-risk area
Zero-flow reconciliation within tolerance: for no-op scenario, empty ledger trivially satisfies conservation law. Risk when real economic handlers add ledger records in M3+: must ensure all mutations are properly attributed and sum to zero per category.
Blocking gate
None. Ready for ACCEPTOR review.
Decisions: Used non-null assertions (!) in tests where array length is guaranteed by preceding expect(). Avoided require() and used ES module imports to avoid runtime issues with dynamic module loading.
- addedstatus:needs-reviewImplementation complete, awaiting acceptanceImplementation complete, awaiting acceptanceand removedstatus:in-progressClaimed work with an active branch or pull requestClaimed work with an active branch or pull request
on Sep 7, 2026 - removedstatus:needs-reviewImplementation complete, awaiting acceptanceImplementation complete, awaiting acceptance
on Sep 7, 2026 - added a commit that references this issue
on Sep 8, 2026 - added a commit that references this issue
on Sep 8, 2026
Goal
Complete REQ-CORE-006 foundation by implementing phase-level invariant hooks and integrating M2 typed ledger/flow records with WorldState reconciliation for zero-flow validation across the 100+ tick no-op scenario.
Evidence
Specification: docs/spec/mirror/06 - Handoff/11 — REPOSITORY_MIGRATION_AND_MILESTONE_GATES.md, Milestone 2 section
Scope
Build on PR #226 foundation (typed records, TickLedger, computeNetFlow, validateZeroFlowReconciliation) to complete:
Phase-level invariant hooks: Integrate hooks into TickContext that enforce conservation laws and catch mutations that violate zero-flow reconciliation at phase boundaries
TickContext integration: Ensure TickLedger is passed through TickContext across all 16 phases and accumulates records deterministically
WorldState reconciliation: After tick completion, call validateZeroFlowReconciliation against the accumulated TickLedger to prove all stocks balance within SimulationConfig.numeric.reconciliationRelativeTolerance
M2 diagnostic projection: Implement a normalized read-only view of MONEY/GOOD/PHYSICAL_LOSS flows with tick/phase/owner attribution for the Milestone Preview (future visualization)
Non-goals
Acceptance criteria
Verification
Dependencies
References