Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion loopx/control_plane/host_adapter_settlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
7 changes: 5 additions & 2 deletions loopx/control_plane/turn_driver/host_todo_completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
);
}

Expand Down Expand Up @@ -443,8 +448,6 @@ function providerSteps(
request.goal_id,
"--slots",
"1",
"--source",
"heartbeat",
"--execute",
"--agent-id",
request.agent_id,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_goal_mode_mcp_settlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Loading