Skip to content

REQ-PRODUCTION-008: wire the M4 closed-economy loop through canonical phases #650

Description

@drevendev

Goal

Implement permanent REQ-PRODUCTION-008: wire the one-region M4 autonomous closed-economy loop through the canonical 0–15 phase orchestrator so already-implemented production, labor, local market, household, capital and lifecycle slices execute in causal order on authoritative state.

Evidence

  • Live master is 1da04b2ea5b0bc17e935e9ab277cbd07e3ae4195; REQ-CONFIG-006..007, REQ-PRODUCTION-001..007, and REQ-POPULATION-001..003 are integrated, and no open simulation-correctness issue preempts this unit.
  • The canonical registry requires Phase-2 plans → Phase-3 labor → Phase-4 input procurement → Phase-5 wages/production → Phase-6/8 canonical local markets → Phase-9 consumption → Phase-12 capital → Phase-14/15 lifecycle/signals, with Phase-5 wages authoritative for Phase-8 affordability and Phase-7 imports unable to retroactively feed Phase-5 production.
  • tickOrchestrator.ts currently keeps one opening WorldState fixed across all phases. Existing M4 settlement/production/capital/lifecycle functions correctly return new immutable WorldState transitions, but no canonical M4 runner threads those transitions between phase boundaries yet.
  • Handoff/04 requires Phase 4 to reuse the canonical deterministic local-clearing primitive and canonical market settlement path with PRE_PRODUCTION allocations; there must be no Production-local purchase function.
  • Existing Phase-6/8 market handlers are M3 fixture-oriented and do not yet consume the residual M4 production/household intent set as a complete autonomous loop.

Scope

  • Add the smallest canonical state-threading seam needed for later phases to observe earlier settled WorldState transitions without mutating the input world in place and without breaking the existing M2/M3 executeTick API.
  • Add one M4 closed-economy composition/runner for exactly one Region that dispatches through canonical phases 0..15 and composes the existing authoritative M4 Phase-2, Phase-3, Phase-5, Phase-9, Phase-12 and Phase-14/15 handlers/transitions.
  • Implement Phase-4 PRE_PRODUCTION local procurement by reusing computeLocalClearing plus the canonical market settlement transition/endpoint rules; carry only residual planned demand to Phase 8 so one need is not bought twice.
  • Reuse M3 Phase-6 price formation and Phase-8 MAIN clearing/settlement for current output offers, household demand and residual production/investment demand. Phase 7 remains no-op in M4.
  • Persist Phase-5 wage settlement before Phase-8 clearing so canonical wallet preflight observes current-tick net wages. Persist Phase-5 production before Phase-6/8 so output exists before it can be sold.
  • Persist Phase-9 household consumption/spoilage, Phase-12 capital formation/depreciation, Phase-14 lifecycle transitions and Phase-15 wage/signal close using their existing explicit state-transition APIs.
  • Add deterministic seeded one-region integration regressions that assert causal phase order, Phase-4 procurement affects Phase-5 bottlenecks, Phase-5 wages are visible to Phase-8 settlement, Phase-7 cannot repair Phase-5 output, and identical runs are stable under irrelevant insertion-order changes.
  • Mark REQ-PRODUCTION-008 IMPLEMENTED in docs/spec/implementation_status.csv only if the full integration contract is mechanically demonstrated on the exact PR head.

Non-goals

  • No M5 interregional trade, shipments or FX; Phase 7 stays inert for this M4 unit.
  • No M6 mutable fiscal/Clan institution dynamics, M7 monetary dynamics, M8 demography/migration, M9 events, or later-system pull-forward.
  • No new local-market allocation or settlement algorithm: reuse the M3 primitives and actor-stock transition path.
  • No edits under docs/spec/mirror/** and no redesign of canonical economic formulas already implemented by REQ-PRODUCTION-001..007 / REQ-POPULATION-001..003.
  • No completion claim for REQ-ACCEPTANCE-005 or REQ-VISUALIZATION-009 in this unit.

Acceptance criteria

  1. A seeded one-region M4 tick executes canonical phases exactly 0..15, and every M4 subsystem observes only state made authoritative by earlier phase transitions.
  2. Phase-2 production/labor/household plans feed Phase 3; Phase-4 local procurement uses canonical PRE_PRODUCTION clearing/settlement; Phase-5 production consumes only stock present by Phase 4 and Phase-5 wage settlement is persisted before Phase 8.
  3. Phase-6 price formation and Phase-8 MAIN clearing reuse the canonical M3 market primitives; residual production demand is not double-filled after Phase 4, and output enters ProductionUnit inventory before ordinary sale settlement.
  4. Phase-9 consumption, Phase-12 capital formation/depreciation, Phase-14 lifecycle and Phase-15 wage/signal close are wired through their existing authoritative transition seams with next-tick semantics preserved.
  5. Phase 7 performs no M4 import mutation. A negative control proves same-tick Phase-7 imports cannot retroactively increase Phase-5 production.
  6. Phase-8 settlement preflight observes the post-Phase-5 canonical wallet state, including wages already settled in Phase 5, without creating a second shopping loop or allowing Phase-2 household planning to pre-spend unsettled wages. This matches the canonical REQ-PRODUCTION-008 registry wording and Handoff/06's conservative Phase-2 household-planning rule.
  7. Input WorldState remains immutable, all persisted stocks stay finite/non-negative, deterministic insertion-order variations normalize identically, and no M5+ behavior is introduced.
  8. Exact-head TypeScript typecheck/tests/build, retained .NET restore/build/tests, generated-status/policy checks and mergeability are green. IMPLEMENT stops at the producer→SLOPSTER boundary.

Verification

Run focused M4 orchestrator integration tests plus full TypeScript and retained .NET gates. Inspect the exact diff for one canonical phase order, explicit immutable state transitions, canonical M3 market reuse, no duplicated settlement path, no mirror edit, no M5+ scope creep and truthful implementation-ledger evidence.

Activity

  1. added
    priority:highImportant and time-sensitive; schedule ahead of normal work
    type:featureNew simulation capability or observable behavior
    area:simulation-coreTick loop, ordering, determinism, configuration
    status:readySpecified and unblocked; safe for an agent to claim
    on Sep 23, 2026
  2. drevendev commented on Sep 23, 2026

    @drevendev
    OwnerAuthor

    CLAIM — REQ-PRODUCTION-008

    I am claiming exactly this bounded implementation unit from current master 1da04b2ea5b0bc17e935e9ab277cbd07e3ae4195. I will use zen/issue-650-m4-closed-economy-orchestrator, keep M5+ behavior out of scope, and stop at the producer→SLOPSTER boundary after exact-head verification.

  3. added
    status:in-progressClaimed work with an active branch or pull request
    and removed
    status:readySpecified and unblocked; safe for an agent to claim
    on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:simulation-coreTick loop, ordering, determinism, configurationpriority:highImportant and time-sensitive; schedule ahead of normal worktype:featureNew simulation capability or observable behavior

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions