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
1 change: 1 addition & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@ jobs:
tests/control_plane/test_refresh_settle_turn.py::test_wrong_or_missing_child_workspace_retains_owed_command_for_exact_recovery
tests/control_plane/test_refresh_settle_turn.py::test_legacy_posix_quoted_powershell_launcher_fails_before_settlement
tests/control_plane/test_refresh_settle_turn.py::test_pinned_powershell_launcher_settles_original_turn_once
tests/control_plane/test_refresh_settle_turn.py::test_composed_settlement_keeps_commit_when_private_capture_is_unsupported
- name: Restore the primary Windows Node runtime
uses: actions/setup-node@v6
Expand Down
16 changes: 16 additions & 0 deletions docs/reference/required-work-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,16 @@ spend receipt. Repair capture privacy or read the same operation without the
output option; a delivery failure does not prove that the effect failed to commit.
Never rerun admission or change the original Turn/effect identity to recover
output. This transport change alone does not prove model retention or savings.
A plan-composed `refresh-state --settle-turn --settlement-receipt` command is
different: it carries no output option, so the budget is implicit and the caller
has nothing to remove. When the host cannot validate private captures, that
composed settlement keeps the already evaluated result inline, reports the
skipped capture as `result_delivery_error`
(`quota_decision_capture_unsupported`), and lets the evaluated outcome decide
the exit code. A committed settlement therefore exits 0 with its identity and
receipts; a refused one still exits nonzero with its recovery step. Read the
original Turn receipts to confirm commitment, and never repeat admission or the
spend for this Turn.

Codex App heartbeat 有原生会话,且当前 Todo 已准入并就绪时,可能收到合并结算计划。
同一 Turn 先领取再复查就绪,升级后的回执与计划匹配时也适用。
Expand Down Expand Up @@ -1653,6 +1663,12 @@ reader reference 在该平台也安全拒绝,不能用 mode bits 代替 Window
信息,不保证展示预算;被拒绝的操作不一定存在 spend receipt。修复捕获权限或以
原身份读取无输出预算的结果,不能据投递失败认定效果未提交。恢复不重新准入或
更换原 Turn/effect 身份。此传输变化本身不证明模型保留或成本收益。
计划给出的合并命令 `refresh-state --settle-turn --settlement-receipt` 不同:
它本身不带输出选项,预算由内部给定,调用方没有可移除的参数。平台无法校验私有
捕获时,该合并结算保留已求值的结果内联返回,把跳过的捕获记为
`result_delivery_error`(`quota_decision_capture_unsupported`),退出码仍按已求值的
结果决定。已提交的结算因此以 0 退出并带回身份与回执;被拒绝的结算仍以非零退出并
带回恢复步骤。核对原 Turn 回执确认提交,不要为此重复准入或扣额。

### Saved context cache / 已保存上下文缓存

Expand Down
20 changes: 20 additions & 0 deletions loopx/cli_commands/refresh_settlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,26 @@ def present_settled_refresh(payload: dict[str, Any], *, runtime_root: Path) -> d
or not isinstance(progress, dict) or progress.get("state") != "settled"
or payload.get("settlement_owed") is not None):
return payload
from ..control_plane.turn_driver.decision_capture import private_capture_supported

