Skip to content

fix(core): prune session markers one day after teardown - #418

Merged
ElbertePlinio merged 7 commits into
mainfrom
fix/317-prune-session-markers
Oct 28, 2026
Merged

ElbertePlinio merged 7 commits into
mainfrom
fix/317-prune-session-markers

Conversation

@ElbertePlinio

@ElbertePlinio ElbertePlinio commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Every desktop or browser teardown left a .<id>.input-closed marker, and .<id>.takeover-identity was never removed, so the sessions directory grew for the life of the install.

session prune now removes both markers one day after the session's teardown. A command reads the record once and re-checks it at every permit; the longest one is a 300 s desktop wait or input after up to 90 s for the session lock, so a day covers live callers with a wide margin. Teardown retains logs with stoppedAt just before it removes the record. When prune removes that directory, it first moves the markers' modification time forward to stoppedAt, so the horizon counts from teardown, not from the first takeover. Markers stay while a record, a session lock or a data directory exists in any sessions root, while either one is younger than the horizon, and when either is not a regular file. The identity goes first, so a crash between the two leaves the closure marker, which still refuses every caller. Nothing else in the directory is removed.

Two fixes came from review. Two concurrent prunes no longer fail when one already removed a marker. A permit or lease caller that read the record before teardown and resumes after the markers are gone no longer recreates the session directory and identity: storage creation re-reads the record first.

Rollback: revert the merge. No data format changes. Markers removed before the revert belonged to sessions with no record, lock or directory for over a day; after the revert, new teardowns keep their markers forever again.

No device pass beyond the CLI: prune has no screen. The CLI journeys below ran against real desktop sessions in an isolated PICKFORGE_HOME.

Closes #317

Requirement Verified by Scenario and edge cases Result Evidence
Decide a safe horizon Code comment, council Longest live reference is minutes; stopped callers; random 32-bit ids One day from teardown SESSION_MARKER_HORIZON_MS in session-retention.ts
Prune both markers past the horizon Unit tests, CLI J3 Markers 25 h old with no record, lock or directory Both removed; a running session's 3-day-old identity kept session-retention.test.ts; ~/.pickforge/investigations/317/qa-output-final.txt J3
Keep the id reserved until then Unit tests, CLI J1, J5, J6 Prune inside the horizon; markers older than a recent teardown Markers kept; teardown time carried into them J1, J5, J6
Late callers inside the horizon fail closed Unit tests, CLI J2 Permit and lease after prune; desktop click on the pruned id Refused, nothing recreated J2; "keeps both markers inside the horizon"
Never remove markers while teardown is pending or interrupted Unit tests Starting, running and error records; session lock; data directory Markers kept; reaper still sees the closure "keeps old markers while ..." tests
Crash between steps leaves a safe state Unit test Prune stops after the identity, before the closure Input still closed, id still reserved "stays closed and reserved when prune stops between the two markers"
Never delete other data Unit tests, CLI J4 Look-alike names, a non-file marker Kept J4; "keeps other files"
Concurrent prunes Unit test Marker removed by another prune first; marker replaced First succeeds; replaced entry refused "accepts a marker that a concurrent prune removed first"
Stale caller after markers are pruned Unit test Permit caller paused at its closure check across teardown and prune Refused, no input, nothing recreated "does not rebuild storage for a caller that resumes"
Release note Pending docs/releases/UNRELEASED.md still holds the tagged 0.7.1 notes Tracked in #416 this PR

Release note for the next version: "session prune removes the input closure and takeover identity markers of a destroyed session one day after its teardown. Until then they keep the id reserved, so late input for that session still fails. (#317)"

Follow-ups: #413 binds late callers to a session generation, so a reused id can never accept stale input. #414 prunes a session directory that a crash or a stalled first caller leaves without stopped.json.

Checks: bun run typecheck, bun run lint, bun run test:coverage with the CI environment variables (3384 passed) before the rebase on main, packages/core/test (1259 passed) after it, PickCheck (no new or worsened functions). One unrelated load flake in evidence-export is #412. A CI timing flake in security-takeover-observations on 138f77f is #423.

Council review, 3 rounds:

Delegate Round 1 Round 2 Round 3
GPT-6.1 Sol 3/10 8/10 7/10
Fable 5.1 8/10 8/10 9/10
Kimi K3.1 Pro 3/10 9/10 not run

Round 1 findings and outcomes: the concurrent prune error was fixed. Three findings about a stalled caller, the check-then-unlink race and markers from older versions were closed by their seats in round 2, because each needs a new session to draw the same random 32-bit id. The lock sentinel finding was closed because the data directory and the carried teardown time protect that window. Sol's round 2 finding about a stale caller rebuilding storage was fixed.

Still disputed after round 3: Sol holds that a first caller can still stall between the record re-read and the directory create, and rebuild storage. Fable accepts it: the stall must last more than a day between two adjacent awaits, no input is delivered, and only an empty directory and identity remain. Rolling back shared storage after publish would be riskier than that leftover. Settled as accepted; the cleanup is tracked in #414.

Explicit session prune now removes the .<id>.input-closed and
.<id>.takeover-identity markers of a gone session once both are older
than SESSION_MARKER_HORIZON_MS (24 hours). Until then they keep the id
reserved and late callers keep failing closed.

Markers stay while a record, a session lock or a data directory exists
in any sessions root, so pending, interrupted and retained teardowns
keep them. Before prune removes a retained directory, it copies the
teardown time from stopped.json onto older markers, so the horizon
starts at the last record. The identity goes first: a crash between the
two removals leaves the closure marker, which still refuses input and
reserves the id.

Closes #317
The release line waits for the 0.7.1 notes to be reset, so it moves to the PR description.
@ElbertePlinio
ElbertePlinio merged commit 2bc3b0e into main Oct 28, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/317-prune-session-markers branch October 28, 2026 22:34
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.

core: input-closed and takeover-identity markers accumulate forever

1 participant