fix(daemon): drop a /exited agent from the ×N count promptly - #14
Merged
Conversation
When you /exit a managed agent its tmux window closes at once, but the lane's ×N badge could linger. overlay_agents keeps a worktree's recent Claude transcripts truncated to alive.max(managed_n), where `alive` (live claude processes) is cached ~10s. On /exit the window vanishes (managed_n drops) but the stale-high `alive` kept the just-exited session's still-recent transcript — surfaced as an extra `external` session — so the count stayed high for up to the cache TTL. Track the set of managed (`lane-…`) windows across overlays; when one disappears (an agent /exited or was stopped), invalidate the live_cwds cache so the very next overlay recomputes the process count fresh and the gone agent drops within one refresh. One extra lsof on the rare exit event only; steady-state cadence and the TTL are untouched, so the CPU posture is preserved. Genuine external sessions (a claude in another terminal) are still shown — only the dead managed one is removed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
/exiting a managed agent closes its tmux window immediately, but the lane's×Nbadge couldstay too high.
overlay_agentskeeps a worktree's recent Claude transcripts truncated toalive.max(managed_n), wherealive(liveclaudeprocesses) is cached ~10s. On/exitthewindow vanishes (
managed_ndrops) but the stale-highalivekeeps the just-exited session'sstill-recent transcript — shown as an extra
externalsession — so the count lingered for up to thecache TTL (and indefinitely if a real external claude shared the worktree).
Confirmed against the live daemon via
lane.list: the badge counts managed windows plus externalclaude transcripts in the worktree.
Fix
Track the set of managed (
lane-…) windows across overlays; when one disappears (an agent/exitedor was stopped), invalidate the
live_cwdscache so the next overlay recomputes the process countfresh — the gone agent drops within one refresh (~1s) instead of up to ~10s.
lsofonly on the rare exit event; steady-state cadence and the cache TTL are untouched,so the CPU posture from the perf work is preserved.
claudein another terminal) are still shown — only the dead managedone is removed.
Daemon-only — the TUI/iOS render whatever
agent_sessionsthe daemon returns, so they benefit forfree.
Verification
cargo build/clippy -D warnings/testgreen; daemon reinstalled + restarted;lane.listhealthy.Manual: spawn 2 agents in a clean worktree (
×2),/exitone → drops to×1within ~1–2s.🤖 Generated with Claude Code