Skip to content

fix: ghost session detection + kill/prune for stale entries (#93)#94

Closed
c-h- wants to merge 2 commits into
mainfrom
fix/ghost-sessions
Closed

fix: ghost session detection + kill/prune for stale entries (#93)#94
c-h- wants to merge 2 commits into
mainfrom
fix/ghost-sessions

Conversation

@c-h-
Copy link
Copy Markdown
Collaborator

@c-h- c-h- commented Mar 5, 2026

PID reuse detection, kill removes stopped sessions, prune has age threshold, force kill always works. Closes #93.

Test and others added 2 commits February 20, 2026 15:29
When a session's real ID can't be resolved during launch, use
`pending-<PID>` format so unresolved entries are identifiable.

In the session tracker's poll cycle, reap stale entries:
- Remove pending-* entries when a resolved session shares the same PID
- Mark "running" sessions as stopped when their PID is dead

Add PID-based dedup in listSessions() as a safety net so pending-*
entries never appear alongside their resolved counterpart.

Fixes #22

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator Author

@c-h- c-h- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid fix for #93 — ghost session reaping, PID reuse detection, kill/prune commands, and great test coverage (305 new test lines).

Code looks correct: the adapter PID map is the source of truth, pending-* dedup is clean, and the isProcessAlive/getProcessCommand DI makes everything testable.

One gap: README needs updating with the new kill and prune commands in the Quick Start / command reference section. Docs must stay current per our merge requirements. Happy to ship a follow-up commit if you want, or you can add it here.

Otherwise LGTM — will approve + merge once CI passes and docs are covered.

@c-h- c-h- force-pushed the fix/ghost-sessions branch from b3be1f7 to 2f7dd95 Compare March 5, 2026 19:08
@c-h- c-h- enabled auto-merge (squash) March 5, 2026 22:33
@c-h- c-h- force-pushed the fix/ghost-sessions branch 3 times, most recently from 01cdf73 to b3be1f7 Compare March 6, 2026 16:35
@c-h-
Copy link
Copy Markdown
Collaborator Author

c-h- commented Mar 6, 2026

Closing this PR — the underlying ghost session bug was addressed by the major architectural refactoring that landed on main.

The new stateless daemon model means adapters own session truth. On every agentctl list, reconcileAndEnrich() fans out to each adapter's discover(), which filters sessions by process name (not just PID). If a PID was recycled by a different process (e.g. trustd), the adapter won't match it and the session gets marked stopped automatically. All adapters also have PID recycling detection via lstart start-time comparison.

Additionally, cleanupDeadLaunches() runs every 30s for lock cleanup, and agentctl prune is available via the CLI.

The PR branch is based on v1.0.1 (before the refactor) and diverges from main by ~16K lines. Not worth rebasing — the fix is structurally already there.

@c-h- c-h- closed this Mar 6, 2026
auto-merge was automatically disabled March 6, 2026 17:55

Pull request was closed

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.

Bug: ghost sessions persist as 'running' after process death + PID reuse

1 participant