Skip to content

fix(core): keep a session prune going when another prune runs at the same time - #465

Merged
ElbertePlinio merged 9 commits into
mainfrom
fix/453-prune-concurrent-carry
Oct 29, 2026
Merged

ElbertePlinio merged 9 commits into
mainfrom
fix/453-prune-concurrent-carry

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

Closes #453

session prune no longer aborts when another prune runs at the same time. A slower run used to throw at a step whose target a faster run had already removed, and it lost the list of ids it had pruned. It now treats each such target as done and does not report the id, so exactly one run reports it. Any other error still propagates.

The handled steps are the teardown time read from stopped.json, the marker carry, a permit or lease record read, and the open and listing of the session directory and of permits/, including a directory that goes while its open is checked. Under Bun, listing a removed directory through its descriptor fails with ENOENT; Node lists it empty. The tests reproduce the Bun result.

Traceability

Requirement Verification Scenario and edge cases Result Evidence
Treat a marker that a concurrent prune removed as done in carryStoppedAt finishes a prune when another prune runs first at the marker carry A second prune runs whole when the first opens the takeover identity marker after its lstat Pass; fails on main with ENOENT ~/.pickforge/investigations/453/before.log, r3/after.log
The same race at every other prune step finishes a prune when another prune runs first at %s (teardown time read, directory open, directory listing), finishes a prune when another prune runs first while its directory open is verified, finishes a stranded prune when another prune runs first at %s (a permit read, the permits/ open, the permits/ listing), finishes a retained prune when another prune runs first at the permits/ open Retained directory older than the horizon; stranded coordination directory; retained directory with permits/; Bun listing result Pass; 8 cases fail on main, 6 on the second revision, and the open-check case on 2439ebc with a plain ENOENT from realpath ~/.pickforge/investigations/453/r3/before-main-source.log, r3/before-r2-source.log, r5/before.log, r5/after.log
Test two concurrent prunes that interleave Each case above checks that the first prune returns [], the second returns the id, and the sessions root ends empty Both prunes in one process, the second started from a hook at the exact step Pass, 92 tests ~/.pickforge/investigations/453/r5/after.log
Other errors still propagate Each helper rethrows any error other than a gone entry; still fails on a directory open error other than a concurrent removal Symlink, file or replaced entry at the open; an EIO at the directory open Pass; the existing symlink and replacement tests pass, and the EIO case fails on cc05ef3 ~/.pickforge/investigations/453/r4/, r5/after.log
Full suite full-suite.sh build, lint, typecheck, viewer build, vitest, cargo All steps pass at b291d78: vitest 3539 passed, 4 skipped; cargo 353 passed ~/.pickforge/investigations/453/full-r5/
PickCheck and secret scan pickcheck check --base origin/main --fail-on new,worsened,unmatched; gitleaks on the branch commits 33 files checked 0 violations; no leaks ~/.pickforge/investigations/453/pickcheck-r5.json, gitleaks-r5.log

No QA pass: the race needs a second prune at one exact step, which only the test hook can place, and the CLI output does not change.

Review

Council of Sol and Fable. The Kimi seat did not run: its provider hit a usage limit during this batch.

Reviewer Revision Score Result
Sol 668542a 10 No findings.
Fable 668542a 7 The teardown time read in retainedStoppedAt had the same race; two nits. Fixed in 59a88d0.
Sol 59a88d0 9 No findings.
Fable 59a88d0 5 Under Bun, listing a removed directory fails with ENOENT, and a removed child directory fails to open with a storage error. Fixed in 6f38872.
Fable 6f38872 8 A catch typing nit, fixed in cc05ef3. The by-name rmdir of the retained directory is older than this change: #463.
Sol cc05ef3 6 The child open swallowed every storage error, not only a gone entry: fixed in 2439ebc. The retained path removes files by name after validation, which is older than this change: #463.
Sol 2439ebc 8 A directory removed while its open is checked threw a plain ENOENT. Fixed in b291d78.
Sol b291d78 10 No findings.

carryStoppedAt lstats each marker and then opens it. When a faster concurrent prune removed the marker in between, the open threw ENOENT and aborted the slower prune's whole run. A marker that is gone now counts as done.
Council review found the same lstat-then-open race at stopped.json and at stranded coordination records. One helper now opens a file that prune just checked and treats ENOENT as removed by a concurrent prune.
A slower prune could still abort after a faster one removed the whole
directory. Under Bun, listing a removed directory fails with ENOENT, and
opening one fails as a storage error. The slower prune now treats both
as gone and reports nothing, as it already does for files.
A directory open that failed for another reason was ignored when a
concurrent prune then removed the entry before the second lstat. The
storage error now keeps the ENOENT as its cause, and prune tolerates
only that.
@ElbertePlinio
ElbertePlinio merged commit 077484f into main Oct 29, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/453-prune-concurrent-carry branch October 29, 2026 22:02
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.

session prune: a concurrent prune can abort in carryStoppedAt after the markers are gone

1 participant