Skip to content

Commit fbe25ff

Browse files
loopx-agenthuangruiteng
authored andcommitted
test(context): restore native recovery coverage for file manifests
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
1 parent 5e26851 commit fbe25ff

3 files changed

Lines changed: 43 additions & 10 deletions

File tree

‎tests/control_plane/codex_checkpoint_fixture.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def delivered_context(request, digest):
4545
return raw.decode().rstrip("\n")
4646

4747

48-
def last_context_page(request):
48+
def last_context_page(request, *, allow_reference=False):
49+
"""Observe the latest tool result; a saved-file reference is not a page."""
4950
for item in reversed(request["input"]):
5051
output = item.get("output")
5152
parts = [p.get("text", "") for p in output] if isinstance(output, list) else [output]
@@ -56,10 +57,18 @@ def last_context_page(request):
5657
value = json.loads(part.split("\nOutput:\n", 1)[-1])
5758
if isinstance(value, dict) and value.get("exit_code") == 0:
5859
value = json.loads(value["output"])
59-
if isinstance(value, dict) and value.get("schema_version") == "context_capture_page_v1":
60+
if isinstance(value, dict) and (
61+
value.get("schema_version") == "context_capture_page_v1"
62+
or (allow_reference and value.get("mode") in {"full", "delta"}
63+
and all(key in value for key in ("path", "sha256", "command", "target", "recovery")))
64+
):
6065
return value
6166
except (ValueError, KeyError):
62-
continue
67+
return None
68+
if output is not None:
69+
# An earlier valid response cannot repair a missing or malformed
70+
# current result in the model's input.
71+
return None
6372
return None
6473

6574

‎tests/control_plane/test_codex_context_capture.py‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,11 @@ def response(request, number, message):
275275
if qualified_resume:
276276
# Actual worker process exit/resume, qualified by the shared
277277
# native-selected replay checkpoint. No old full prefetch.
278-
assert ("LoopX context baseline invalidated." in _input_text(request)) == bool(resume_loss)
278+
assert ("LoopX model-context baseline invalidated." in _input_text(request)) == bool(resume_loss)
279279
stages["phase"] = "warm_ready"
280280
cmd = invoke("warm")
281281
else:
282-
assert "LoopX context baseline invalidated." in _input_text(request)
282+
assert "LoopX model-context baseline invalidated." in _input_text(request)
283283
assert wires["cold"]["recovery"]["command"] in _input_text(request)
284284
# Unqualified native histories still recover the exact
285285
# original before continuing its dependent decision.
@@ -297,7 +297,7 @@ def response(request, number, message):
297297
# The native consumer must discover the next command from its
298298
# actual retained input. Disk reads below are independent expected
299299
# byte/state oracles, never a substitute for a truncated guard.
300-
descriptor = _last_page(request)
300+
descriptor = _last_page(request, allow_reference=True)
301301
assert descriptor and descriptor["ok"], "native guard is not complete model-visible JSON"
302302
assert descriptor == json.loads(wire_paths[name].read_bytes())
303303
assert len(json.dumps(descriptor, ensure_ascii=False, separators=(",", ":")).encode()) + 1 <= (native_guard_output_bytes or 64000)
@@ -308,12 +308,19 @@ def response(request, number, message):
308308
wires[name] = json.loads(wire_file.read_text())
309309
assert descriptor["mode"] == wires[name]["mode"] == ("full" if name == "cold" or resume_loss else "delta")
310310
assert "Native input observation independently verifies" not in descriptor["instruction"]
311-
if name == "warm" and not resume_loss:
311+
if name == "warm" and not resume_loss and "content" in descriptor:
312312
assert json.dumps(wires[name]["instruction"]).encode() in descriptor["content"].encode()
313313
capture = Path(wires[name]["recovery"]["path"]).parent / "decision.json"
314314
snapshots.append((capture, capture.read_bytes()))
315315
read_paths[name] = Path(wires[name]["recovery"]["path"]) if wires[name]["mode"] == "full" else wire_file
316-
stages["pages"] = ([descriptor["next_command"]] if not descriptor["eof"] else []) if bounded_pages else pages(name, read_paths[name])
316+
if "content" not in descriptor:
317+
# File-first delivery is a reference, not an already-read page.
318+
# Discover the read from model-visible output, never from the
319+
# independent disk oracle. Recovery after compaction remains
320+
# governed by the same admitted Turn's working brief below.
321+
stages["pages"] = [descriptor["command"]] if bounded_pages else pages(name, read_paths[name])
322+
else:
323+
stages["pages"] = ([descriptor["next_command"]] if not descriptor["eof"] else []) if bounded_pages else pages(name, read_paths[name])
317324
page_digests[name] = descriptor["sha256"]
318325
stages["phase"] = name + "_read"
319326
if not stages["pages"]:
@@ -361,7 +368,7 @@ def response(request, number, message):
361368
return message
362369
if hook_loss:
363370
text = _input_text(request)
364-
assert "LoopX context baseline invalidated." not in text
371+
assert "LoopX model-context baseline invalidated." not in text
365372
# The recovery entry must really be present after compaction;
366373
# the fixture may not supply a hidden saved capture path.
367374
prefix = "Before dependent action, recover missing or uncertain necessary facts"
@@ -372,7 +379,7 @@ def response(request, number, message):
372379
stages["phase"] = "lookup_read"
373380
assert delivered(request, "cold") == "" and delivered(request, "warm") == ""
374381
return tool(cmd, number)
375-
assert "LoopX context baseline invalidated." in _input_text(request)
382+
assert "LoopX model-context baseline invalidated." in _input_text(request)
376383
assert wires["warm"]["recovery"]["command"] in _input_text(request)
377384
assert delivered(request, "cold") == "" and delivered(request, "warm") == ""
378385
stages["phase"] = "recovered"

‎tests/control_plane/test_context_capture_selection.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,28 @@
66

77
import pytest
88

9+
from tests.control_plane.codex_checkpoint_fixture import last_context_page
910
from loopx.cli_commands.quota_capture import read_context_capture
1011
from loopx.control_plane.turn_driver.decision_capture import capture_page_range
1112
from test_quota_settlement_cli import _run_cli
1213

1314

15+
@pytest.mark.parametrize("wrapped", [False, True])
16+
def test_native_saved_reference_is_not_reader_coverage(wrapped):
17+
reference = {"ok": True, "mode": "full", "path": "saved.json", "sha256": "digest",
18+
"command": "read saved.json", "target": {}, "recovery": {}}
19+
output = json.dumps(reference)
20+
if wrapped:
21+
output = [{"type": "input_text", "text": json.dumps({"exit_code": 0, "output": output})}]
22+
item = {"type": "custom_tool_call_output" if wrapped else "function_call_output", "output": output}
23+
request = {"input": [item]}
24+
assert last_context_page(request) is None
25+
assert last_context_page(request, allow_reference=True) == reference
26+
# A damaged current response cannot borrow the earlier complete reference.
27+
request["input"].append({"type": "function_call_output", "output": '{"ok":true'})
28+
assert last_context_page(request, allow_reference=True) is None
29+
30+
1431
def fixture_capture(tmp_path):
1532
original = {"rows": [{"text": "保留末尾约束🙂" * 90, "tail": "stop if unavailable"}],
1633
"a/b": {"~": None}, "large": 9007199254740993, "optional": "other evidence"}

0 commit comments

Comments
 (0)