Repository navigation
fix(core): prune session directories left without stopped.json - #435
Merged
Merged
Conversation
A prune that stopped after unlinking stopped.json and before rmdir left an empty directory that later prunes skipped forever, together with the session markers it kept. Prune now removes such a directory once its mtime is past the marker horizon and no record or session lock exists. rmdir refuses a directory that gained an entry, so this path never deletes data. Refs #414
…led caller A first permit or lease caller that stalls past teardown and prune rebuilds the session directory without stopped.json, with permits/ and a new takeover identity. Prune skipped it forever, and the identity with it. Prune now removes a directory without stopped.json when no record or lock exists, the directory and every entry are older than the marker horizon, and every entry is an allowlisted permit or lease file whose owner or writer is gone. Any other entry keeps the directory. After its own unlinks, prune restores each directory's times, so a prune that stops midway leaves a state the next prune finishes. The identity then follows the marker rules. Closes #414
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.
session pruneremoved a retained session directory in three steps: the logs, thenstopped.json, then the directory. A crash between thestopped.jsonunlink andrmdirleft an empty directory that later prunes skipped forever, because they read the teardown time fromstopped.json. A first permit or lease caller that stalled past teardown and prune could also rebuild the directory with only coordination files and a new identity marker. After #317 such a directory also keeps the session's input-closed and takeover-identity markers.Prune now has a second path for a session directory without a valid
stopped.json. It removes the directory only when there is no record and no session lock in any sessions root, the directory's own mtime is older than the one-day marker horizon, and every entry is on an allowlist and passes its check:O_NOFOLLOW, whose owner process is gone (start ticks count when present, so a reused pid counts as gone).permits/: a real directory older than a day whose entries all pass the checks above.Anything else keeps the directory: an unknown name, another subdirectory, a symlink, a young file, or a live owner. Prune checks the record and lock again and that the directory is still the inode it opened, unlinks each file bound to the identity it checked, restores the directory times after its own unlinks, and removes directories with
rmdir, which refuses a directory that gained an entry. The #317 rules then remove the identity and input-closed markers in the same pass. A stalled caller that resumes after the removal fails closed and delivers no input.Known limit: a hard kill of prune between an unlink and the time restore leaves the directory with a fresh mtime, so the next prune finishes it one day later. The state is safe and lets no input through.
Rollback: revert this PR. It adds no stored format; directories it would have removed simply stay, as before.
Closes #414
stopped.jsonafter the marker horizonstopped.jsonunlink andrmdirafter a real teardown with markers; a young directory; a writer that adds an entry beforermdirsession-retention.test.ts,414/qa/stopped.jsonunlink andrmdirrmdironce414/round2-before-main-source.log(fails on main)withAgentPermitcaller; unknown file next to coordination files, including near-miss names; young permit; live owner of a permit, staged permit, lease or temp writer; a prune stopped midwaysession-retention.test.ts,414/round2-before-first-fix-source.logAgentPermitUnavailableError, nothing delivered or recreatedsession-retention.test.ts414/mutation-*.logQA ran through the CLI with a temporary
PICKFORGE_HOME: a destroyed session left in the crash state was kept while young and pruned with both markers once backdated, and a directory holding an unknownnotes.txtwas kept.Council review, 2 rounds:
Sol's two round 1 blockers, removal by name racing a same-user rename, and the identity check then unlink racing a replaced lease, were disputed and resolved in round 2:
rmdirremoves only an empty directory, leases and permits publish by exclusivelink, so no legitimate writer's entry is lost, and a same-user process could delete these files directly. Sol's should, the one-day delay after a hard kill, is the accepted limit above, which Fable also rated a nit. Fable's should, a shorter stall that leavespermits/in a retained directory withstopped.json, predates this change and is #434. Fable and Kimi had no open items for round 2.Follow-ups: #434 (a short stall during teardown leaves
permits/in a retained directory), #431 (staging files from a crash inpublishCoordinationIdentity).Checks on 591c6fa (before the merge of main, which brought only the test fixes from #430): oxlint, typecheck, build; full vitest coverage run with the desktop, window, wait, browser and viewer requirements on (191 files, 3438 passed, 4 skipped);
PICKFORGE_REQUIRE_XVFB=1 cargo test --workspace --locked(328 passed). PickCheck 0.4.0 against main is clean.