Skip to content

Commit ec90739

Browse files
committed
test(benchmark): qualify native context through joint checkpoints
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
1 parent 9558f75 commit ec90739

7 files changed

Lines changed: 298 additions & 76 deletions

‎benchmark/README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,15 @@ CKPT_GUEST_NODE=/absolute/path/to/node
789789
--output "$CKPT_PROVIDER_ROOT/joint-result"
790790
```
791791

792+
Pass `--context-delivery on` with a supported native hook host (Codex CLI
793+
`0.162.1`) to qualify the opt-in transport in the same joint path. The source
794+
must actually deliver a complete full packet and later deltas across worker
795+
wakes; every fresh receiver must begin with a complete current full packet.
796+
The static inference follows model-visible page cursors, and a separate byte-map
797+
oracle checks complete delivery and retained delta bases before candidate work.
798+
The default remains `off`. Neither mode measures paid inference, task quality or
799+
fees; reusing a point still does not count its source test as passed in this run.
800+
792801
The public fixture runs six actual native work wakes, captures the pending
793802
pre-decision guard and continues the source; the ordinary and stride receivers
794803
then use separate fresh guests with no mounted source authority. It includes a

‎benchmark/tests/qualify_checkpoint_joint.py‎

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def main():
5353
parser.add_argument("--guest-dependencies", type=Path, required=True)
5454
parser.add_argument("--output", type=Path, required=True)
5555
parser.add_argument("--image", default="python:3.12-slim")
56+
parser.add_argument("--context-delivery", choices=("off", "on"), default="off",
57+
help="Qualify the existing opt-in context transport through source and fresh receivers")
5658
parser.add_argument("--reuse-point", type=Path, help="Reuse an already sealed synthetic source; never count its source test as passed")
5759
parser.add_argument("--captured-config", type=Path, help="The reused point's matching native fixture configuration")
5860
args = parser.parse_args()
@@ -103,6 +105,7 @@ def main():
103105
"LOOPX_NATIVE_CHECKPOINT_BIN": "/native/codex"}
104106
client = docker.from_env(timeout=30)
105107
image = client.images.get(args.image).id # Caller-prepared image, no implicit pull.
108+
context_results = {}
106109

107110
def guest(command, volumes, env, log, *, capture_supervisor=None):
108111
container = client.containers.create(image, command, platform="linux/amd64",
@@ -117,6 +120,12 @@ def guest(command, volumes, env, log, *, capture_supervisor=None):
117120
log.write_bytes(container.logs())
118121
assert status["StatusCode"] == 0, f"Qualification failed; inspect {log}"
119122
require_one_pass(log.parent / log.stem / "junit.xml")
123+
if env.get("LOOPX_CONTEXT_DELIVERY") == "on":
124+
reports = list((log.parent / log.stem).rglob("context-delivery-result.json"))
125+
assert len(reports) == 1
126+
context_results[log.stem] = json.loads(reports[0].read_bytes())
127+
assert context_results[log.stem]["context_delivery"] == "on"
128+
assert context_results[log.stem]["reads"][0]["mode"] == "full"
120129
finally:
121130
if capture_supervisor:
122131
capture_supervisor.close()
@@ -153,11 +162,19 @@ def guest(command, volumes, env, log, *, capture_supervisor=None):
153162
script = ("from pathlib import Path; import time,pytest; "
154163
"p=Path('/opt/loopx-benchmark/control'); p.mkdir(parents=True); "
155164
f"(p/'phase-deadline').write_text(str(int(time.time())+{SYNTHETIC_PHASE_SECONDS})); "
156-
"raise SystemExit(pytest.main(["
165+
"code=pytest.main(["
157166
"'/source/benchmark/tests/test_native_checkpoint_handoff.py::"
158-
"test_actual_worker_captures_pending_replan_before_native_model[planning]',"
167+
f"test_actual_worker_captures_pending_replan_before_native_model[{args.context_delivery}-planning]',"
159168
"'-q','-rs','-p','no:cacheprovider','--basetemp=/qualification/source-tmp',"
160-
"'--junitxml=/qualification/source.xml']))")
169+
"'--junitxml=/qualification/source.xml']); ")
170+
if args.context_delivery == "on":
171+
# Copy the declared report while the source writer is alive;
172+
# its root-owned pytest directory stays private to that guest.
173+
script += ("\nif code == 0:\n"
174+
" reports=list(Path('/qualification/source-tmp').rglob('controller-result.json'))\n"
175+
" assert len(reports) == 1\n"
176+
" Path('/qualification/context-delivery-source.json').write_bytes(reports[0].read_bytes())\n")
177+
script += "\nraise SystemExit(code)"
161178
container = client.containers.create(image, ["python", "-c", script],
162179
platform="linux/amd64", network_disabled=True,
163180
volumes={**base, str(source_files): {"bind": "/qualification", "mode": "rw"}},
@@ -172,6 +189,18 @@ def guest(command, volumes, env, log, *, capture_supervisor=None):
172189
supervisor.close()
173190
assert status["StatusCode"] == 0, f"Inspect {output / 'source.log'}"
174191
require_one_pass(source_files / "source.xml")
192+
if args.context_delivery == "on":
193+
# The real source writer may be root. Its private pytest
194+
# directory is intentionally unreadable to this controller;
195+
# stage only the declared result through the daemon seam.
196+
from benchmark.edgebench.checkpoint_worker import _archive
197+
report = _archive(container, "/qualification/context-delivery-source.json",
198+
output / "source-context-result.json")
199+
report.chmod(0o600)
200+
context_results["source"] = json.loads(report.read_bytes())
201+
assert context_results["source"]["context_delivery"] == "on"
202+
reads = context_results["source"]["context_reads"]
203+
assert reads[0]["mode"] == "full" and any(row["mode"] == "delta" for row in reads[1:])
175204
points = [p for p in (output / "points").iterdir() if p.is_dir() and not p.name.startswith(".")]
176205
assert len(points) == 1 and len(grades) == 1
177206
point = points[0]
@@ -222,6 +251,7 @@ def guest(command, volumes, env, log, *, capture_supervisor=None):
222251
str(results): {"bind": "/results", "mode": "rw"}, **extra_volumes},
223252
{"LOOPX_JOINT_RECEIVER_POINT": "/point", "LOOPX_JOINT_RECEIVER_CONFIG": "/captured-config.toml",
224253
"LOOPX_RUNTIME_ROOT": "/results/transport-runtime",
254+
"LOOPX_CONTEXT_DELIVERY": args.context_delivery,
225255
**({"LOOPX_JOINT_RECEIVER_STRIDE": "1"} if stride else {}),
226256
**extra_env},
227257
output / f"{name}.log", capture_supervisor=capture_supervisor)
@@ -245,7 +275,8 @@ def guest(command, volumes, env, log, *, capture_supervisor=None):
245275
str(third): {"bind": "/results", "mode": "rw"}},
246276
{"LOOPX_JOINT_RECEIVER_POINT": "/point", "LOOPX_JOINT_RECEIVER_CONFIG": "/captured-config.toml",
247277
"LOOPX_JOINT_RECEIVER_GOAL": "joint-grandreceiver", "LOOPX_JOINT_RECEIVER_AGENT": "joint-grandresearcher",
248-
"LOOPX_RUNTIME_ROOT": "/results/transport-runtime"},
278+
"LOOPX_RUNTIME_ROOT": "/results/transport-runtime",
279+
"LOOPX_CONTEXT_DELIVERY": args.context_delivery},
249280
output / "grandreceiver.log")
250281
assert not grades if args.reuse_point else len(grades) == 1
251282
# The same native provider must also complete the public Core journey
@@ -262,6 +293,8 @@ def guest(command, volumes, env, log, *, capture_supervisor=None):
262293
assert not subprocess.check_output(["git", "-C", str(source), "status", "--porcelain"], text=True).strip(), "Source changed during qualification"
263294
receipt = {"passed": True, "controller_uid": os.getuid(), "provider_revision": args.provider_revision,
264295
"source_revision": source_revision, "source_tree_dirty": False,
296+
"context_delivery": args.context_delivery,
297+
"native_context_reads": context_results,
265298
"qualification_sha256": {p.name: hashlib.sha256(p.read_bytes()).hexdigest() for p in
266299
[Path(__file__), source / "benchmark/tests/test_native_checkpoint_handoff.py",
267300
source / "benchmark/tests/test_checkpoint_joint_receiver.py",

‎benchmark/tests/test_checkpoint_joint_receiver.py‎

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def cli(*args):
186186
"--text",
187187
"Use retained code and evidence for one synthetic candidate, then verify its native result.",
188188
)["todo_id"]
189-
execution = Execution(context="resume")
189+
execution = Execution(context="resume", context_delivery=os.environ.get("LOOPX_CONTEXT_DELIVERY", "off"))
190190
env = {
191191
**os.environ,
192192
"CODEX_BIN": os.environ["LOOPX_NATIVE_CHECKPOINT_BIN"],
@@ -203,6 +203,13 @@ def cli(*args):
203203
"OPENAI_API_KEY": "synthetic-local-only",
204204
"LOOPX_USAGE_PING": "0",
205205
}
206+
if execution.context_delivery == "on":
207+
from benchmark.runtime.context_delivery import prepare_context_delivery
208+
executable = tmp_path / "loopx-cli"
209+
executable.write_text("#!/bin/sh\nexec " + shlex.quote(sys.executable) + ' -m loopx.cli "$@"\n')
210+
executable.chmod(0o700)
211+
env.update(LOOPX_CLI=str(executable), LOOPX_EXECUTION_MODE=execution.mode,
212+
LOOPX_CONTEXT_DELIVERY=execution.context_delivery)
206213
with pytest.raises(ValueError, match="distinct destination"):
207214
admit_native_checkpoint_session(
208215
{**env, "LOOPX_GOAL_ID": metadata["loopx_state"]["goal_id"]},
@@ -240,6 +247,8 @@ def lose_binding_reply(self, *args):
240247
env, unit, digest, config, sandbox=(execution).sandbox, timeout=30
241248
)
242249
assert replay["session_id"] == admitted["session_id"] and replay["history_verified"]
250+
if execution.context_delivery == "on":
251+
prepare_context_delivery(env, home)
243252
lease = cli(
244253
"task-lease",
245254
"acquire",
@@ -404,6 +413,8 @@ def lose_binding_reply(self, *args):
404413
)
405414
)
406415
requests = []
416+
from tests.control_plane.codex_checkpoint_fixture import NativeContextReader, native_context_command
417+
reader = NativeContextReader()
407418
provider_phase = {
408419
"count": 0,
409420
"command": "cat "
@@ -422,7 +433,14 @@ def do_POST(self):
422433
json.loads(self.rfile.read(int(self.headers["Content-Length"])))
423434
)
424435
provider_phase["count"] += 1
425-
if provider_phase["count"] == 1:
436+
message = reader.follow(requests[-1]) if execution.context_delivery == "on" else None
437+
if execution.context_delivery == "on" and not provider_phase.get("context_started"):
438+
provider_phase["context_started"] = True
439+
message = reader.begin(native_context_command(requests[-1]), "fresh-receiver")
440+
if message is not None:
441+
pass
442+
elif not provider_phase.get("work_sent"):
443+
provider_phase["work_sent"] = True
426444
message = {
427445
"type": "function_call",
428446
"id": "fc_receiver",
@@ -482,6 +500,16 @@ def do_POST(self):
482500

483501
def run_native_work(current_guard, logs, purpose):
484502
logs.mkdir()
503+
provider_phase.update(context_started=False, work_sent=False)
504+
native_input = json.dumps(current_guard["interaction_contract"]) + "\n" + purpose
505+
if execution.context_delivery == "on":
506+
from benchmark.runtime.context_delivery import preflight_context_instruction
507+
original = logs / "original-guard.json"
508+
original.write_text(json.dumps(current_guard))
509+
original.chmod(0o600)
510+
native_input = preflight_context_instruction(env, original,
511+
hashlib.sha256(original.read_bytes()).hexdigest(),
512+
current_guard["heartbeat_receipt"]["turn_instance_id"]) + "\n" + purpose
485513
wake = BenchmarkSessionWake(env, execution, {})
486514
command = native_command(env, execution, "execute", logs, wake)
487515
result = subprocess.run(
@@ -494,7 +522,7 @@ def run_native_work(current_guard, logs, purpose):
494522
],
495523
env=env,
496524
cwd=workspace,
497-
input=json.dumps(current_guard["interaction_contract"]) + "\n" + purpose,
525+
input=native_input,
498526
text=True,
499527
capture_output=True,
500528
timeout=60,
@@ -511,18 +539,21 @@ def run_native_work(current_guard, logs, purpose):
511539
"This is a new destination. Historical source commands/guards are not executable authority. "
512540
"Use the retained context under the current admission, and continue the synthetic candidate.",
513541
)
514-
assert len(requests) == 2
542+
if execution.context_delivery == "off":
543+
assert len(requests) == 2
544+
else:
545+
assert len(reader.deliveries) == 1 and reader.deliveries[0]["mode"] == "full"
515546
expected = (
516547
"Restored state verified"
517548
if stride_continuation
518549
else "cooldown still blocks submission"
519550
if cooldown_pending
520551
else "candidate 8 graded"
521552
)
522-
assert expected in json.dumps(requests[1]), json.dumps(
553+
assert expected in json.dumps(requests[-1]), json.dumps(
523554
[
524555
item
525-
for item in requests[1].get("input", [])
556+
for item in requests[-1].get("input", [])
526557
if item.get("type") == "function_call_output"
527558
]
528559
)
@@ -872,9 +903,9 @@ def run_native_work(current_guard, logs, purpose):
872903
tmp_path / "larger-work",
873904
"Execute the current grow decision as one complete two-candidate experiment. Old guards are evidence only.",
874905
)
875-
assert len(requests) == 4 and "Current grow adopted" in json.dumps(
876-
requests[3]
877-
), requests[3]
906+
if execution.context_delivery == "off":
907+
assert len(requests) == 4
908+
assert "Current grow adopted" in json.dumps(requests[-1]), requests[-1]
878909
assert (
879910
candidate.read_text() == "10"
880911
and not grades
@@ -1047,6 +1078,10 @@ def run_native_work(current_guard, logs, purpose):
10471078
).hexdigest()
10481079
== metadata["research_context"]["sha256"]
10491080
)
1081+
(tmp_path / "context-delivery-result.json").write_text(json.dumps({
1082+
"context_delivery": execution.context_delivery, "reads": reader.deliveries,
1083+
"fresh_receiver": True, "source_authority_unchanged": True,
1084+
}))
10501085
finally:
10511086
server.shutdown()
10521087
thread.join()

0 commit comments

Comments
 (0)