Skip to content

Commit 86dfa6f

Browse files
authored
Merge pull request #7682 from loopx-project/codex/turn-launch-settlement-identity-20261029
2 parents c38b3a1 + 5d1525e commit 86dfa6f

5 files changed

Lines changed: 142 additions & 4 deletions

File tree

‎docs/architecture/rfcs/controller-executor-unified-contract-v0.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,13 @@ and retirement, and adoption/full-cost qualification where each boundary is
991991
independently reviewable. Record dependencies in the existing tasks and PRs.
992992
Splitting delivery does not close C1 or waive §9's original quota-baseline test.
993993

994+
Native launch rechecks use the original `SettlementIdentity` as their sole
995+
Todo/obligation binding. Both `codex-cli` and `codex-app-server` call the existing
996+
`current_turn_host_launch_decision` owner; an observed replan packet is context,
997+
not an additional binding argument. This transport simplification can ship before
998+
wire cutover. Qualify real launch, refusal and replay against the same original
999+
identity; retain the current typed eligibility, Stop and settlement owners.
1000+
9941001
The first **cutover** slice pairs the complete field/clause migration with a
9951002
real single-session producer and consumer replacement. Start at the
9961003
shared quota emission boundary and trace both attached heartbeat delivery and

‎docs/architecture/rfcs/controller-executor-unified-contract-v0.zh-CN.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,12 @@ owner。列明后续切换消费者;不能添加无人使用的基础设施或
750750
可按独立可审查的边界拆分,在既有任务和 PR 中记录依赖。拆分交付不代表 C1 完成,
751751
也不豁免第 9 节相对原 quota 基线的验证。
752752

753+
原生启动重查只从原 `SettlementIdentity` 取得 Todo/obligation 绑定。
754+
`codex-cli` 和 `codex-app-server` 都调用既有
755+
`current_turn_host_launch_decision` owner;观察到的 replan packet 是上下文,
756+
不再作为另一份绑定参数。这项运输简化可以先于 wire 切换交付。沿相同原身份验证真实
757+
启动、拒绝与重放,保留既有 typed 资格、Stop 和结算 owner。
758+
753759
首个**切换**片必须把完整字段/条款迁移与真实单会话 producer、consumer 替换一起交付。
754760
从共享 quota emission 边界开始,同时追踪 attached heartbeat 交付与 Turn adapter,
755761
保留各自真实宿主归属。不能新增无人使用的第三个 serializer,而两个活跃 writer 继续