if not private_capture_supported():
# This plan-composed command carries no output option to remove: the
# budget is implicit here. A host without a qualified private capture
# reader therefore keeps the already evaluated result inline instead of
# failing a committed settlement. The evaluated outcome still decides
# the exit code; this note only explains the skipped capture.
return {**payload, "result_delivery_error": {
"error_code": "quota_decision_capture_unsupported",
"reason": (
"This platform cannot validate a private context capture, so bounded result "
"delivery was skipped and the complete result is returned inline. "
+ ("The exact Turn is settled; read the original Turn receipts to confirm commitment."
if payload.get("ok") is True else
"Use the inline failure controls and the returned recovery step.")
),
"recommended_action": "Keep the original Turn and effect identity. Do not repeat "
"admission or spend for this result.",
}}
from .quota_capture import budgeted_settlement_result
from ..command_invocation import current_loopx_cli_argv
from ..control_plane.turn_driver.native_context_profile import NATIVE_CONTEXT_PAGE_OUTPUT_BYTES
Expand Down
68 changes: 68 additions & 0 deletions tests/control_plane/test_refresh_settle_turn.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,74 @@ def test_receipt_capture_failure_keeps_committed_receipts_and_exact_retry(tmp_pa
assert _spend_run_count(runtime) == 1


@pytest.mark.parametrize("provider", ["file", "sqlite"])
def test_composed_settlement_keeps_commit_when_private_capture_is_unsupported(
tmp_path, monkeypatch, capsys, provider,
):
from loopx.cli import main
from loopx.control_plane.turn_driver import decision_capture

isolate_sqlite_runtime(tmp_path, monkeypatch)
project, runtime, registry = _write_fixture(tmp_path)
_initialize_fixture_authority(project, runtime, provider=provider)
binding = ["--goal-id", GOAL_ID, "--agent-id", AGENT_ID,
"--todo-id", TODO_ID, "--turn-instance-id", TURN_ID]
rc, guard = _run_cli(registry, runtime, "quota", "should-run", "--codex-app", *binding, cwd=project)
assert rc == 0, guard
identity = guard["heartbeat_receipt"]["settlement_identity"]
command = ["refresh-state", *binding, "--classification", "verified_capture_boundary",
"--delivery-batch-scale", "implementation", "--delivery-outcome", "outcome_progress",
"--delivery-boundary", "in_flight_continuation", "--no-global-sync", "--suppress-external-sinks",
"--settle-turn", "--settlement-receipt"]

def run():
with monkeypatch.context() as unsupported:
unsupported.setattr(decision_capture, "private_capture_supported", lambda: False)
unsupported.chdir(project)
code = main(["--registry", str(registry), "--runtime-root", str(runtime),
"--format", "json", *command])
return code, json.loads(capsys.readouterr().out)

code, settled = run()
# The plan-composed command carries no output option the caller can remove,
# so a host without private capture must not turn commitment into refusal.
assert code == 0 and settled["ok"] is True, settled
assert settled["settlement_progress"]["state"] == "settled"
assert settled["settlement_identity"] == identity
assert len(settled["settlement_result"]["receipts"]) == 3
delivery = settled["result_delivery_error"]
assert delivery["error_code"] == "quota_decision_capture_unsupported"
assert "--max-page-output-bytes" not in json.dumps(delivery)
assert "result_details" not in settled
assert _spend_run_count(runtime) == 1
assert not (runtime / "context-delivery").exists()

code, replay = run()
assert code == 0 and replay["ok"] is True, replay
assert replay["settlement_identity"] == identity
assert replay["result_delivery_error"]["error_code"] == "quota_decision_capture_unsupported"
assert _spend_run_count(runtime) == 1

if not decision_capture.private_capture_supported():
# This host cannot establish private capture privacy at all, so there is
# no bounded receipt to compare against. The unsupported-path assertions
# above are the cross-platform contract; only POSIX continues below.
return

# POSIX keeps the bounded receipt it already had on the same Turn.
private = runtime / "context-delivery"
private.mkdir(mode=0o700, exist_ok=True)
private.chmod(0o700)
with monkeypatch.context() as capture:
capture.chdir(project)
assert main(["--registry", str(registry), "--runtime-root", str(runtime),
"--format", "json", *command]) == 0
bounded = json.loads(capsys.readouterr().out)
assert "result_delivery_error" not in bounded
Comment thread
loopx-agent marked this conversation as resolved.
Resolved
assert bounded["settlement_identity"] == identity
assert _spend_run_count(runtime) == 1


@pytest.mark.parametrize("provider", ["file", "sqlite"])
def test_complete_turn_composition_failure_preserves_original_guard_and_recovers(tmp_path, monkeypatch, capsys, provider):
import hashlib
Expand Down
Loading