From 0ddbc5b04dc3154b65e33a2402141f26cca4d699 Mon Sep 17 00:00:00 2001 From: garrytan Date: Sat, 24 Oct 2026 22:55:59 +0000 Subject: [PATCH] fix(context-restore): name another branch as a cause when the saved commit is not in history Cross-branch resume (Conductor handoff) is a supported restore path, and there the checkpoint's commit is usually not an ancestor of HEAD. The diverged line said only 'rebased, reset, or not fetched'. It now names 'saved on another branch' first; the new test case covers a save on a feature branch restored from main. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --- context-restore/SKILL.md | 4 ++-- context-restore/SKILL.md.tmpl | 4 ++-- test/context-restore-head.test.ts | 12 ++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/context-restore/SKILL.md b/context-restore/SKILL.md index f937eefb7..2cfcc402f 100644 --- a/context-restore/SKILL.md +++ b/context-restore/SKILL.md @@ -560,8 +560,8 @@ fi under **Verify first**: the saving session could not know about those commits, so any step may already be done. - `HEAD_DIVERGED` or `HEAD_UNKNOWN`: print `This checkpoint was saved at {first 7 - characters of head}, which is not in this checkout's history (rebased, reset, or - not fetched).` and list every item under Verify first. + characters of head}, which is not in this checkout's history (saved on another + branch, rebased, reset, or not fetched).` and list every item under Verify first. - `HEAD_UNTRACKED`: print `This checkpoint predates commit tracking; restore cannot tell whether work landed after it.` and sort as usual. diff --git a/context-restore/SKILL.md.tmpl b/context-restore/SKILL.md.tmpl index 4c5f2dd1d..0f4d974ec 100644 --- a/context-restore/SKILL.md.tmpl +++ b/context-restore/SKILL.md.tmpl @@ -236,8 +236,8 @@ fi under **Verify first**: the saving session could not know about those commits, so any step may already be done. - `HEAD_DIVERGED` or `HEAD_UNKNOWN`: print `This checkpoint was saved at {first 7 - characters of head}, which is not in this checkout's history (rebased, reset, or - not fetched).` and list every item under Verify first. + characters of head}, which is not in this checkout's history (saved on another + branch, rebased, reset, or not fetched).` and list every item under Verify first. - `HEAD_UNTRACKED`: print `This checkpoint predates commit tracking; restore cannot tell whether work landed after it.` and sort as usual. diff --git a/test/context-restore-head.test.ts b/test/context-restore-head.test.ts index 8e855e786..7365cb039 100644 --- a/test/context-restore-head.test.ts +++ b/test/context-restore-head.test.ts @@ -144,6 +144,18 @@ describe('context-restore compares the checkpoint with HEAD', () => { expect(headCheck(app, file)).toStartWith('HEAD_DIVERGED '); }); + test('a checkpoint resumed from another branch is reported, and the prompt names that cause', () => { + const app = repo(); + git(app, 'checkout', '-q', '-b', 'feature'); + commit(app, 'feature work'); + const file = save(app); + git(app, 'checkout', '-q', 'main'); + commit(app, 'unrelated main work'); + expect(headCheck(app, file)).toStartWith('HEAD_DIVERGED '); + const restore = fs.readFileSync(path.join(ROOT, 'context-restore/SKILL.md'), 'utf-8'); + expect(restore).toContain('(saved on another\n branch, rebased, reset, or not fetched)'); + }); + test('checkpoints saved before head tracking, or with a malformed head, are never treated as current', () => { const app = repo(); const legacy = path.join(tmp, 'legacy.md');