Preserve sub-agent liveness in the agent picker (#33921)

## Why

Opening the agent picker could clear a successful spawn hint before the new
sub-agent had emitted a turn event, making a running agent appear stopped.

## What changed

- Treat active turns and matching completion events as authoritative liveness
  transitions while leaving an empty event store unchanged.
- Remember terminal liveness so delayed activity cannot revive a stopped agent;
  only a new turn can mark it running again.
- Ignore `Interacted` activity when deriving agent liveness.

## Testing

Added coverage for empty stores, stale and current completion events, completed
snapshots, delayed activity, and subsequent turns.

GitOrigin-RevId: 462539d8134a5d3520dbd41edb44b3251f50ead5
This commit is contained in:
Eric Traut authored and copyberry committed 2026-07-17 23:07:40 +00:00
1 parent 3a06748458
commit d4982d0a33
5 files changed
+185 -23

No files matched your search

+18 -3
View File
@@ -930,17 +930,32 @@ impl App {
let channel = self.ensure_thread_channel(thread_id);
(channel.sender.clone(), Arc::clone(&channel.store))
};
let (should_send, pending_status) = {
let (should_send, pending_status, turn_stopped) = {
let mut guard = store.lock().await;
if guard.session.is_none()
&& let Some(session) = inferred_session
{
guard.session = Some(session);
}
let turn_stopped = match &notification {
ServerNotification::TurnCompleted(notification) => {
guard.active_turn_id() == Some(notification.turn.id.as_str())
}
ServerNotification::ThreadClosed(_) => true,
_ => false,
};
guard.push_notification(notification.clone());
(guard.active, guard.side_parent_pending_status())
(
guard.active,
guard.side_parent_pending_status(),
turn_stopped,
)
};
if matches!(notification, ServerNotification::TurnStarted(_)) {
self.agent_navigation.mark_running(thread_id);
} else if turn_stopped {
self.agent_navigation.mark_stopped(thread_id);
}
let notification_status_change = SideParentStatusChange::for_notification(&notification);
if should_send {