Repository navigation
fix(core): remove an owned file only when the removed entry is the checked one - #485
Merged
Merged
Conversation
…ecked one unlinkOwnedFile now moves the entry to a removal name that only its call uses, checks it there and unlinks it there. A replacement made before the move goes back under its name, and one made after the move stays where it is. Prune and teardown put back entries that a stopped remover left under a removal name. The teardown staging cleanup uses the same check, and the errors name a removal instead of an atomic write.
A removal name that already exists is skipped, so a process that reuses a stopped remover's pid cannot move onto an entry kept there. Directories stay under their removal name, because putting one back could replace an empty directory. A restore that a concurrent restore finished first succeeds. An abandoned removal that cannot go back counts as the retained or coordination file it was, and prune keeps stopped.json while an entry that arrived meanwhile remains.
A removal name now ends in a random UUID, so the move cannot land on an entry that a stopped remover left or that a restore puts back under a removal name. Teardown also removes a staging file that a stopped teardown left under a removal name after its original name was taken again.
A removal name holds the original name only when the result fits in 255 bytes. A longer name is left out, so the file is still removed, and a crash midway leaves an entry that prune keeps as unknown data.
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.
DirHandle.unlinkOwnedFilechecked an entry withlstatand then unlinked it by name. A file that replaced the entry between those two syscalls was removed. Session prune, evidence export and screenshots use this helper, and teardown cleaned lease staging files by name with no check at all.Now the entry first moves to a removal name that only this call knows, with a random UUID in it. It is checked there and unlinked there. A replacement made before the move goes back under its name with a link, which never replaces anything. A replacement made after the move stays where it is. Prune and teardown put back entries that a stopped remover left under a removal name. When the original name was taken again, they treat the entry as the file it was. Teardown's staging cleanup uses the same removal. The errors now name a removal: "File to remove is gone", "File to remove was replaced, so it was kept", or "...the replacement was kept as ".
Closes #472
Rollback: revert the merge commit. An entry that this version left under a removal name then reads as unknown data, so the older prune keeps its directory and nothing is lost.
before-new-tests.log,core-r3.logr2-before.log,qa/af1793d/j2toj5retainSessionLogsr3-before.log,core-r3.logcore-r3.logbefore-new-tests.logcore-r3.logsession prunethrough the built CLIPICKFORGE_HOMEqa/af1793d/r4-before.log,core-r4.logtsc --noEmit; PickCheck; gitleakscore-r4.log,typecheck-r4.log,pickcheck-r4.json,gitleaks-r4.logKnown limits: a name too long to keep in its removal name is removed the same way, but a crash midway leaves an entry that prune keeps as unknown data. A directory that replaces a log during prune stays under its removal name, and its session directory is kept, as main keeps any stray subdirectory. A log written into a retained directory after prune's last listing, and before stopped.json goes, leaves that directory without stopped.json; teardown confirms the session's processes are gone first, so no writer exists then.
Evidence paths are under
~/.pickforge/investigations/472/on the author's machine.Council review, 3 rounds and a recheck:
The Kimi seat did not run: its OpenCode Go weekly usage limit was reached. Declined, with both other seats accepting the answers: a log written after prune's last listing (no writer exists after teardown), a restore that returns false when the name frees up at that moment (the next prune restores it), a directory left under a removal name (kept as main keeps stray subdirectories), and a stray marker removal in the sessions root whose name was taken again (one file, no directory kept).