mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Refresh the subagent picker in the background (#35693)
## Why Opening the subagent picker could wait on thread metadata and live event-store locks, delaying terminal input. Its cached entries could also omit descendants that were not observed in the current TUI session. ## What changed - Render the picker immediately from cached navigation state and refresh root descendants asynchronously with `thread/list`. - Merge discovered descendants into an open picker while preserving its selection and live status, and coalesce concurrent refresh requests. - Ignore refresh responses from a previous session and avoid blocking on busy event stores. ## Testing - Extend session lifecycle coverage for nonblocking picker opens, refresh coalescing, descendant discovery, selection preservation, and status updates. - Add coverage for rejecting a refresh response after navigation state is cleared. GitOrigin-RevId: 7eae7f696f8d2d323a47b3fd2800ea1c1cdbf2a0
This commit is contained in:
1 parent
63682c4e1a
commit
f029bb795c
10 files changed
+415
-37
No files matched your search
@@ -28,6 +28,7 @@ use codex_protocol::ThreadId;
|
||||
use ratatui::text::Span;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Small state container for multi-agent picker ordering and labeling.
|
||||
///
|
||||
@@ -48,6 +49,8 @@ pub(crate) struct AgentNavigationState {
|
||||
stopped_threads: HashSet<ThreadId>,
|
||||
/// Spawned child threads whose instructions are owned by their parent agent.
|
||||
parent_owned_threads: HashSet<ThreadId>,
|
||||
/// Coalesces root refreshes while rejecting replies from a previous session.
|
||||
picker_refresh: Option<(ThreadId, Uuid)>,
|
||||
}
|
||||
|
||||
/// Direction of keyboard traversal through the stable picker order.
|
||||
@@ -60,6 +63,23 @@ pub(crate) enum AgentNavigationDirection {
|
||||
}
|
||||
|
||||
impl AgentNavigationState {
|
||||
pub(crate) fn begin_picker_refresh(&mut self, thread_id: ThreadId) -> Option<Uuid> {
|
||||
if self.picker_refresh.is_some() {
|
||||
return None;
|
||||
}
|
||||
let request_id = Uuid::new_v4();
|
||||
self.picker_refresh = Some((thread_id, request_id));
|
||||
Some(request_id)
|
||||
}
|
||||
|
||||
pub(crate) fn finish_picker_refresh(&mut self, thread_id: ThreadId, request_id: Uuid) -> bool {
|
||||
if self.picker_refresh != Some((thread_id, request_id)) {
|
||||
return false;
|
||||
}
|
||||
self.picker_refresh = None;
|
||||
true
|
||||
}
|
||||
|
||||
/// Returns the cached picker entry for a specific thread id.
|
||||
///
|
||||
/// Callers use this when they already know which thread they care about and need the last
|
||||
@@ -203,6 +223,7 @@ impl AgentNavigationState {
|
||||
self.order.clear();
|
||||
self.stopped_threads.clear();
|
||||
self.parent_owned_threads.clear();
|
||||
self.picker_refresh = None;
|
||||
}
|
||||
|
||||
/// Removes a tracked thread entirely from picker metadata and traversal order.
|
||||
@@ -433,6 +454,24 @@ mod tests {
|
||||
assert!(!state.is_parent_owned(second_agent_id));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn picker_refresh_rejects_responses_from_before_clear() {
|
||||
let mut state = AgentNavigationState::default();
|
||||
let thread_id = ThreadId::new();
|
||||
let stale_request = state
|
||||
.begin_picker_refresh(thread_id)
|
||||
.expect("first picker refresh");
|
||||
|
||||
assert_eq!(state.begin_picker_refresh(thread_id), None);
|
||||
state.clear();
|
||||
let current_request = state
|
||||
.begin_picker_refresh(thread_id)
|
||||
.expect("refresh after session reset");
|
||||
|
||||
assert!(!state.finish_picker_refresh(thread_id, stale_request));
|
||||
assert!(state.finish_picker_refresh(thread_id, current_request));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn adjacent_thread_id_wraps_in_spawn_order() {
|
||||
let (state, main_thread_id, first_agent_id, second_agent_id) = populated_state();
|
||||
|
||||
Reference in new issue
Block a user