Skip to content

fix(daemon): drop a /exited agent from the ×N count promptly - #14

Merged
AliHamzaAzam merged 1 commit into
mainfrom
fix/drop-exited-agent-count
Jun 17, 2026
Merged

fix(daemon): drop a /exited agent from the ×N count promptly#14
AliHamzaAzam merged 1 commit into
mainfrom
fix/drop-exited-agent-count

Conversation

@AliHamzaAzam

Copy link
Copy Markdown
Owner

Problem

/exiting a managed agent closes its tmux window immediately, but the lane's ×N badge could
stay too high. 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 keeps the just-exited session's
still-recent transcript — shown as an extra external session — so the count lingered for up to the
cache 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 external
claude transcripts in the worktree.

Fix

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 next overlay recomputes the process count
fresh — the gone agent drops within one refresh (~1s) instead of up to ~10s.

  • One extra lsof only on the rare exit event; steady-state cadence and the cache TTL are untouched,
    so the CPU posture from the perf work is preserved.
  • Genuine external sessions (a claude in another terminal) are still shown — only the dead managed
    one is removed.

Daemon-only — the TUI/iOS render whatever agent_sessions the daemon returns, so they benefit for
free.

Verification

cargo build/clippy -D warnings/test green; daemon reinstalled + restarted; lane.list healthy.
Manual: spawn 2 agents in a clean worktree (×2), /exit one → drops to ×1 within ~1–2s.

🤖 Generated with Claude Code

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>
@AliHamzaAzam
AliHamzaAzam merged commit aa5c934 into main Jun 17, 2026
@AliHamzaAzam
AliHamzaAzam deleted the fix/drop-exited-agent-count branch June 17, 2026 22:02
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