fix(branch-start): archive un-appliable auto-transfer stash instead of leaking it#644
Merged
Conversation
…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>
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. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When protected-branch changes are auto-transferred into a new agent worktree and both the worktree
stash applyand the fallback restore-apply fail,restore_auto_transfer_stash_on_failureleft the stash in the stash list forever. Over many agent runs these accumulate — one real repo (recodee) reached 994guardex-auto-transferstashes, slowing everygit status/ shell prompt and clutteringgit 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 viagit stash apply <ref>, but no longer piles up.archive_auto_transfer_stashhelperGUARDEX_TEST_FAIL_RESTORE_APPLYtest hook to drive the path deterministicallyTests
archives the auto-transfer stash instead of leaking it when restore also fails— RED before / GREEN after.🤖 Generated with Claude Code