Skip to content

feat(coding-agent): reap orphaned empty session files at daemon start - #903

Open
y0usaf wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
y0usaf:reap-empty-sessions
Open

feat(coding-agent): reap orphaned empty session files at daemon start#903
y0usaf wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
y0usaf:reap-empty-sessions

Conversation

@y0usaf

@y0usaf y0usaf commented Aug 8, 2026

Copy link
Copy Markdown

When the daemon (or a worker) gets killed mid-flight, it can leave a sessions/*.jsonl behind 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

  • On startup, AgentDaemon now calls a new reapOrphanedEmptySessions method that scans .jsonl session files and deletes those containing only bookkeeping entries (e.g. session, model_change, agent_status) with no active lease.
  • A new hasActiveSessionLease function in session-lease.ts checks whether a session file's lease owner process is still alive, protecting files from active sessions.
  • Files that are unreadable or corrupt are silently skipped to avoid blocking startup.

Macroscope summarized f50fa1d.

@y0usaf
y0usaf force-pushed the reap-empty-sessions branch from 1a4b80f to 81cc4d9 Compare August 8, 2026 04:32
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
y0usaf force-pushed the reap-empty-sessions branch from 81cc4d9 to f50fa1d Compare August 8, 2026 04:33
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.

1 participant