Repository navigation
fix(checkpoint): recheck native binding without mutating capture witness #7240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| """A capture recheck must not mutate its source, or overlook a real change.""" | ||
| import json | ||
| import sys | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def source(tmp_path, capsys): | ||
| from loopx.cli import main | ||
| from loopx.control_plane.turn_driver.codex_agent_session import CodexAgentSession | ||
| from loopx.control_plane.turn_driver.codex_sessions import _store_codex_cli_session | ||
| from loopx.hosts.research_checkpoint import native_binding_participant | ||
|
|
||
| project, runtime, home = (tmp_path / name for name in ("project", "runtime", "home")) | ||
| for path in (project, runtime, home): | ||
| path.mkdir() | ||
| registry = project / ".loopx/registry.json" | ||
| (home / "config.toml").write_text("[features]\ngoals=false\n") | ||
| prefix = ["--format", "json", "--registry", str(registry), "--runtime-root", str(runtime)] | ||
| for argv in (["bootstrap", "--project", str(project), "--goal-id", "source", | ||
| "--objective", "Preserve a synthetic candidate.", "--no-global-sync"], | ||
| ["configure-goal", "--goal-id", "source", "--registered-agent", "agent", "--execute"]): | ||
| code = main([*prefix, *argv]) | ||
| assert code == 0, capsys.readouterr().out | ||
| env = {"LOOPX_REGISTRY": str(registry), "LOOPX_RUNTIME_ROOT": str(runtime), | ||
| "LOOPX_PROJECT": str(project), "LOOPX_GOAL_ID": "source", "LOOPX_AGENT_ID": "agent", | ||
| "CODEX_BIN": sys.executable, "CODEX_HOME": str(home), "MODEL_NAME": "synthetic", | ||
| "REASONING_EFFORT": "high", "LOOPX_CODEX_SANDBOX": "read-only"} | ||
| session = CodexAgentSession(env, context="resume", sandbox="read-only", receipt={}) | ||
| _store_codex_cli_session(runtime, lineage=session.lineage, session_scope="agent", | ||
| session_id="source-session", goal_ref=session.goal_ref, session_profile_digest=session.digest) | ||
| components, session, raw = native_binding_participant(env, | ||
| [{"id": "project", "source_path": str(project)}], {"session": {"session_id": "source-session"}}) | ||
| return env, components, session, raw | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("fault", [None, "registry", "session", "profile", "provenance", "config", "missing"]) | ||
| def test_binding_observation_preserves_witness_and_rejects_changes(source, tmp_path, fault): | ||
| from pathlib import Path | ||
| from loopx.control_plane.effect_runtime import effect_runtime_result | ||
| from loopx.control_plane.turn_driver.codex_sessions import _session_path | ||
| from loopx.hosts.research_checkpoint import verify_native_binding_participant | ||
|
|
||
| env, components, session, raw = source | ||
| before = effect_runtime_result("runtime.checkpoint_artifacts", {"action": "probe", "components": components}) | ||
| binding_path = _session_path(session.root, session.lineage, "agent") | ||
| if fault == "registry": | ||
| registry = Path(env["LOOPX_REGISTRY"]) | ||
| registry.write_bytes(registry.read_bytes() + b"\n") | ||
| elif fault == "config": | ||
| (Path(env["CODEX_HOME"]) / "config.toml").write_text("model = 'changed'\n") | ||
| elif fault == "missing": | ||
| binding_path.unlink() | ||
| elif fault: | ||
| value = json.loads(binding_path.read_bytes()) | ||
| value[{"session": "session_id", "profile": "session_profile_digest", | ||
| "provenance": "checkpoint_artifact_sha256"}[fault]] = "changed" | ||
| binding_path.write_text(json.dumps(value)) | ||
| if fault: | ||
| with pytest.raises(ValueError, match="registry moved|binding or profile moved"): | ||
| verify_native_binding_participant(env, session, raw) | ||
| else: | ||
| verify_native_binding_participant(env, session, raw) | ||
| verify_native_binding_participant(env, session, raw) | ||
| after = effect_runtime_result("runtime.checkpoint_artifacts", {"action": "probe", "components": components}) | ||
| assert before == after | ||
| sealed = effect_runtime_result("runtime.checkpoint_artifacts", {"action": "capture", | ||
| "components": components, "destination": str(tmp_path / "point"), "point_metadata": {}, | ||
| "expected_source_sha256": before["source_sha256"]}) | ||
| assert sealed["sha256"] | ||
| # Even advisory lock bytes remain part of the artifact fence. This fix | ||
| # must not introduce a wildcard exclusion for lock-named task files. | ||
| lock = Path(env["LOOPX_REGISTRY"] + ".lock") | ||
| lock.write_text("changed after preparation") | ||
| with pytest.raises(Exception, match="changed|moved|witness"): | ||
| effect_runtime_result("runtime.checkpoint_artifacts", {"action": "capture", | ||
| "components": components, "destination": str(tmp_path / "later"), "point_metadata": {}, | ||
| "expected_source_sha256": before["source_sha256"]}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P3] 同步既有原生绑定变化负例的错误文字断言。按 fixture 自带的 canonical 初始化恢复该扩展用例后,probe-binding 的拒绝、无产物、原 reader 关闭及调用数断言均通过,最后仍期待
profile changed,当前实际返回checkpoint source session binding or profile moved before sealing。这是本次诊断变化的测试同步项;不影响已经验证的安全拒绝,但不能将完整原生变体称为全绿。