Skip to content

fix(core): remove retained session files only while they are the checked ones - #473

Merged
ElbertePlinio merged 3 commits into
mainfrom
fix/463-retained-identity-unlink
Oct 29, 2026
Merged

ElbertePlinio merged 3 commits into
mainfrom
fix/463-retained-identity-unlink

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

Closes #463

session prune removed each retained file by name after checking it, so a writer that replaced xvfb.log or stopped.json in between lost the replacement, and prune still reported the id. Retained files now go through unlinkStaleFile, as the coordination path already did: each file is removed only while its device and inode match the checked ones, and a file that a concurrent prune already removed counts as done. stopped.json still goes last. A replaced file fails the prune run and stays, with its directory, and the next prune still finds the teardown time.

Two windows remain, both documented in the code. The identity check and the unlink are two syscalls, and POSIX has no unlink by inode, so a replacement made between them is still removed. This is the same window the coordination path has; #472 tracks closing it in the shared helper. The directory removal also goes by name. If a concurrent prune removed the directory and a stalled first permit caller made an empty one with the same id, this prune removes that one too. The caller then fails closed on its next step, so no data is lost and no input is delivered.

Traceability

Requirement Verification Scenario and edge cases Result Evidence
Remove retained files only while their identity matches the validated one "keeps a retained %s that is replaced after its check", for xvfb.log and stopped.json; a probe that replaces a file just before the by-name unlink A log replaced after its check; the marker replaced after its check; a file a concurrent prune already removed Both tests fail with main's source and pass here. The probe on main loses the replacement and reports the id ~/.pickforge/investigations/463/before.log, after-1.log to after-3.log, probe-main.json
Decide on the rmdir window Council review of the documented limit A concurrent prune, then a stalled first permit caller recreating the directory Kept as a documented limit at rmdirIfEmpty: the caller fails closed, and no data is lost packages/core/src/session-retention.ts
Test a replacement before each removal The two tests above. After the replacement, each test restores the file and checks that the next prune finds the teardown time and reports the id Replacement before each file's removal; recovery on the next run Retention tests pass 94 of 94, three times; core passes 1309 ~/.pickforge/investigations/463/after-1.log to after-3.log, core.log
The check-then-unlink window A probe that swaps the file between the check and the unlink Replacement at the last syscall Still removed, as on the coordination path; documented, tracked in #472 ~/.pickforge/investigations/463/probe-fixed.json
Full suite full-suite.sh at f57c269; faf8635 adds a code comment only, and the retention tests, lint and typecheck were rerun on it build, lint, typecheck, viewer build, vitest, cargo All steps pass: vitest 3553 passed, 4 skipped; cargo 355 passed. On faf8635: retention 94 of 94, lint and typecheck exit 0 ~/.pickforge/investigations/463/full/, after-doc.log, lint-doc.log, typecheck-doc.log
PickCheck and secret scan pickcheck check --base origin/main --fail-on new,worsened,unmatched; gitleaks on the branch commits 0 violations; no leaks ~/.pickforge/investigations/463/pickcheck.json, gitleaks.log

No device pass: the change is in prune's file removal, with no screen or CLI output change. The tests drive pruneSessionLogs, which session prune calls.

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 f57c269 6 A replacement between the identity check and the by-name unlink is still removed. Confirmed with a probe. Kept as a documented limit in faf8635, the same window as the coordination path; a rename-and-check protocol in the shared helper is #472. Sol found the rmdir limit reasonable.
Fable f57c269 9 No blockers. Agreed with the rmdir limit. Nits: the helper's error names atomic writes, and retainSessionLogs removes staging files by name after an lstat; both are in #472. A replaced file fails the whole session prune run; kept, because the command reports the error and can run again.

Prune validated each retained file, then removed it by name. A file replaced in between was removed, and prune still reported the id. Each file is now removed only while its device and inode match the checked ones, as in the coordination path. The rmdir by name stays a documented limit.
@ElbertePlinio
ElbertePlinio merged commit 4158a79 into main Oct 29, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/463-retained-identity-unlink branch October 29, 2026 23:25
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: the retained path removes files and the directory by name after validation

1 participant