mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Make parent-owned sub-agent threads read-only in the TUI (#33841)
## Why Multi-agent V2 spawned threads are controlled by their parent and reject direct app-server input. The TUI should expose that ownership instead of presenting an input flow that the server will reject. ## What changed - Add the experimental `Thread.canAcceptDirectInput` capability for loaded threads and populate it from the same policy used to validate `turn/start` and `turn/steer`. Stored, unloaded threads report `null`. - Carry the capability through TUI thread discovery, selection, startup, and resume flows, with a compatibility fallback for older app servers. - Present parent-owned threads as view-only, preserve drafts and queued input, block agent-directed commands and settings shortcuts, and keep local navigation and inspection commands available. ## Testing - Cover V1 writable and V2 view-only spawned threads through selection and resume. - Cover composer submission paths, queued and initial input preservation, allowed navigation commands, settings shortcuts, and the view-only UI. GitOrigin-RevId: 495ad051249e5577fb0b0c1cc8c40a0998d04918
This commit is contained in:
1 parent
315195492c
commit
3f0669dbd6
37 files changed
+781
-99
No files matched your search
@@ -6,6 +6,7 @@
|
||||
//!
|
||||
//! Responsibilities here are intentionally narrow:
|
||||
//! - remember picker entries and their first-seen order
|
||||
//! - remember which V2 child threads are owned by their parent agent
|
||||
//! - answer traversal questions like "what is the next thread?"
|
||||
//! - derive user-facing picker/footer text from cached thread metadata
|
||||
//!
|
||||
@@ -26,6 +27,7 @@ use crate::multi_agents::previous_agent_shortcut;
|
||||
use codex_protocol::ThreadId;
|
||||
use ratatui::text::Span;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
|
||||
/// Small state container for multi-agent picker ordering and labeling.
|
||||
///
|
||||
@@ -42,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>,
|
||||
/// Spawned child threads whose instructions are owned by their parent agent.
|
||||
parent_owned_threads: HashSet<ThreadId>,
|
||||
}
|
||||
|
||||
/// Direction of keyboard traversal through the stable picker order.
|
||||
@@ -64,6 +68,15 @@ impl AgentNavigationState {
|
||||
self.threads.get(thread_id)
|
||||
}
|
||||
|
||||
pub(crate) fn is_parent_owned(&self, thread_id: ThreadId) -> bool {
|
||||
self.parent_owned_threads.contains(&thread_id)
|
||||
}
|
||||
|
||||
/// Marks a spawned child thread as view-only for direct user instructions.
|
||||
pub(crate) fn mark_parent_owned(&mut self, thread_id: ThreadId) {
|
||||
self.parent_owned_threads.insert(thread_id);
|
||||
}
|
||||
|
||||
/// Returns whether the picker cache currently knows about any threads.
|
||||
///
|
||||
/// This is the cheapest way for `App` to decide whether opening the picker should show "No
|
||||
@@ -162,6 +175,7 @@ impl AgentNavigationState {
|
||||
pub(crate) fn clear(&mut self) {
|
||||
self.threads.clear();
|
||||
self.order.clear();
|
||||
self.parent_owned_threads.clear();
|
||||
}
|
||||
|
||||
/// Removes a tracked thread entirely from picker metadata and traversal order.
|
||||
@@ -172,6 +186,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.parent_owned_threads.remove(&thread_id);
|
||||
}
|
||||
|
||||
/// Returns whether there is at least one tracked thread other than the primary one.
|
||||
@@ -376,6 +391,20 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parent_owned_state_is_removed_with_thread_metadata() {
|
||||
let (mut state, _main_thread_id, first_agent_id, second_agent_id) = populated_state();
|
||||
|
||||
state.mark_parent_owned(first_agent_id);
|
||||
assert!(state.is_parent_owned(first_agent_id));
|
||||
state.remove(first_agent_id);
|
||||
assert!(!state.is_parent_owned(first_agent_id));
|
||||
|
||||
state.mark_parent_owned(second_agent_id);
|
||||
state.clear();
|
||||
assert!(!state.is_parent_owned(second_agent_id));
|
||||
}
|
||||
|
||||
#[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