Repository navigation
fix: safely recover teardown scratch content - #4935
Open
jasonlgong wants to merge 8 commits into
Open
jasonlgong wants to merge 8 commits into
jasonlgong wants to merge 8 commits into
Conversation
Replace destructive teardown scratch cleanup with durable retention plus an explicit refusal for repository-bearing or tracked scratch. Ordinary and ignored untracked scratch is moved into data/<id>/scratch-recovery-*/ (empty dirs rmdir'd) so the slot re-leases; any nested/bare/linked git repo or tracked/staged scratch change causes teardown to refuse with the exact path and preserve the work and task record in place, including under --force. This is a documented safe partial: it does not auto-recover slots that hold a real repository or genuine tracked changes. Refs kunchenguid#4784.
…sing Two fail-closed over-triggers in the scratch retention path refused slots that held no committed work at risk, stranding them for manual cleanup: - Mixed tracked + untracked scratch (e.g. a committed scratch/.gitkeep plus untracked worker output) refused the whole slot. Now only the untracked and ignored subset is relocated to recovery; tracked content is left in place for Treehouse to reset, and the slot re-leases. - An unborn HEAD (a repo with zero commits) made git diff HEAD error, which was read as tracked scratch changes and refused. The check now distinguishes an unresolvable HEAD from a real diff and still preserves staged content, so an unborn HEAD with only untracked scratch takes the ordinary move path. Repository-bearing scratch (nested/bare/linked) and genuine tracked/staged changes are still preserved-not-deleted, including under --force; this stays a documented safe partial that does not auto-recover repo-bearing slots. Refs kunchenguid#4784.
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.
Summary
scratch/or.scratch/content can prevent a returned Treehouse pool slot from being leased again, eventually blocking new task spawns.data/<id>/scratch-recovery-*directory before returning the slot.HEADwith only untracked scratch uses the same recovery path.--force.Validation
75613db1d091d704aad350619a51dab4bab4beefhas a no-mistakes attestation recording completed review, test, document, and lint steps.Limitations
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed (3) ✅
bin/fm-teardown.sh:1767-tracked_scratch_changes()treats every nonzero result fromgit diff --quiet HEAD -- <scratch>other than 1 as an unborn HEAD, then accepts the path when the cached diff is clean. A worktree with a broken/unresolvable existing HEAD and modified tracked scratch can therefore move only untracked files and proceed to reset/delete the modified tracked content. Only an actually unborn HEAD should use the fallback; other Git inspection errors must refuse teardown.🔧 Fix applied.
1 error still open:
bin/fm-teardown.sh:1779-show-ref --verifyonly confirms that the symbolic ref exists; it does not prove that the ref's object is resolvable. IfHEADpoints to an existing branch ref containing an invalid object ID,git diff HEADreturns an error,ref_existsis still 0, and the code falls back to checking only the index. With clean staged content and modified tracked scratch, teardown therefore proceeds and can delete the tracked modification instead of refusing. Validate the target object (for example withgit rev-parse --verify HEAD) before treating this as an unborn HEAD.🔧 Fix applied.
1 error still open:
bin/fm-teardown.sh:1727- The early return skips Git inspection whenever both scratch paths are absent. Deleting the only trackedscratch/fileremovesscratch/, so teardown proceeds and later reset/return discards the tracked deletion instead of refusing. Inspect Git changes forscratchand.scratcheven when the directories are absent.🔧 Fix applied.
✅ Re-checked - no issues remain.
tests/fm-teardown.test.sh:4000- The broader teardown script also reported an unrelated Herdr preflight failure for the missing-adapter case; all change-relevant scratch scenarios passed.bash tests/fm-teardown.test.shbash tests/fm-teardown-endpoint-safety.test.shFocused scratch scenarios captured inteardown-scratch-pass-lines.logEndpoint safety output captured inteardown-endpoint-safety.loggit status --short✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.