Files
codex/codex-rs/tui/src/app/archived_thread.rs
T
Benjamin Carlsson 7924f95421 Keep archived threads read-only and support unarchiving in the TUI (#61486)
## What changed

- Show an archived-thread notice and freeze input while preserving the cached transcript, drafts, pending steers, and question answers.
- Allow `U` to unarchive and resume the displayed thread, and automatically resume it when another client unarchives it.
- Preserve archived state across reconnects and thread selection, and retain drafts when recovery fails or encounters a writer conflict.
- Dismiss transient composer searches and suppress automatic submissions when entering a read-only view.

## Testing

Add regression tests and notice snapshots covering archive recovery, external unarchiving, writer conflicts, reconnects, input preservation, and agent navigation.

GitOrigin-RevId: 695c19790b87df83e51095b400f605e37b309fc1
2026-11-14 07:46:36 +00:00

77 lines
2.5 KiB
Rust

//! Archive notifications freeze cached threads; external unarchive resumes the displayed thread.
//! Archive metadata is separate from attachment; archived channels only replay cached events.
use super::*;
use crate::chatwidget::ReadOnlyThread;
pub(super) fn update_archived_thread(
app: &mut App,
thread_id: ThreadId,
notification: &ServerNotification,
) {
let Some(channel) = app.thread_event_channels.get_mut(&thread_id) else {
return;
};
match notification {
ServerNotification::ThreadArchived(_) => {
channel.archived = true;
channel.mark_replay_only();
}
ServerNotification::ThreadUnarchived(_) if channel.archived => {
channel.archived = false;
}
_ => return,
}
let resume = !channel.archived;
if app.current_displayed_thread_id() == Some(thread_id) {
show_cached_read_only_thread(app, thread_id);
if resume {
app.app_event_tx
.send(AppEvent::ResumeUnarchivedThread(thread_id));
}
}
}
pub(super) async fn resume_displayed_thread(
app: &mut App,
tui: &mut tui::Tui,
app_server: &mut AppServerSession,
thread_id: ThreadId,
) {
let target = SessionTarget {
backend_id: app_server.backend_id(),
path: app
.primary_session_configured
.as_ref()
.and_then(|session| session.rollout_path.clone()),
thread_id,
cwd: None,
history_mode: None,
};
if let Ok(AppRunControl::Exit(_)) = app.resume_target_session(tui, app_server, target).await {
app.app_event_tx.send(AppEvent::Exit(ExitMode::Immediate));
}
// A writer conflict does not establish that the thread was unarchived.
// Keep the archive flag if resume could not replace the archived view.
if app.current_displayed_thread_id() == Some(thread_id)
&& !app.chat_widget.is_archived_view()
&& let Some(channel) = app.thread_event_channels.get_mut(&thread_id)
{
channel.archived = false;
}
}
pub(super) fn show_cached_read_only_thread(app: &mut App, thread_id: ThreadId) {
let Some(channel) = app.thread_event_channels.get(&thread_id) else {
return;
};
let reason = if channel.archived {
ReadOnlyThread::Archived
} else if channel.attachment() == ThreadEventAttachment::ExternalWriter {
ReadOnlyThread::ExternalWriter
} else {
return;
};
app.chat_widget.show_read_only_thread(reason);
}