fix(list): keep sessions whose daemon outlives a socket-reachable failure#35
Merged
myobie merged 1 commit intoMay 3, 2026
Merged
Conversation
…achable listSessions() previously deleted .sock files whenever a socket was unreachable, even if the recorded pid was still alive. That made any transient socket-reachable failure (busy daemon, EAGAIN, race with a service restart) permanent: once the .sock is removed, the still-alive daemon becomes invisible to all future scans. It also called cleanupAll() on .json files older than 24h without checking whether the daemon process was still running, so long-lived daemons silently lost their metadata after a day and disappeared from 'pty list' even though they kept consuming RAM. This commit makes both checks gated on isProcessAlive(pid): - if pid is alive but socket is unreachable, keep both .sock and metadata, report status as running - if .json is older than 24h, only cleanupAll() when pid is dead Refs: myobie#34
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.
Closes #34.
listSessions()had two cleanup paths that fired even when the recordedpid was still alive:
.sockbranch deleted the socket file wheneverisSocketReachablereturned false. The probe has a 500ms timeout and trips on a busy
daemon, transient EAGAIN, or a race with a service restart. Once the
.sockwas gone, the still-alive daemon became invisible to everyfuture scan and there was no way to recover it short of
kill -9..jsonbranch unconditionally deleted metadata older than 24h.Long-lived daemons whose metadata wasn't refreshed (because nothing
refreshes it) had their
.jsonremoved after a day even though theykept consuming memory.
This change gates both paths on
isProcessAlive(pid):.sockand report the session as
running. Calling code that needs areachable socket will fail in the usual way; the lister no longer
destroys recovery state.
.jsonis older than 24h but the pid is alive, leave the metadataalone. The TTL is meant to age out known-dead sessions, not to garbage-
collect unknown-state ones. The pid probe is cheap (a single
kill(pid, 0)syscall) and runs at most once per dead-looking sessionper scan.
Tests in
tests/list-filters.test.tslock in both behaviors using thetest runner's own pid as a stand-in for an alive daemon, plus a
matched negative case proving the 24h TTL still fires when the pid is
dead.
Verification
npx vitest run tests/list-filters.test.ts— all 18 tests pass(including the 2 new ones).
npx vitest run tests/gc.test.ts tests/list-filters.test.ts— passes.npx tsc -p tsconfig.build.json— clean.Posted on behalf of @schickling
agent_nameagent_session_idagent_toolagent_tool_versionagent_runtimeagent_modelworktreemachinetooling_profile