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

+30 -2
View File
@@ -44,6 +44,8 @@ pub(crate) struct AgentNavigationState {
threads: HashMap<ThreadId, AgentPickerThreadEntry>,
/// Stable first-seen traversal order for picker rows and keyboard cycling.
order: Vec<ThreadId>,
/// Threads with observed terminal liveness that must not be revived by delayed activity.
stopped_threads: HashSet<ThreadId>,
/// Spawned child threads whose instructions are owned by their parent agent.
parent_owned_threads: HashSet<ThreadId>,
}
@@ -132,8 +134,32 @@ impl AgentNavigationState {
is_closed: false,
});
entry.agent_path = Some(activity.agent_path);
entry.is_running = activity.is_running_hint;
entry.is_closed = false;
if activity.is_running_hint
&& !entry.is_closed
&& !self.stopped_threads.contains(&activity.thread_id)
{
entry.is_running = true;
} else {
entry.is_running = false;
self.stopped_threads.insert(activity.thread_id);
}
}
pub(crate) fn mark_running(&mut self, thread_id: ThreadId) {
if self
.threads
.get(&thread_id)
.is_some_and(|entry| entry.is_closed)
{
return;
}
self.stopped_threads.remove(&thread_id);
self.set_running(thread_id, /*is_running*/ true);
}
pub(crate) fn mark_stopped(&mut self, thread_id: ThreadId) {
self.stopped_threads.insert(thread_id);
self.set_running(thread_id, /*is_running*/ false);
}
pub(crate) fn set_running(&mut self, thread_id: ThreadId, is_running: bool) {
@@ -175,6 +201,7 @@ impl AgentNavigationState {
pub(crate) fn clear(&mut self) {
self.threads.clear();
self.order.clear();
self.stopped_threads.clear();
self.parent_owned_threads.clear();
}
@@ -186,6 +213,7 @@ impl AgentNavigationState {
pub(crate) fn remove(&mut self, thread_id: ThreadId) {
self.threads.remove(&thread_id);
self.order.retain(|candidate| *candidate != thread_id);
self.stopped_threads.remove(&thread_id);
self.parent_owned_threads.remove(&thread_id);
}