Skip to content

fix: reap closed agents from the sidebar - #57

Open
vimeh wants to merge 2 commits into
Ataraxy-Labs:mainfrom
vimeh:fix/reap-closed-agents
Open

fix: reap closed agents from the sidebar#57
vimeh wants to merge 2 commits into
Ataraxy-Labs:mainfrom
vimeh:fix/reap-closed-agents

Conversation

@vimeh

@vimeh vimeh commented Jul 22, 2026

Copy link
Copy Markdown

Fixes #48.

Closed agents stayed in the agents panel until a server restart because every removal path was unwired:

  • prune_terminal was dead code — implemented but never called. It now runs on every snapshot: terminal entries (done/error/interrupted/stale) without a live pane expire 5 min after being seen, or 30 min while unseen (so the notification dot isn't reaped before it can be noticed). It also clears unseen markers for pruned keys.
  • dismiss-agent had no server handler — the sidebar's D key sent the command, handle_client_command dropped it. Wired to AgentTracker::dismiss with a snapshot broadcast.
  • pi's exit signal went nowheresession_shutdown posts /api/runtime/pi/delete, which only mutated the write-only PiRuntimeRegistry. The pid is now resolved back to its session (via the registered cwd) and the tracker entry dismissed, broadcasting a fresh snapshot.
  • /pane-exited now broadcasts immediately (the snapshot path re-syncs pane presence and prunes) instead of waiting for the next 2s poll tick, and the already-installed pane-died hook is accepted by is_ok_hook_path and handled identically (Agents not removed from sidebar when closed — prune_terminal/prune_stuck never called + /pane-exited skips tracker update #48 items 2 and 3).
  • pi/droid Waiting threads now stale out after 15s of file silence, matching claude/codex — an agent killed while waiting no longer freezes in a non-terminal status the reaper ignores.

prune_stuck stays unwired on purpose: reaping running entries by timestamp alone risks deleting agents that are mid-turn but quiet; the agent watcher already downgrades killed agents to the terminal stale status within ~15s, which prune_terminal then reaps.

Tests: 5 new tracker tests covering the TTL/liveness/unseen matrix, plus a server-side test harness (FakeProvider) with 4 tests for the dismiss handler and the pi-delete bridge, and a watcher test for the pi Waiting→Stale transition. cargo test --workspace green (tmux E2E included, one pre-existing env-dependent flake on my machine).

Closed agents stayed in the agents panel until a server restart because
every removal path was unwired (Ataraxy-Labs#48):

- AgentTracker::prune_terminal was never called. Invoke it on every
  snapshot so terminal entries (done/error/interrupted/stale) without a
  live pane expire: 5 min after being seen, 30 min while unseen so the
  notification dot isn't reaped before it can be noticed. It now also
  clears unseen markers for pruned keys and reports whether it changed
  anything.
- The sidebar's D key sends dismiss-agent, but the server had no
  handler, so manual dismissal was silently dropped. Wire it to
  AgentTracker::dismiss and broadcast the updated snapshot.
- pi's session_shutdown posts /api/runtime/pi/delete, which only
  touched the write-only PiRuntimeRegistry. Resolve the pid back to its
  session via the registry's cwd and dismiss the tracker entry, pushing
  a fresh snapshot.
- /pane-exited now broadcasts a snapshot (which re-syncs pane presence
  and prunes) instead of waiting for the next poll tick, and the
  already-installed pane-died hook is accepted by is_ok_hook_path and
  handled the same way.

prune_stuck stays unwired on purpose: reaping running entries by
timestamp alone risks deleting agents that are mid-turn but quiet; the
agent watcher already downgrades killed agents to the terminal stale
status within 15s, which prune_terminal then reaps.

Fixes Ataraxy-Labs#48

@inspect-review inspect-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

inspect review

Triage: 53 entities analyzed | 0 critical, 0 high, 17 medium, 36 low
Verdict: standard_review

Findings (0)


Reviewed by inspect | Entity-level triage found 0 high-risk changes

claude/codex watchers already downgrade Waiting to Stale after 15s of
file silence; pi and droid only did so for Running. An agent killed
while waiting froze in a non-terminal status the reaper ignores.

@inspect-review inspect-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

inspect review

Triage: 57 entities analyzed | 0 critical, 0 high, 20 medium, 37 low
Verdict: standard_review

Findings (0)


Reviewed by inspect | Entity-level triage found 0 high-risk changes

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.

Agents not removed from sidebar when closed — prune_terminal/prune_stuck never called + /pane-exited skips tracker update

1 participant