The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(checkpoints): select nested repo guard scope by recorded path, not symlink target
unsupportedpastels713d09970ffa
diff --git a/tests/tools/test_checkpoint_gitlinks.py b/tests/tools/test_checkpoint_gitlinks.pyindex 5a92c540e75..aa837cdcd26 100644--- a/tests/tools/test_checkpoint_gitlinks.py+++ b/tests/tools/test_checkpoint_gitlinks.py@@ -141,3 +141,34 @@ def test_inspection_failure_leaves_files_and_history_untouched(checkpoint, monkeassert "inspection unavailable" in result["error"]assert durable_state(work) == beforeassert not list(cm._store_path().glob("restore-inspect-*"))++[email protected](os.name == "nt", reason="symlink creation needs privileges on Windows")[email protected]("safe", [False, True])+def test_captured_file_replaced_by_symlink_into_nested_repo_restores(checkpoint, safe):+ mgr, work, commit = checkpoint+ notes = work / "notes.txt"+ notes.unlink()+ notes.symlink_to(work / "tool" / "main.py")+ result = mgr.restore(str(work), commit, file_path="notes.txt", safe=safe)+ assert result["success"] is True, result+ assert not notes.is_symlink()+ assert notes.read_text() == "before\n"+ assert (work / "tool" / "main.py").read_text() == "agent overwrite\n"++[email protected](os.name == "nt", reason="symlink creation needs privileges on Windows")[email protected]("spec", [None, "tool", "tool/main.py"])+def test_gitlink_replaced_by_unrelated_symlink_still_refuses(checkpoint, tmp_path, spec):+ mgr, work, commit = checkpoint+ (work / "tool").rename(tmp_path / "moved-tool")+ other = work / "other"+ other.mkdir()+ (other / "main.py").write_text("unrelated\n")+ (work / "tool").symlink_to(other, target_is_directory=True)+ before = durable_state(work)+ result = mgr.restore(str(work), commit, file_path=spec)+ assert result["success"] is False+ assert result["nested_repositories"] == ["tool"]+ assert (work / "tool").is_symlink()+ assert durable_state(work) == beforediff --git a/tools/checkpoint_manager.py b/tools/checkpoint_manager.pyindex 269e52b9d32..a87d5071259 100644--- a/tools/checkpoint_manager.py+++ b/tools/checkpoint_manager.py@@ -1157,8 +1157,12 @@ class CheckpointManager:if nested_repos:blocked_repos = nested_reposif file_path:- root_path = Path(abs_dir).resolve()- requested_path = (root_path / file_path).resolve()+ # Select by the path as recorded in the checkpoint, not by+ # where it points now: a captured file later replaced by a+ # symlink into a nested repo is still recoverable. Resolved+ # confinement is enforced separately by _validate_file_path.+ root_path = Path(abs_dir)+ requested_path = Path(os.path.normpath(root_path / file_path))try:requested_rel = requested_path.relative_to(root_path)except ValueError: