diff --git a/loopx/control_plane/host_adapter_settlement.py b/loopx/control_plane/host_adapter_settlement.py index 26aad2c6a7..5b945ac3a9 100644 --- a/loopx/control_plane/host_adapter_settlement.py +++ b/loopx/control_plane/host_adapter_settlement.py @@ -374,8 +374,17 @@ def _run_provider_plan( ) -> list[dict[str, str]]: outcomes: list[dict[str, str]] = [] for step in steps: + args = list(step.args) + if step.step_kind == "quota_spend": + # Forward the source from the preceding identity-checked writeback. + # The quota command still verifies the requested debit. + writeback = json.loads(outcomes[-1]["output"]) + source = _path_value(writeback, ["settlement_progress", "quota_spend_source"]) + if not isinstance(source, str) or "--source" in args: + raise RuntimeError("TypeScript host provider spend source shape mismatch") + args.extend(("--source", source)) output = run_cli( - list(step.args), + args, legacy_args=(list(step.legacy_args) if step.legacy_args else None), ) outcomes.append({"step_kind": step.step_kind, "output": output}) diff --git a/loopx/control_plane/turn_driver/host_todo_completion.ts b/loopx/control_plane/turn_driver/host_todo_completion.ts index f4cb77fed8..ebd2e7fc96 100644 --- a/loopx/control_plane/turn_driver/host_todo_completion.ts +++ b/loopx/control_plane/turn_driver/host_todo_completion.ts @@ -344,6 +344,11 @@ function writebackContinueWhen(identity: JsonObject): JsonObject { ...exactIdentityConditions(["settlement_identity"], identity), objectAt(["settlement_result"]), nullish(["settlement_result", "failure"]), + equals(["settlement_progress", "schema_version"], "quota_settlement_progress_v0"), + any( + equals(["settlement_progress", "quota_spend_source"], "heartbeat"), + equals(["settlement_progress", "quota_spend_source"], "visible-goal"), + ), ); } @@ -443,8 +448,6 @@ function providerSteps( request.goal_id, "--slots", "1", - "--source", - "heartbeat", "--execute", "--agent-id", request.agent_id, diff --git a/tests/test_goal_mode_mcp_settlement.py b/tests/test_goal_mode_mcp_settlement.py index c70e45201d..d18f818489 100644 --- a/tests/test_goal_mode_mcp_settlement.py +++ b/tests/test_goal_mode_mcp_settlement.py @@ -336,7 +336,7 @@ def test_real_mcp_settlement_rejects_missing_writeback_then_commits_same_identit "--slots", "1", "--source", - "heartbeat", + "visible-goal", "--execute", ) assert premature_rc == 1 @@ -363,6 +363,7 @@ def test_real_mcp_settlement_rejects_missing_writeback_then_commits_same_identit assert settlement["lifecycle_completion"]["ok"] is True assert settlement["quota_spend"]["ok"] is True assert settlement["quota_spend"]["appended"] is True + assert settlement["quota_spend"]["source"] == "visible-goal" status_rc, status = _run_cli( registry,