mirror of
https://github.com/openai/codex.git
synced 2026-11-18 23:02:23 +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
@@ -5,6 +5,8 @@
|
||||
//! cache used for multi-agent navigation.
|
||||
|
||||
use super::*;
|
||||
use crate::app_server_session::source_agent_path;
|
||||
use crate::app_server_session::thread_blocks_direct_input;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(super) enum ThreadAttachPresentation {
|
||||
@@ -184,6 +186,12 @@ impl App {
|
||||
self.sync_active_agent_label();
|
||||
}
|
||||
|
||||
/// Persists the app-server's authoritative ownership flag and updates the active composer.
|
||||
pub(super) fn mark_primary_thread_parent_owned(&mut self, thread_id: ThreadId) {
|
||||
self.agent_navigation.mark_parent_owned(thread_id);
|
||||
self.chat_widget.set_parent_owned_thread();
|
||||
}
|
||||
|
||||
/// Marks a cached picker thread closed and recomputes the contextual footer label.
|
||||
///
|
||||
/// Closing a thread is not the same as removing it: users can still inspect finished agent
|
||||
@@ -205,6 +213,8 @@ impl App {
|
||||
.await
|
||||
{
|
||||
Ok(thread) => {
|
||||
let is_parent_owned = thread_blocks_direct_input(&thread);
|
||||
let agent_path = source_agent_path(&thread.source);
|
||||
let is_running = matches!(
|
||||
thread.status,
|
||||
codex_app_server_protocol::ThreadStatus::Active { .. }
|
||||
@@ -227,6 +237,10 @@ impl App {
|
||||
}),
|
||||
is_closed,
|
||||
);
|
||||
if is_parent_owned {
|
||||
self.agent_navigation.mark_parent_owned(thread_id);
|
||||
}
|
||||
self.agent_navigation.set_agent_path(thread_id, agent_path);
|
||||
self.agent_navigation.set_running(thread_id, is_running);
|
||||
true
|
||||
}
|
||||
@@ -278,7 +292,12 @@ impl App {
|
||||
.resume_thread(self.config.clone(), thread_id, self.resume_model_settings())
|
||||
.await
|
||||
{
|
||||
Ok(started) => (started.session, started.turns, true),
|
||||
Ok(started) => {
|
||||
if started.blocks_direct_input {
|
||||
self.agent_navigation.mark_parent_owned(thread_id);
|
||||
}
|
||||
(started.session, started.turns, true)
|
||||
}
|
||||
Err(resume_err) => {
|
||||
tracing::warn!(
|
||||
thread_id = %thread_id,
|
||||
@@ -369,7 +388,6 @@ impl App {
|
||||
.add_error_message(format!("Agent thread {thread_id} is no longer available."));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut is_replay_only = self
|
||||
.agent_navigation
|
||||
.get(&thread_id)
|
||||
@@ -398,7 +416,6 @@ impl App {
|
||||
.add_error_message(format!("Agent thread {thread_id} is no longer available."));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let previous_thread_id = self.active_thread_id;
|
||||
self.store_active_thread_receiver().await;
|
||||
self.active_thread_id = None;
|
||||
@@ -419,6 +436,7 @@ impl App {
|
||||
&mut snapshot,
|
||||
)
|
||||
.await;
|
||||
let blocks_direct_input = self.agent_navigation.is_parent_owned(thread_id);
|
||||
|
||||
self.active_thread_id = Some(thread_id);
|
||||
self.active_thread_rx = Some(receiver);
|
||||
@@ -429,6 +447,9 @@ impl App {
|
||||
/*initial_user_message*/ None,
|
||||
);
|
||||
self.replace_chat_widget(ChatWidget::new_with_app_event(init));
|
||||
if blocks_direct_input {
|
||||
self.chat_widget.set_parent_owned_thread();
|
||||
}
|
||||
|
||||
self.reset_for_thread_switch(tui)?;
|
||||
self.replay_thread_snapshot(snapshot, !is_replay_only);
|
||||
@@ -519,6 +540,9 @@ impl App {
|
||||
.set_queue_submissions_until_session_configured(/*queue*/ false);
|
||||
match result {
|
||||
Ok(started) => {
|
||||
if started.blocks_direct_input {
|
||||
self.mark_primary_thread_parent_owned(started.session.thread_id);
|
||||
}
|
||||
self.enqueue_primary_thread_session(started.session, started.turns)
|
||||
.await?;
|
||||
self.chat_widget.maybe_send_next_queued_input();
|
||||
@@ -625,6 +649,9 @@ impl App {
|
||||
initial_user_message,
|
||||
);
|
||||
self.replace_chat_widget(ChatWidget::new_with_app_event(init));
|
||||
if started.blocks_direct_input {
|
||||
self.mark_primary_thread_parent_owned(started.session.thread_id);
|
||||
}
|
||||
self.enqueue_primary_thread_session_with_presentation(
|
||||
started.session,
|
||||
started.turns,
|
||||
@@ -694,6 +721,9 @@ impl App {
|
||||
|
||||
for thread in find_loaded_subagent_threads_for_primary(threads, primary_thread_id) {
|
||||
let agent_path = thread.agent_path;
|
||||
if thread.blocks_direct_input {
|
||||
self.agent_navigation.mark_parent_owned(thread.thread_id);
|
||||
}
|
||||
self.upsert_agent_picker_thread(
|
||||
thread.thread_id,
|
||||
thread.agent_nickname,
|
||||
|
||||
Reference in new issue
Block a user