Clean up side conversations in the background (#35887)

## Why

Switching away from a side conversation should not wait for its interrupt and
unsubscribe requests to finish.

## What changed

- Remove a side conversation from local TUI state immediately when switching
  threads, then interrupt and unsubscribe it in a background task.
- Retry interruption with the active turn ID when the original turn races with
  cleanup.
- Ignore late notifications and reject server requests for abandoned side
  conversations.

## Testing

- Added coverage that background cleanup removes local state and ignores late
  events and approval requests.

GitOrigin-RevId: 7a1d1c34f16ab023d1d1e235451b55404731190c
This commit is contained in:
Eric Traut authored and copyberry committed 2026-07-29 03:54:05 +00:00
1 parent b96ebfb312
commit d06c7ac055
6 files changed
+148 -11

No files matched your search

+3
View File
@@ -180,6 +180,7 @@ use ratatui::widgets::Paragraph;
use ratatui::widgets::Wrap;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Write;
use std::path::Path;
@@ -575,6 +576,7 @@ pub(crate) struct App {
thread_event_listener_tasks: HashMap<ThreadId, JoinHandle<()>>,
agent_navigation: AgentNavigationState,
side_threads: HashMap<ThreadId, SideThreadState>,
abandoned_side_threads: HashSet<ThreadId>,
active_thread_id: Option<ThreadId>,
active_thread_rx: Option<mpsc::Receiver<ThreadBufferedEvent>>,
primary_thread_id: Option<ThreadId>,
@@ -1068,6 +1070,7 @@ See the Codex keymap documentation for supported actions and examples."
thread_event_listener_tasks: HashMap::new(),
agent_navigation: AgentNavigationState::default(),
side_threads: HashMap::new(),
abandoned_side_threads: HashSet::new(),
active_thread_id: None,
active_thread_rx: None,
primary_thread_id: None,