‎loopx/cli_commands/turn_decision.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def build_fresh_turn_decision_owner(
349349

350350
def current_turn_host_launch_decision(
351351
args: argparse.Namespace, *, registry_path: Path, runtime_root: Path,
352-
identity: SettlementIdentity, replan_obligation_id: str | None,
352+
identity: SettlementIdentity,
353353
planned_effective_action: object,
354354
scheduler_execution_context: Mapping[str, Any],
355355
operator_inbox_urgency_projector: Callable[..., dict[str, Any]],
@@ -361,6 +361,8 @@ def current_turn_host_launch_decision(
361361
The caller supplies the real receipt identity; a Host session or turn_key
362362
cannot reconstruct it. This read neither creates another receipt nor
363363
substitutes a newly selected task into the already planned Host request.
364+
An observed replan packet is context, not a second settlement binding.
365+
Both native callers transport the obligation recorded in this identity.
364366
"""
365367
current = build_live_quota_should_run_decision(
366368
collect_turn_status_payload(args, registry_path=registry_path,
@@ -373,7 +375,7 @@ def current_turn_host_launch_decision(
373375
operator_inbox_urgency_projector=operator_inbox_urgency_projector,
374376
bounded_research_frontier_projector=project_live_explore_composition_frontier,
375377
receipt_bound_todo_id=identity.todo_id or None,
376-
receipt_bound_replan_obligation_id=replan_obligation_id,
378+
receipt_bound_replan_obligation_id=identity.replan_obligation_id,
377379
turn_instance_id=identity.turn_instance_id,
378380
turn_start_hook_dispatch=turn_start_hook_dispatch,
379381
workspace_path=Path(args.project).expanduser().resolve(), goal_ref=goal_ref,

‎loopx/cli_commands/turn_run_once.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,6 @@ def scheduler(_spend_payload: dict[str, object]) -> dict[str, object]:
803803
def native_launch_decision(current_registry: Path) -> Mapping[str, Any]:
804804
return current_turn_host_launch_decision(args, registry_path=current_registry,
805805
runtime_root=runtime_root, identity=settlement_identity,
806-
replan_obligation_id=replan_obligation_id,
807806
planned_effective_action=payload["turn_envelope"].get("effective_action"),
808807
scheduler_execution_context=payload.get("scheduler_execution_context") or {},
809808
operator_inbox_urgency_projector=operator_inbox_urgency_projector,
@@ -827,7 +826,7 @@ def current_launch_decision(current_registry: Path) -> Mapping[str, Any]:
827826
# when its mirror still advertises old quota or health.
828827
return current_turn_host_launch_decision(
829828
args, registry_path=current_registry, runtime_root=runtime_root,
830-
identity=settlement_identity, replan_obligation_id=replan_obligation_id,
829+
identity=settlement_identity,
831830
planned_effective_action=payload["turn_envelope"].get("effective_action"),
832831
scheduler_execution_context=payload.get("scheduler_execution_context") or {},
833832
operator_inbox_urgency_projector=operator_inbox_urgency_projector,
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
"""Native launch preserves the admitted binding through real CLI and stores."""
2+
from __future__ import annotations
3+
4+
import json
5+
import sys
6+
from pathlib import Path
7+
8+
import pytest
9+
10+
from host_process_fixture import write_python_host_fixture
11+
from test_replan_successor_guard_reentry import AGENT, GOAL, _fixture
12+
13+
14+
def _host(root: Path, *, material: bool) -> Path:
15+
# This is a deterministic process transport, not a model or task evaluator.
16+
# The material arm writes a distinct artifact checked by the outer validator;
17+
# the replan arm ends the iteration and earns no writeback or debit.
18+
return write_python_host_fixture(root / "native-host", f'''#!/usr/bin/env python3
19+
import json, pathlib, sys
20+
request = json.loads(sys.stdin.read().split("Turn request:\\n", 1)[1])
21+
with pathlib.Path("host-requests.jsonl").open("a") as stream:
22+
stream.write(json.dumps(request) + "\\n")
23+
material = {material!r}
24+
if material:
25+
pathlib.Path("checked-source.txt").write_text("independently checked source\\n")
26+
print(json.dumps({{"type": "thread.started", "thread_id": "fixture-launch-session"}}), flush=True)
27+
result = {{
28+
"schema_version": "loopx_turn_result_v0", "turn_key": request["turn_key"],
29+
"result_kind": "validated_progress" if material else "iteration_failed",
30+
"completed_phases": ["host_execute", "typed_result"],
31+
"classification": "source_checked" if material else "",
32+
"recommended_action": "Retain the original source criteria." if material else "",
33+
"next_action": "Continue independent source validation." if material else "",
34+
"delivery_batch_scale": "single_surface" if material else "",
35+
"delivery_outcome": "outcome_progress" if material else "",
36+
"path_delta_mode": "unchanged" if material else "", "agent_vision_json": "",
37+
"vision_unchanged_reason": "Original source criteria still apply." if material else "",
38+
"progress_observation_json": "",
39+
"summary": "Source checked." if material else "Source remains unverified.",
40+
}}
41+
if material:
42+
result.update(work_evidence=["artifact:checked-source"],
43+
validation_evidence=["check:independent-source-validator"])
44+
args = sys.argv[1:]
45+
pathlib.Path(args[args.index("--output-last-message") + 1]).write_text(json.dumps(result))
46+
''')
47+
48+
49+
@pytest.mark.parametrize("provider", ["file", "sqlite"])
50+
@pytest.mark.parametrize("binding", ["todo", "autonomous_replan"])
51+
def test_native_cli_uses_original_binding_and_replays_without_new_effects(
52+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, provider: str, binding: str,
53+
) -> None:
54+
call, runtime, _ = _fixture(tmp_path, monkeypatch, provider, future_monitor=False)
55+
todo_id = None
56+
declared_text = None
57+
if binding == "todo":
58+
todo_id = call("todo", "add", "--goal-id", GOAL, "--role", "agent",
59+
"--claimed-by", AGENT, "--text", "Independently check the original source.",
60+
"--task-class", "advancement_task", "--action-kind", "validate")["todo_id"]
61+
declared_text = call("todo", "list", "--goal-id", GOAL,
62+
"--todo-id", todo_id)["todo"]["text"]
63+
project = tmp_path / "project"
64+
executable = _host(tmp_path, material=binding == "todo")
65+
decision = ["--goal-id", GOAL, "--agent-id", AGENT, "--host", "codex-cli",
66+
"--execution-mode", "isolated-headless", "--scheduler-owner", "outer_controller",
67+
"--iteration-context", "fresh", "--session-scope", "agent"]
68+
if todo_id:
69+
decision += ["--todo-id", todo_id]
70+
common = [*decision, "--project", str(project), "--codex-bin", str(executable),
71+
"--no-global-sync"]
72+
if todo_id:
73+
common += ["--validation-command-json", json.dumps([
74+
sys.executable, "-c", "from pathlib import Path; "
75+
"assert Path('checked-source.txt').read_text() == 'independently checked source\\n'",
76+
])]
77+
turn = "native-launch-binding"
78+
preview = call("turn", "plan", *decision, "--turn-instance-id", turn,
79+
"--include-transaction-detail")
80+
assert preview["route"]["kind"] == ("ready_for_host" if todo_id else "replan_required")
81+
obligation_id = None
82+
subject = todo_id
83+
if not todo_id:
84+
envelope = preview["turn_envelope"]
85+
obligation_id = envelope["replan_action_packet"]["obligation_id"]
86+
assert obligation_id.startswith("replan-")
87+
subject = f"autonomous_replan:{obligation_id}"
88+
expected_effect = f"{GOAL}:{AGENT}:{subject}:{turn}"
89+
assert not (project / "host-requests.jsonl").exists()
90+
91+
result = call("turn", "run-once", *common, "--turn-instance-id", turn, "--execute")
92+
assert result["effects"]["host_invoked"] is True, result
93+
assert result["receipt"]["settlement_effect_id"] == expected_effect
94+
lineage = result["receipt"]["lineage"]
95+
assert lineage["todo_id"] == (todo_id or "")
96+
assert lineage.get("replan_obligation_id") == obligation_id
97+
assert result["effects"]["state_written"] is bool(todo_id)
98+
assert result["quota_slot_spend_count"] == int(bool(todo_id))
99+
if todo_id:
100+
assert result["status"] == "committed" and result["validation"]["ok"] is True
101+
current = call("todo", "list", "--goal-id", GOAL, "--todo-id", todo_id)
102+
assert current["todo"]["text"] == declared_text
103+
else:
104+
assert result["status"] == "stopped" and result["result_kind"] == "iteration_failed"
105+
assert not (project / "checked-source.txt").exists()
106+
107+
requests = (project / "host-requests.jsonl").read_bytes()
108+
sent = json.loads(requests)
109+
assert sent["turn_key"] == result["receipt"]["turn_key"]
110+
captures = {path: path.read_bytes() for path in runtime.rglob("decisions/*.json")}
111+
assert captures
112+
replay_args = list(common)
113+
if todo_id:
114+
rejected = call("turn", "run-once", *common, "--resume-turn-key", sent["turn_key"],
115+
"--execute", expected_code=1)
116+
assert "cannot retarget" in rejected["error"] and not any(rejected["effects"].values())
117+
index = replay_args.index("--todo-id")
118+
del replay_args[index:index + 2]
119+
replay = call("turn", "run-once", *replay_args, "--resume-turn-key", sent["turn_key"],
120+
"--execute")
121+
assert replay["replayed"] is True
122+
assert not any(replay["effects"].values())
123+
assert (project / "host-requests.jsonl").read_bytes() == requests
124+
assert all(path.read_bytes() == original for path, original in captures.items())

0 commit comments

Comments
 (0)