Skip to content

fix(branch-start): archive un-appliable auto-transfer stash instead of leaking it#644

Merged
NagyVikt merged 1 commit into
mainfrom
fix/branch-start-stash-leak
Jun 10, 2026
Merged

fix(branch-start): archive un-appliable auto-transfer stash instead of leaking it#644
NagyVikt merged 1 commit into
mainfrom
fix/branch-start-stash-leak

Conversation

@NagyVikt

Copy link
Copy Markdown
Collaborator

Problem

When protected-branch changes are auto-transferred into a new agent worktree and both the worktree stash apply and the fallback restore-apply fail, restore_auto_transfer_stash_on_failure left the stash in the stash list forever. Over many agent runs these accumulate — one real repo (recodee) reached 994 guardex-auto-transfer stashes, slowing every git status / shell prompt and cluttering git stash list.

Fix

On the failed-restore path, archive the stash as a permanent refs/stash-archive/<msg>-<sha> ref and drop the stash entry. Stash entries are already commits, so the ref points at the same object — work stays fully recoverable via git stash apply <ref>, but no longer piles up.

  • add archive_auto_transfer_stash helper
  • archive on failed restore; message prints the recover command
  • add GUARDEX_TEST_FAIL_RESTORE_APPLY test hook to drive the path deterministically

Tests

  • New test archives the auto-transfer stash instead of leaking it when restore also failsRED before / GREEN after.
  • Baseline-red repo: full suite 662→663 pass, 28→28 fail, failing set byte-identical by name (zero new failures).

🤖 Generated with Claude Code

…f leaking it

When protected-branch changes are auto-transferred to a new agent worktree and
both the worktree apply AND the fallback restore-apply fail, the stash was left
in the stash list forever. Over many agent runs this accumulated (one repo hit
994 guardex-auto-transfer stashes), slowing every git status / prompt.

Now a failed restore archives the stash as a permanent refs/stash-archive/<msg>
ref and drops the stash entry. Work stays fully recoverable (git stash apply
<ref>) but no longer piles up in the stash list.

- add archive_auto_transfer_stash helper (ref points at the stash commit)
- archive on the failed-restore path; message tells the user the recover cmd
- add GUARDEX_TEST_FAIL_RESTORE_APPLY test hook to drive the path
- test: RED before / GREEN after; failing set unchanged (baseline-red repo)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@NagyVikt NagyVikt merged commit cc3d198 into main Jun 10, 2026
2 of 3 checks passed
@NagyVikt NagyVikt deleted the fix/branch-start-stash-leak branch June 10, 2026 12:48
@NagyVikt

Copy link
Copy Markdown
Collaborator Author

AI code review (gated-ship): 0 CRITICAL / 0 HIGH / 0 MEDIUM. Surgical fix on the EXIT-trap restore path covers all failure exits; reuses env_flag_truthy, git-validated ref name with graceful fallback. Gate: full suite 662→663 pass, failing set byte-identical (zero new failures); new test RED→GREEN. Merged via --admin past baseline-red CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant