feat(coding-agent): reap orphaned empty session files at daemon start - #903
Open
y0usaf wants to merge 1 commit into
Open
feat(coding-agent): reap orphaned empty session files at daemon start#903y0usaf wants to merge 1 commit into
y0usaf wants to merge 1 commit into
Conversation
y0usaf
force-pushed
the
reap-empty-sessions
branch
from
August 8, 2026 04:32
1a4b80f to
81cc4d9
Compare
A killed daemon or worker can leave a sessions/*.jsonl behind that never captured a message — only the header and model/state bookkeeping. At daemon start, sweep the session dir and delete files whose entries are all bookkeeping, skipping any session a live process still holds. Deletes via the existing trash-first deleteSessionFile().
y0usaf
force-pushed
the
reap-empty-sessions
branch
from
August 8, 2026 04:33
81cc4d9 to
f50fa1d
Compare
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.
When the daemon (or a worker) gets killed mid-flight, it can leave a
sessions/*.jsonlbehind that never captured a single message — just the header and a few model/state bookkeeping lines. They pile up and clutter the session list.This cleans those up: on daemon start it scans the session dir and deletes any file whose entries are purely bookkeeping. Things that actually contain a message, a custom entry, or a label are left alone, and any session a live process still holds is skipped (via a new
hasActiveSessionLease()helper). Deletion goes through the existing trash-first path, so it's recoverable.Small, self-contained, no test balloon — code speaks for itself.
Note
Reap orphaned empty session files on daemon startup
AgentDaemonnow calls a newreapOrphanedEmptySessionsmethod that scans.jsonlsession files and deletes those containing only bookkeeping entries (e.g.session,model_change,agent_status) with no active lease.hasActiveSessionLeasefunction in session-lease.ts checks whether a session file's lease owner process is still alive, protecting files from active sessions.Macroscope summarized f50fa1d.