Skip to content

fix(core): prune permits/ in retained directories and identity staging files - #455

Merged
ElbertePlinio merged 5 commits into
mainfrom
fix/431-434-prune-leftovers
Oct 29, 2026
Merged

ElbertePlinio merged 5 commits into
mainfrom
fix/431-434-prune-leftovers

Conversation

@ElbertePlinio

@ElbertePlinio ElbertePlinio commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Closes #431
Closes #434

session prune now removes two leftovers that it used to keep forever.

A first permit caller that stalls only through teardown builds permits/ in the retained directory and then fails closed (#434). Prune now accepts a retained directory that holds permits/, when permits/ is a real directory that is empty or holds only stale permit files whose owners are gone. It uses the same permit checks as the #414 coordination path. Before it removes anything, it checks again that the session is not in the registry and that the directory under the id is still the one it opened, by device and inode. It then removes the permit files, carries the teardown time, removes the files and the marker through the directory handle, and removes the directory only if it is empty.

publishCoordinationIdentity leaves .takeover-identity-<uuid> and its writeFileAtomic temp in the sessions root when its process dies between the write and the unlink (#431). Prune now removes a staging file older than the one-day horizon, and a temp older than the horizon whose writer pid is gone. A staging file names no writer, so age alone decides. A writer that stalls past the horizon and then finds its staging file gone fails on the link and publishes nothing.

Traceability

Requirement Verification Scenario and edge cases Result Evidence
#431: remove an old staging file and its temp when the writer is gone removes takeover identity staging files that a killed writer left, keeps takeover identity staging files inside the horizon, keeps %s in the sessions root Staging file and temp older than the horizon with a dead writer; a fresh staging file; a temp whose writer is alive; a symlink, a directory and a near-miss name under a staging name Pass; the first fails on main ~/.pickforge/investigations/431-434/before-main-source.log, r2/core-tests.log
#431: a stalled writer publishes nothing fails closed for a writer that stalls past the horizon before it links the identity Prune removes the staging file while its writer waits before the link Pass; fails on main ~/.pickforge/investigations/431-434/before-main-source.log
#434: remove an old permits/ that is empty or holds only stale permit files with gone owners removes permits/ that a caller stalled only through teardown left in a retained directory, removes stale permit files with gone owners from permits/ in a retained directory, keeps a retained directory whose permits is a symlink, keeps a retained directory whose permits/ holds %s Empty permits/; stale permit records and temps; permits/ as a symlink; a young permit, a live owner, a live temp writer and an unknown file are kept Pass; the first two fail on main ~/.pickforge/investigations/431-434/434-before-main-source.log, r2/core-tests.log
#434: the short stall during teardown The same tests plant the state the stalled caller leaves: stopped.json, a log, permits/, the identity and input-closed markers Backdated past the horizon Pass ~/.pickforge/investigations/431-434/r2/core-tests.log
Prune never removes a directory that changed under it keeps a retained directory that is replaced after its permits are listed, keeps a retained directory that gains an entry before rmdir Directory renamed and replaced after the permit listing; a new entry before rmdir Pass; both fail on the first revision ~/.pickforge/investigations/431-434/r2/before-r1-source.log
Each new check is needed Mutations: no permit checks, no staging age, no temp pid check One mutation at a time Each fails at least one test ~/.pickforge/investigations/431-434/mutation-*.log
QA through the built CLI cli-qa.sh plants both leftovers in a temporary PICKFORGE_HOME and runs session prune --all-stopped --json Backdated leftovers, plus one fresh staging file Pass: the session is pruned and only the fresh staging file stays. On main nothing is pruned ~/.pickforge/investigations/431-434/cli-qa-after.log, cli-qa-before-main-source.log
Full suite full-suite.sh build, lint, typecheck, viewer build, vitest, cargo At 0f97b00: 3520 passed, 4 skipped; cargo 351 passed. After the parameter refactor and merging main: build, typecheck, lint and session-retention.test.ts (82 tests) pass ~/.pickforge/investigations/431-434/full/, r3/
PickCheck and secret scan pickcheck check --base origin/main --fail-on new,worsened,unmatched; gitleaks on the branch commits 46 files checked 0 violations after dff4ede, which moved two parameters into one object; no leaks ~/.pickforge/investigations/431-434/pickcheck.json

Known limit: the directory identity check runs before the removal steps, which await. A process that swaps the directory between that check and the final rmdir cannot make prune remove its files, because each unlink goes through the handle prune opened and removes only files prune validated. The only step by name is the rmdir of an empty directory, and neither POSIX nor Node can remove a directory by inode. The coordination path merged with #414 has the same window.

Found during review and filed as #453: a slower concurrent prune can abort in carryStoppedAt after a faster prune removed the markers. It is unchanged from main, and no data is at risk.

Review

Council, three seats per round.

Round Revision Sol Fable Kimi
1 b926616 6 8 not run (usage limit)
2 0f97b00 6 9 not run

Round 1 found that prune did not check the directory identity before removal, and that a bare rmdir threw when the directory gained an entry. Both are fixed in 0f97b00. dff4ede after the council only passes the checked files and the teardown time as one object, for PickCheck's parameter limit. In round 2, Sol held that the identity check still leaves a rename window. That window is the known limit above, and Fable agreed that no change is needed. Sol rechecked dff4ede: 10/10, no findings.

…g files

A first permit caller that stalls only through teardown builds an empty
permits/ in the retained session directory. The retained prune path now
removes an old permits/ that is empty or holds only stale permit files
with gone owners, using the same checks as the coordination directory
path, then prunes the directory as before.

A writer killed inside publishCoordinationIdentity leaves its
.takeover-identity-<uuid> staging file or the writeFileAtomic temp for
it in the sessions root. Prune now removes them once they are older than
the marker horizon, and the temp only when its writer pid is gone.

Closes #431
Closes #434
Prune removed a retained directory's files through its open handle
without checking that the name still pointed at it, and a bare rmdir
aborted the whole run when an entry appeared first. Check the device
and inode as the coordination path does, and keep a directory that
gains an entry before rmdir.
removeRetainedDirectory took seven parameters, over the PickCheck limit of six.
@ElbertePlinio
ElbertePlinio merged commit f6434be into main Oct 29, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/431-434-prune-leftovers branch October 29, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant