Ignore closed agents when changing directories (#40625)

## Why

Closed agent channels can retain stale in-progress turns, which can incorrectly
block `/cd` or cause unnecessary background-terminal checks.

## What changed

- Mark agents closed whenever a `thread/closed` notification is routed, including
  for inactive event channels.
- Exclude closed agents from running-turn detection and background-terminal checks
  during working-directory changes.

## Testing

Cover directory-change recovery with both a routed close notification and a
replay-only closed thread that contains a stale in-progress turn.

GitOrigin-RevId: 1072456056f8c1a1b751a52635470b0be160d76c
This commit is contained in:
Benjamin Carlsson authored and copyberry committed 2026-08-25 15:15:06 +00:00
1 parent f832b2fe7b
commit 34c5303f49
3 files changed
+65 -7

No files matched your search

+3 -1
View File
@@ -1017,6 +1017,7 @@ impl App {
None
};
let is_turn_started = matches!(notification, ServerNotification::TurnStarted(_));
let is_thread_closed = matches!(notification, ServerNotification::ThreadClosed(_));
let notification_status_change = SideParentStatusChange::for_notification(&notification);
let (sender, store) = {
let channel = self.ensure_thread_channel(thread_id);
@@ -1034,7 +1035,6 @@ impl App {
ServerNotification::TurnCompleted(notification) => {
guard.active_turn_id() == Some(notification.turn.id.as_str())
}
ServerNotification::ThreadClosed(_) => true,
_ => false,
};
let notification = if guard.active {
@@ -1053,6 +1053,8 @@ impl App {
};
if is_turn_started {
self.agent_navigation.mark_running(thread_id);
} else if is_thread_closed {
self.mark_agent_picker_thread_closed(thread_id);
} else if turn_stopped {
self.agent_navigation.mark_stopped(thread_id);
}