|
| 1 | +# C4.3 settlement obligation comparison |
| 2 | + |
| 3 | +- Parent: [controller/executor RFC, C4.3](2026-10-27-refactor-handoff.md#c43--settlement-adapters-over-existing-primitives). |
| 4 | +- Baseline: `e19d94ca0`, 2026-10-29. The settlement owners are unchanged at `fb331f45`. |
| 5 | +- Status: reading-only comparison. No deletion, runtime, schema, wire or default change. |
| 6 | +- Correction: an earlier revision of this entry read the adapter's lack of a |
| 7 | + local journal as a lack of recovery on the whole MCP path. That was wrong. |
| 8 | + The recovery baseline is corrected below, in both mirrors. |
| 9 | +- [Chinese mirror](2026-10-29-c4-3-settlement-obligation-comparison.zh-CN.md). |
| 10 | + |
| 11 | +## Why this entry exists |
| 12 | + |
| 13 | +C4.3 requires comparing `host_adapter_settlement.py`, `turn_driver/host_todo_completion.ts` |
| 14 | +and `turn_driver/settlement.py` obligation by obligation *before* deleting a |
| 15 | +supposedly duplicated condition/step interpreter. No such comparison was |
| 16 | +recorded. This entry supplies it so the next PR can be decided rather than |
| 17 | +guessed. |
| 18 | + |
| 19 | +An **obligation** here is a decision or durable effect that must occur exactly |
| 20 | +once per transaction, and whose owner must reject, replay or recover it. |
| 21 | + |
| 22 | +## The three owners at this baseline |
| 23 | + |
| 24 | +| Where | Entry | Decision owner | Python role | |
| 25 | +| --- | --- | --- | --- | |
| 26 | +| A — Host Todo completion | `settle_host_todo_completion` | `host_todo_completion.ts` via `turn.host_todo_completion.evaluate` | Materializes authored vision JSON, decodes the emitted plan, runs CLI steps, evaluates `continue_when` | |
| 27 | +| B — Turn settlement | `execute_turn_driver_settlement` | `settlement.ts` via `turn.settlement.reduce` | Invokes provider effects, writes checkpoints, returns observations | |
| 28 | +| C — MCP host facade | `goal_mode_mcp.py` | A end-to-end | Loads A's request from the host | |
| 29 | + |
| 30 | +## Obligation matrix |
| 31 | + |
| 32 | +| Obligation | A decides | B decides | Equivalent? | |
| 33 | +| --- | --- | --- | --- | |
| 34 | +| Transaction identity | TS `turnInstanceId` / `expectedIdentity`, surfaced as `SettlementIdentity` | TS identity plus per-step receipt matching | Same vocabulary, different derivation inputs | |
| 35 | +| Request validation | TS `decodeRequest`, `TODO_ID_PATTERN` | TS decode plus `receipt_missing` / `identity_mismatch` | Not equivalent: A validates shape, B validates committed receipts | |
| 36 | +| Pre-write admission | `guard` step runs the real `quota should-run` CLI with the turn instance id | `validation` is a pre-committed phase; B throws if it would have to execute it | **Not equivalent** — different obligations sharing no code | |
| 37 | +| Lifecycle completion | `lifecycle_completion` step with completion args | No counterpart; completion is part of writeback | A-only | |
| 38 | +| Durable writeback | `durable_writeback` step, condition guarded | `durable_writeback` provider effect through the reducer | Same kind, different execution and recovery | |
| 39 | +| Quota spend | `quota_spend` step | `quota_spend` provider effect | Same kind, different execution and recovery | |
| 40 | +| Terminal closeout | `terminal_closeout` step, emitted last with `continue_when: null` | `terminal_closeout` provider effect plus `terminal_closeout_requirement` | Same kind, B owns the requirement rule | |
| 41 | +| Replay / recovery | The adapter keeps no journal of its own. The call chain still recovers: `turnInstanceId` derives a stable identity from the same intent, the CLI persists canonical settlement receipts, and the continue-when conditions accept `idempotent_replay` / `receipt_repaired`, so re-entering the same intent succeeds and spends exactly one slot | Checkpoint per step, `resolve_prepared`, receipt replay, retry ceiling | **Different owner and granularity** — not "recovery versus none" | |
| 42 | +| Persistence | The adapter writes only a temporary vision file; the durable settlement receipts live in the canonical CLI/quota store, owned by the CLI | Durable checkpoint plus source journal | Different owners: CLI receipts versus transaction journal | |
| 43 | + |
| 44 | +## Findings |
| 45 | + |
| 46 | +1. **Neither path is a second policy owner.** Both delegate every decision to a |
| 47 | + TypeScript owner and keep Python as transport. `host_adapter_settlement.py` |
| 48 | + carries no lifecycle policy of its own. |
| 49 | + |
| 50 | +2. **The step vocabularies overlap only partially.** A emits |
| 51 | + `guard / lifecycle_completion / durable_writeback / quota_spend / |
| 52 | + terminal_closeout`; B's `SettlementStepKind` is |
| 53 | + `validation / durable_writeback / quota_spend / terminal_closeout`. `guard` |
| 54 | + and `lifecycle_completion` have no B counterpart, and B's `validation` is a |
| 55 | + phase marker it refuses to execute rather than A's admission call. |
| 56 | + |
| 57 | +3. **Recovery differs in owner and granularity, not in existence.** The adapter |
| 58 | + keeps no journal, but the MCP path is not recovery-free. |
| 59 | + `turnInstanceId` derives a stable identity from the same intent, the CLI |
| 60 | + persists canonical settlement receipts, and `spendContinueWhen` accepts |
| 61 | + `idempotent_replay` / `receipt_repaired`. A response lost after the real |
| 62 | + commit therefore recovers by re-entering the same intent: the durable |
| 63 | + readback reports `settlement_pending` or `settled`, a premature terminal |
| 64 | + completion is blocked, the retry succeeds, and the slot is spent exactly |
| 65 | + once — `tests/test_goal_mode_mcp_settlement.py::test_real_mcp_completion_recovers_a_lost_mutation_response`, |
| 66 | + parametrized over `lifecycle`, `writeback` and `spend`. B recovers at |
| 67 | + provider-step granularity inside one transaction, through its own checkpoint |
| 68 | + and `resolve_prepared`. A consolidation must preserve the CLI-receipt replay |
| 69 | + path; it must neither assume the MCP host needs a new journal nor assume the |
| 70 | + CLI receipts disappear with the adapter. |
| 71 | + |
| 72 | +4. **At the shipped capability call site they already compose.** |
| 73 | + `extensions/governed_capability_execution.py` calls A's |
| 74 | + `classify_host_guard_snapshot` for admission and then |
| 75 | + `execute_turn_driver_settlement` for the transaction with its own journal. |
| 76 | + The suspicion that these are competing settlement transactions is not |
| 77 | + supported by this call site. |
| 78 | + |
| 79 | +5. **The only Python-side interpreter is small and transport-necessary.** |
| 80 | + `_condition_matches` supports `all`, `any`, `equals`, `nullish`, `object`, |
| 81 | + `not_object` and `normalized_string_equals`; `_decode_provider_steps` |
| 82 | + validates that the plan has four or five steps in the fixed order. TypeScript |
| 83 | + still authors every condition. Evaluating them in TypeScript instead needs |
| 84 | + one runtime call per step, which the RFC explicitly says is not automatically |
| 85 | + an improvement. |
| 86 | + |
| 87 | +## What a deletion would require |
| 88 | + |
| 89 | +None of these is established today: |
| 90 | + |
| 91 | +- the consolidation preserving the CLI's canonical receipt replay and the |
| 92 | + stable turn instance id that let a re-entry of the same intent succeed |
| 93 | + without paying twice, together with an adapter-local journal *or* an |
| 94 | + equivalent effect receiver for A's steps; or |
| 95 | +- B accepting `ordered_cli_sequence` plans with `continue_when` plus A's `guard` |
| 96 | + and `lifecycle_completion` kinds without a per-step runtime call, and |
| 97 | + adopting the CLI-receipt replay that A's path relies on today; or |
| 98 | +- evidence that no shipped caller uses A end-to-end. |
| 99 | + |
| 100 | +## Candidate next slices |
| 101 | + |
| 102 | +1. **Vocabulary unification (small).** If any caller adopts both paths, give |
| 103 | + `guard`, `lifecycle_completion` and `validation` one typed owner instead of |
| 104 | + three names in two files. Do not unify names that describe different |
| 105 | + obligations. |
| 106 | +2. **Characterization of A's adapter-local behavior (medium).** Pin what the |
| 107 | + adapter itself does when a step succeeds and a later step raises, before any |
| 108 | + recovery change touches it. The end-to-end response-loss case is already |
| 109 | + characterized by `test_real_mcp_completion_recovers_a_lost_mutation_response`; |
| 110 | + what is not characterized is the adapter's own partial-step behavior and |
| 111 | + where the recovery boundary between the adapter and the CLI receipts sits. |
| 112 | +3. **Not recommended now.** Merging A and B, or adding a third plan format, |
| 113 | + would add a transaction boundary without deleting an obligation. |
| 114 | + |
| 115 | +## Coordination |
| 116 | + |
| 117 | +Active or recently merged work touching these obligations: |
| 118 | +[#3412](https://github.com/loopx-project/loopx/pull/3412) (ambiguous settlement |
| 119 | +recovery), [#5677](https://github.com/loopx-project/loopx/pull/5677) (caller-authored |
| 120 | +first delivery), [#7580](https://github.com/loopx-project/loopx/pull/7580) (failed |
| 121 | +journal with an unresolved prepared effect), [#7523](https://github.com/loopx-project/loopx/pull/7523) |
| 122 | +(typed receipts and continuation). Any implementation slice must reconcile those |
| 123 | +diffs first. |
| 124 | + |
| 125 | +## What this does not establish |
| 126 | + |
| 127 | +No equivalence proof, no deletion authorization, no runtime qualification, no |
| 128 | +benefit measurement, and no claim that either path is redundant. The recovery |
| 129 | +baseline is the CLI-receipt replay that exists today; the adapter-local |
| 130 | +partial-step behavior is not characterized here. Source facts are read at the |
| 131 | +baseline above and may drift. |
0 commit comments