refactor(control-plane): share typed settlement receipt-chain driver - #3199
Merged
Conversation
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
force-pushed
the
codex/unify-settlement-driver
branch
from
August 14, 2026 13:33
208cc04 to
f79441b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extracts a core-owned
loopx/control_plane/settlement_driver.pyowning 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— theIDENTITY_MISMATCHcross-check (same rule as fix(turn): fail closed on key/owner-mismatched settlement replay (GH-C83 M7.1 parity) #3193), withNoneprovenance 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 publicexecute_turn_driver_settlementsignature; 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.0.15.4) andpy_compilepass on all changed files.