Skip to content

The agent that grows with you

fix(checkpoints): label checkpoints that did not capture a nested repo

unsupportedpastels9ec9028e5006
diff --git a/tests/tools/test_checkpoint_gitlinks.py b/tests/tools/test_checkpoint_gitlinks.py
index b876df48b98..0b7ccdea178 100644
--- a/tests/tools/test_checkpoint_gitlinks.py
+++ b/tests/tools/test_checkpoint_gitlinks.py
@@ -115,6 +115,23 @@ def test_gitlink_name_roundtrips_in_refusal(checkpoint, name):
assert durable_state(work) == before
+def test_checkpoint_listing_discloses_uncaptured_nested_repository(checkpoint, tmp_path):
+ mgr, work, _ = checkpoint
+ entry = mgr.list_checkpoints(str(work))[0]
+ assert entry["reason"] == "baseline [nested git repos not captured: tool]"
+ assert "[nested git repos not captured: tool]" in cm.format_checkpoint_list([entry], str(work))
+
+ plain = tmp_path / "plain"
+ plain.mkdir()
+ (plain / "a.txt").write_text("a\n")
+ assert mgr.ensure_checkpoint(str(plain), "no nested repo")
+ assert mgr.list_checkpoints(str(plain))[0]["reason"] == "no nested repo"
+
+
+def test_checkpoint_disclosure_caps_listed_repositories(checkpoint):
+ assert cm._uncaptured_note(["a", "b", "c", "d", "e"]) == " [nested git repos not captured: a, b, c (+2)]"
+
+
@pytest.fixture
def deep_checkpoint(checkpoint):
mgr, work, _ = checkpoint
diff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.py
index 55bcedae8ce..55987e58af3 100644
--- a/tests/tui_gateway/test_tui_gateway_server.py
+++ b/tests/tui_gateway/test_tui_gateway_server.py
@@ -12123,6 +12123,28 @@ def test_rollback_restore_resolves_number_and_file_path():
assert calls["args"][2] == "src/app.tsx"
+def test_rollback_list_carries_checkpoint_reason_as_message():
+ reason = "before write_file: a.py [nested git repos not captured: tool]"
+
+ class _Mgr:
+ enabled = True
+
+ def list_checkpoints(self, cwd):
+ return [{"hash": "aaa111", "short_hash": "aaa", "timestamp": "2026-09-29T10:00:00+00:00",
+ "reason": reason, "files_changed": 1}]
+
+ server._sessions["sid"] = _session(
+ agent=types.SimpleNamespace(_checkpoint_mgr=_Mgr()), history=[]
+ )
+ resp = server.handle_request(
+ {"id": "1", "method": "rollback.list", "params": {"session_id": "sid"}}
+ )
+
+ row = resp["result"]["checkpoints"][0]
+ assert row["hash"] == "aaa111"
+ assert row["message"] == reason
+
+
def test_rollback_restore_truncates_from_real_user_turn_not_marker(monkeypatch):
"""rollback.restore must truncate from the last *real* user turn,
not a display_kind timeline marker (same bug class as /undo).
diff --git a/tools/checkpoint_manager.py b/tools/checkpoint_manager.py
index a87d5071259..bbe22b419a1 100644
--- a/tools/checkpoint_manager.py
+++ b/tools/checkpoint_manager.py
@@ -287,6 +287,24 @@ def _ref_name(dir_hash: str) -> str:
return f"{_REFS_PREFIX}/{dir_hash}"
+def _gitlink_paths(ls_tree_z: str) -> List[str]:
+ """Paths of gitlinks (nested repositories stored as a commit reference, not
+ their files) in ``git ls-tree -r -z`` output."""
+ return [
+ record.split("\t", 1)[1]
+ for record in ls_tree_z.split("\x00")
+ if record.startswith("160000 commit ") and "\t" in record
+ ]
+
+
+def _uncaptured_note(nested_repos: List[str]) -> str:
+ """Checkpoint-message suffix naming nested repositories whose files were
+ not captured, so every /rollback listing discloses it."""
+ shown = ", ".join(nested_repos[:3])
+ more = f" (+{len(nested_repos) - 3})" if len(nested_repos) > 3 else ""
+ return f" [nested git repos not captured: {shown}{more}]"
+
+
def _project_meta_path(store: Path, dir_hash: str) -> Path:
return store / _PROJECTS_DIRNAME / f"{dir_hash}.json"
@@ -1149,11 +1167,7 @@ class CheckpointManager:
)
if not ok:
return {"success": False, "error": f"Could not inspect checkpoint: {err}"}
- nested_repos = [
- record.split("\t", 1)[1]
- for record in tree_out.split("\x00")
- if record.startswith("160000 commit ") and "\t" in record
- ]
+ nested_repos = _gitlink_paths(tree_out)
if nested_repos:
blocked_repos = nested_repos
if file_path:
@@ -1470,6 +1484,15 @@ class CheckpointManager:
logger.debug("Checkpoint write-tree failed: %s", err)
return False
+ # A nested repository is stored as a gitlink, not its files: say so in
+ # the checkpoint itself rather than only when a rollback is refused.
+ ok_ls, tree_out, _ = _run_git(["ls-tree", "-r", "-z", tree_sha], store, working_dir)
+ nested_repos = _gitlink_paths(tree_out) if ok_ls else []
+ if nested_repos:
+ logger.info("Checkpoint of %s does not capture nested git repositories: %s",
+ working_dir, ", ".join(nested_repos))
+ reason += _uncaptured_note(nested_repos)
+
# Build commit (parent = current ref tip, if any).
commit_args = ["commit-tree", tree_sha, "-m", reason, "--no-gpg-sign"]
if has_ref:
diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.py
index 48345a5d143..c37e47ac94e 100644
--- a/tui_gateway/methods_tools.py
+++ b/tui_gateway/methods_tools.py
@@ -1096,8 +1096,9 @@ def _(rid, params: dict, session) -> dict:
def go(mgr, cwd):
if not mgr.enabled:
return _ok(rid, {"enabled": False, "checkpoints": []})
- keys = ("hash", "timestamp", "message")
- rows = [{k: c.get(k, "") for k in keys} for c in mgr.list_checkpoints(cwd)]
+ # The TUI renders ``message``; the manager calls it ``reason``.
+ rows = [{"hash": c.get("hash", ""), "timestamp": c.get("timestamp", ""), "message": c.get("reason", "")}
+ for c in mgr.list_checkpoints(cwd)]
return _ok(rid, {"enabled": True, "checkpoints": rows})
return _with_checkpoints(session, go)
diff --git a/website/docs/user-guide/checkpoints-and-rollback.md b/website/docs/user-guide/checkpoints-and-rollback.md
index edf11cfef22..d9a8ea916e1 100644
--- a/website/docs/user-guide/checkpoints-and-rollback.md
+++ b/website/docs/user-guide/checkpoints-and-rollback.md
@@ -239,7 +239,9 @@ Restore just one file from a checkpoint without affecting the rest of the direct
A checkpoint of a parent directory can store a nested repository as a Git
**gitlink** (a commit reference), not a copy of its files. Recursive capture of
nested repositories is not supported: their uncommitted edits and untracked
-files are not recoverable from that parent checkpoint.
+files are not recoverable from that parent checkpoint. Checkpoints taken by this
+version or later are labelled in `/rollback` listings, for example
+`before write_file: app.py [nested git repos not captured: tool]`.
If the selected checkpoint contains gitlinks, a full rollback (including
`--all`) is refused before changing files or creating a pre-rollback snapshot.