Skip to content

Commit 8304388

Browse files
authored
feat(context): add explicit complete Turn context for external hosts (#8489)
* Add explicit complete Turn context for external heartbeat hosts Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> * fix(benchmark): retain explicit complete context in checkpoint preflight Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --------- Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
1 parent a8ffad3 commit 8304388

29 files changed

Lines changed: 562 additions & 54 deletions

‎benchmark/edgebench/README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,19 @@ Omit the flag on the next run to disable it. No active experiment is changed by
980980
installing this code. Inspect wake receipts and the saved decisions before
981981
claiming adoption; score countability still requires the usual integrity review.
982982

983+
For an explicitly complete v1 Host contract, choose `--complete-turn` instead
984+
on either heartbeat profile. The shared worker forwards that choice through
985+
the real heartbeat renderer and guard; it retains the original ready claim,
986+
receipt and single-command settlement. It cannot be combined with the legacy
987+
short-envelope option. Context delivery remains independent, and unselected
988+
runs keep their existing behavior. See the [Host protocol](../../docs/reference/protocols/turn-envelope-v0.md#explicit-complete-v1-host-entry--显式完整-v1-host-入口)
989+
for source readback, failure recovery and rollback. User task time requirements
990+
remain readable; private Host deadlines stay outside model context.
991+
992+
中文:heartbeat profile 可显式选择 `--complete-turn` 以消费完整 v1,不能与旧短包
993+
选项同时启用;共用原 ready claim、回执和单条结算 owner,不改变未选择的运行。
994+
按原 source reader 核实采用与恢复;该开关不新增模型、子 worker、时钟或权限。
995+
983996
## Close a managed native attempt
984997

985998
For a native-feedback run with an existing experiment-board row and a fresh

‎benchmark/edgebench/run.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,11 @@ def main(argv=None):
122122
help="New-run default: native public feedback; blind/best-only are explicit controls")
123123
parser.add_argument("--managed-run-json", type=Path,
124124
help="Opt-in private binding for native terminal proof, consumed by the controller")
125-
parser.add_argument("--turn-envelope", action="store_true",
125+
turn_view = parser.add_mutually_exclusive_group()
126+
turn_view.add_argument("--turn-envelope", action="store_true",
126127
help="Opt-in short heartbeat context with same-invocation full captures")
128+
turn_view.add_argument("--complete-turn", action="store_true",
129+
help="Explicit complete v1 Turn contract with shared exact-Turn settlement; heartbeat workers only")
127130
parser.add_argument("--context-delivery", choices=("off", "on"),
128131
help="Native Codex context delivery: on by default for heartbeat workers; pass off to disable")
129132
parser.add_argument("--execution-observation", choices=("local_probe",),
@@ -246,6 +249,8 @@ def main(argv=None):
246249
parser.error("--task-entry loopx-planned requires a heartbeat worker")
247250
if args.turn_envelope and args.worker not in {"heartbeat-resume", "heartbeat-explore"}:
248251
parser.error("--turn-envelope requires a heartbeat worker")
252+
if args.complete_turn and args.worker not in {"heartbeat-resume", "heartbeat-explore"}:
253+
parser.error("--complete-turn requires a heartbeat worker")
249254
if args.context_delivery is None:
250255
args.context_delivery = Execution(mode="heartbeat" if args.worker.startswith("heartbeat-") else "plain").context_delivery
251256
if args.context_delivery != "off" and not args.worker.startswith("heartbeat-"):
@@ -455,6 +460,7 @@ def main(argv=None):
455460
task_objective=task_objective,
456461
task_entry=args.task_entry,
457462
turn_envelope=args.turn_envelope,
463+
**({"complete_turn": True} if args.complete_turn else {}),
458464
context_delivery=args.context_delivery,
459465
**({"execution_observation": args.execution_observation}
460466
if args.execution_observation is not None else {}),
@@ -538,7 +544,7 @@ def main(argv=None):
538544
"loopx_commit": pins[0], "runner_commit": pins[1],
539545
"sforge_source": sforge_source if native_result_scope is not None else active_source_receipt(),
540546
"local_docker_images": local_docker_images,
541-
**turn_envelope_receipt(explicit=args.turn_envelope),
547+
**turn_envelope_receipt(explicit=args.turn_envelope, complete=args.complete_turn),
542548
**({"context_delivery": "on"} if args.context_delivery != "off" else {}),
543549
**({"execution_observation": args.execution_observation}
544550
if args.execution_observation is not None else {}),

‎benchmark/runtime/checkpoint.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
research_participants, verify_research_participants,
2525
)
2626
from .checkpoint_handoff import CHECKPOINT_CAPTURE_SECONDS
27+
from .codex import explicit_turn_display
2728

2829

2930
def normalize_checkpoint_request_path(value: str) -> str:
@@ -230,6 +231,9 @@ def capture_before_replan(env: dict[str, str], receipt: dict[str, Any], body: st
230231
"--goal-id", env["LOOPX_GOAL_ID"], "--agent-id", env["LOOPX_AGENT_ID"],
231232
"--runtime-profile", "generic_cli", "--turn-instance-id", receipt["turn_id"],
232233
"--available-capability", "shell", "--available-capability", "filesystem_write"]
234+
display = explicit_turn_display(env)
235+
if display.complete_turn:
236+
command.append("--complete-turn")
233237
native_context = env.get("LOOPX_CONTEXT_DELIVERY") == "on" and bool(env.get("LOOPX_CODEX_CONTEXT_DIR"))
234238
if native_context:
235239
# The native reader selects full/delta after SessionStart. Ask the

‎benchmark/runtime/codex.py‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Execution:
3030
turn_envelope: bool = False
3131
context_delivery: str | None = None
3232
native_child_limit: int | None = None
33+
complete_turn: bool = False
3334

3435
def __post_init__(self) -> None:
3536
if self.native_child_limit is not None and (
@@ -44,6 +45,8 @@ def __post_init__(self) -> None:
4445
raise ValueError("context_delivery supports only off or on with heartbeat execution")
4546
if not isinstance(self.turn_envelope, bool) or (self.turn_envelope and self.mode != "heartbeat"):
4647
raise ValueError("turn_envelope requires heartbeat execution and a boolean opt-in")
48+
if type(self.complete_turn) is not bool or (self.complete_turn and (self.mode != "heartbeat" or self.turn_envelope)):
49+
raise ValueError("complete_turn requires heartbeat execution without legacy turn_envelope")
4750
if self.mode not in MODES or self.context not in CONTEXTS:
4851
raise ValueError("unsupported execution mode or iteration context")
4952
if self.task_entry is None:
@@ -79,11 +82,22 @@ def native_goal(self) -> bool:
7982
return self.mode in {"native-goal", "loopx-goal"}
8083

8184

82-
def turn_envelope_receipt(*, explicit: bool) -> dict:
85+
def turn_envelope_receipt(*, explicit: bool, complete: bool = False) -> dict:
8386
"""Record only the explicit display opt-in; checkpoint capture is independent."""
84-
if explicit:
85-
return {"turn_envelope": True, "turn_envelope_source": "explicit"}
86-
return {}
87+
return {**({"turn_envelope": True, "turn_envelope_source": "explicit"} if explicit else {}),
88+
**({"complete_turn": True, "complete_turn_source": "explicit"} if complete else {})}
89+
90+
91+
def explicit_turn_display(env: dict[str, str]) -> Execution:
92+
"""Decode the shared explicit display request through its Execution owner."""
93+
selected = {}
94+
for variable, field in (("LOOPX_TURN_ENVELOPE", "turn_envelope"),
95+
("LOOPX_COMPLETE_TURN", "complete_turn")):
96+
value = env.get(variable, "0")
97+
if value not in {"0", "1"}:
98+
raise ValueError(f"{variable} must be 0 or 1")
99+
selected[field] = value == "1"
100+
return Execution(**selected)
87101

88102

89103
def native_child_instructions(limit: int | None) -> str:

‎benchmark/runtime/harbor.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def __init__(
8282
goal_id=_GOAL_ID,
8383
agent_id=_AGENT_ID,
8484
defer_codex_home=False,
85+
complete_turn=False,
8586
**kwargs,
8687
):
8788
if "research_loop" in kwargs:
@@ -102,6 +103,7 @@ def __init__(
102103
turn_envelope,
103104
context_delivery,
104105
native_child_limit,
106+
complete_turn=complete_turn,
105107
)
106108
if type(provider_request_admission) is not bool:
107109
raise ValueError("provider_request_admission must be a boolean opt-in")
@@ -191,7 +193,7 @@ def __init__(
191193
raise ValueError("provider_request_admission requires the Responses wire API")
192194

193195
def _turn_envelope_receipt(self) -> dict:
194-
return {**turn_envelope_receipt(explicit=self.execution.turn_envelope),
196+
return {**turn_envelope_receipt(explicit=self.execution.turn_envelope, complete=self.execution.complete_turn),
195197
**({"native_child_limit": self.execution.native_child_limit}
196198
if self.execution.native_child_limit is not None else {}),
197199
**({"context_delivery": "on"} if self.execution.context_delivery != "off" else {})}
@@ -690,6 +692,7 @@ def _worker_env(self, *, cwd: str) -> dict[str, str]:
690692
**({"LOOPX_CHECKPOINT_REQUEST": self.checkpoint_request_path}
691693
if self.checkpoint_request_path is not None else {}),
692694
**({"LOOPX_TURN_ENVELOPE": "1"} if self.execution.turn_envelope else {}),
695+
"LOOPX_COMPLETE_TURN": "1" if self.execution.complete_turn else "0",
693696
"LOOPX_CONTEXT_DELIVERY": self.execution.context_delivery,
694697
# A trial's explicit None must not inherit a container opt-in.
695698
"LOOPX_NATIVE_CHILD_LIMIT": (

‎benchmark/runtime/sforge.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __init__(self, config, *, profile: str, cwd: str,
108108
checkpoint_request_path: str | None = None,
109109
checkpoint_request: bytes | None = None,
110110
warm_start=None, research_sidecar: bool = False,
111-
native_result_scope: dict | None = None):
111+
native_result_scope: dict | None = None, complete_turn: bool = False):
112112
super().__init__(config)
113113
if profile not in PROFILES:
114114
raise ValueError("Unknown benchmark worker profile")
@@ -123,6 +123,8 @@ def __init__(self, config, *, profile: str, cwd: str,
123123
):
124124
raise ValueError("turn_envelope requires a heartbeat worker")
125125
self.turn_envelope = turn_envelope
126+
self.complete_turn = Execution(mode="heartbeat" if profile.startswith("heartbeat-") else "plain",
127+
turn_envelope=turn_envelope, complete_turn=complete_turn).complete_turn
126128
self.native_child_limit = Execution(mode="plain", native_child_limit=native_child_limit).native_child_limit
127129
if self.native_child_limit is not None and (not feedback_prompt or not workspace_instructions):
128130
raise ValueError("Native child authorization requires the explicit task prompt and workspace instructions")
@@ -408,6 +410,7 @@ def _install_worker(self, backend, handle, log_dir, logger):
408410
scheduler_timeout_sec=self.timeout_seconds,
409411
task_entry=self.task_entry,
410412
turn_envelope=self.turn_envelope,
413+
**({"complete_turn": True} if self.complete_turn else {}),
411414
context_delivery=self.context_delivery,
412415
**({"execution_observation": self.execution_observation}
413416
if self.execution_observation is not None else {}),

‎benchmark/runtime/worker.py‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from dataclasses import replace
1515
from pathlib import Path
1616

17-
from benchmark.runtime.codex import Execution, prepare_codex_home, process_environment
17+
from benchmark.runtime.codex import Execution, explicit_turn_display, prepare_codex_home, process_environment
1818

1919
from benchmark.runtime.scheduler import PHASE_WORK_RESERVE_SECONDS as PHASE_WORK_RESERVE_SECONDS
2020
from benchmark.runtime.scheduler import phase_work_reserve
@@ -95,18 +95,19 @@ def heartbeat_body(env: dict[str, str], turn_id: str, *, native_goal: bool,
9595
]
9696
if not native_goal:
9797
command += ["--turn-instance-id", turn_id]
98-
if env.get("LOOPX_TURN_ENVELOPE", "0") not in {"0", "1"}:
99-
raise ValueError("LOOPX_TURN_ENVELOPE must be 0 or 1")
98+
display = explicit_turn_display(env)
10099
context_dir = env.get("LOOPX_CODEX_CONTEXT_DIR") if env.get("LOOPX_CONTEXT_DELIVERY") == "on" else None
101-
if env.get("LOOPX_TURN_ENVELOPE") == "1" or decision_handoff_socket is not None or context_dir:
100+
if display.complete_turn or display.turn_envelope or decision_handoff_socket is not None or context_dir:
102101
if native_goal:
103102
raise ValueError("TurnEnvelope capture requires a host-owned heartbeat Turn")
104103
# Wake identity comes from this worker, never from model-authored text.
105104
root = Path(env["LOOPX_WAKE_LOG_DIR"]) / turn_id / "decisions"
106105
root.mkdir(mode=0o700, exist_ok=False)
107106
command += ["--decision-output-root", str(root)]
108-
if env.get("LOOPX_TURN_ENVELOPE") == "1":
107+
if display.turn_envelope:
109108
command += ["--turn-envelope"]
109+
if display.complete_turn:
110+
command += ["--complete-turn"]
110111
if decision_handoff_socket is not None:
111112
command += ["--decision-handoff-socket", decision_handoff_socket]
112113
if context_dir:
@@ -497,8 +498,7 @@ def _phase_timeout(timeout: float | None, deadline: float | None) -> tuple[float
497498
def run_once(env: dict[str, str]) -> dict:
498499
if env.get("LOOPX_CONTEXT_DELIVERY", "off") not in {"off", "on"}:
499500
raise ValueError("LOOPX_CONTEXT_DELIVERY supports only off or on")
500-
if env.get("LOOPX_TURN_ENVELOPE", "0") not in {"0", "1"}:
501-
raise ValueError("LOOPX_TURN_ENVELOPE must be 0 or 1")
501+
display = explicit_turn_display(env)
502502
execution = Execution(
503503
mode=env.get("LOOPX_EXECUTION_MODE", "heartbeat"),
504504
context=env.get("LOOPX_ITERATION_CONTEXT"),
@@ -507,10 +507,11 @@ def run_once(env: dict[str, str]) -> dict:
507507
if env.get("LOOPX_CODEX_TURN_TIMEOUT_SEC") else None),
508508
validation_command=json.loads(env.get("LOOPX_VALIDATION_COMMAND_JSON", "[]")),
509509
task_entry=env.get("LOOPX_TASK_ENTRY"),
510-
turn_envelope=env.get("LOOPX_TURN_ENVELOPE", "0") == "1",
510+
turn_envelope=display.turn_envelope,
511511
context_delivery=env.get("LOOPX_CONTEXT_DELIVERY"),
512512
native_child_limit=(int(env["LOOPX_NATIVE_CHILD_LIMIT"])
513513
if env.get("LOOPX_NATIVE_CHILD_LIMIT") else None),
514+
complete_turn=display.complete_turn,
514515
)
515516
request_admission = False
516517
if env.get("LOOPX_PROVIDER_REQUEST_ADMISSION", "off") != "off":
@@ -557,6 +558,8 @@ def run_once(env: dict[str, str]) -> dict:
557558
if observation_producer is not None else {}),
558559
**({"turn_envelope": True, "turn_envelope_source": "explicit"}
559560
if execution.turn_envelope else {}),
561+
**({"complete_turn": True, "complete_turn_source": "explicit"}
562+
if execution.complete_turn else {}),
560563
**({"context_delivery": "on"} if execution.context_delivery != "off" else {}),
561564
**({"native_child_limit": execution.native_child_limit}
562565
if execution.native_child_limit is not None else {}),

0 commit comments

Comments
 (0)