Skip to content

refactor(control-plane): share typed settlement receipt-chain driver - #3199

Merged
huangruiteng merged 1 commit into
mainfrom
codex/unify-settlement-driver
Aug 14, 2026
Merged

refactor(control-plane): share typed settlement receipt-chain driver#3199
huangruiteng merged 1 commit into
mainfrom
codex/unify-settlement-driver

Conversation

@huangruiteng

Copy link
Copy Markdown
Owner

What

Extracts a core-owned loopx/control_plane/settlement_driver.py owning the typed settlement receipt-chain semantics that the quota adapter and the isolated Turn adapter each re-implemented:

  • settlement_identity_from_plan — resolve the complete typed identity/effect id from a transaction plan, failing closed on missing/contradictory identity;
  • require_matching_effect_id — the IDENTITY_MISMATCH cross-check (same rule as fix(turn): fail closed on key/owner-mismatched settlement replay (GH-C83 M7.1 parity) #3193), with None provenance as the opt-in seam;
  • seed_committed_steps — ordered committed-receipt seeding from durable step payloads, with per-step missing-failure kinds and exact preserved messages;
  • commit_step_effect — run one step effect, validate the committed payload, checkpoint phases, and record the receipt;
  • settlement_receipt / effect_ids_match / is_committed_payload — shared factories/predicates.

The Turn adapter (turn_driver/settlement.py) now delegates identity resolution, seeding, and step effects to the driver while keeping its public execute_turn_driver_settlement signature; the quota adapter (quota/settlement.py) reuses the shared receipt factory and effect-id predicate. Domain policy stays outside the driver: scheduler apply/ACK, Todo lifecycle reducers, spend accounting, and vision/replan qualification remain in their bounded contexts.

Validation

  • tests/control_plane/test_settlement_driver.py (new, 15 tests) pins the shared contract: identity resolution, mismatch cross-check, ordered seeding, validator vs effect mode, failure-kind mapping.
  • Existing suites unchanged and green at exact head: turn transaction/executor/driver, quota settlement/should-run parity/CLI projection/slot accounting, adapter conformance, incident replay, fault replay matrix, state-refresh projections — 214 focused tests pass locally.
  • Ruff within the repo pin (0.15.4) and py_compile pass on all changed files.
  • No behavior change: the diff is a behavior-preserving extraction; the committed-effect cross-check activates only when a caller supplies provenance (already wired by fix(turn): fail closed on key/owner-mismatched settlement replay (GH-C83 M7.1 parity) #3193's executor change).

Quota and Turn adapters both settle a typed SettlementPlan under one
identity, but each re-implemented the receipt-chain semantics: effect-id
resolution, committed-receipt seeding, IDENTITY_MISMATCH cross-check, and
committed-payload validation. Extract a core settlement_driver owning
those rules; the Turn adapter now delegates identity resolution, seeding,
and step effects to it, and the quota adapter reuses the shared receipt
factory and effect-id predicate. No behavior change: existing turn/quota
settlement, conformance, incident-replay, and fault-replay suites stay
green, plus focused driver tests pin the shared contract.
@huangruiteng
huangruiteng force-pushed the codex/unify-settlement-driver branch from 208cc04 to f79441b Compare August 14, 2026 13:33
@huangruiteng
huangruiteng merged commit e539d8b into main Aug 14, 2026
5 checks passed
@huangruiteng
huangruiteng deleted the codex/unify-settlement-driver branch August 14, 2026 13:36
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