Branch conversations when editing earlier TUI prompts (#33201)

## What changed

- Fork the conversation immediately before the selected prompt instead of rolling back the current thread in place, preserving the original conversation.
- Reopen the selected prompt in the new conversation with its images, text elements, and mention bindings intact.
- Start a fresh conversation when editing the first prompt, show a dedicated continuation notice, and restore the prompt with an error if branching fails.

## Testing

- Cover branching before first and later prompts, source preservation, prompt restoration, hidden review prompts, mid-turn steering, in-progress turns, stale transcript entries, and mention bindings.

GitOrigin-RevId: 15473535b3f9733b0300711a498969e6d389db79
This commit is contained in:
Felipe Coury authored and copyberry committed 2026-07-15 01:36:44 +00:00
1 parent 72b41c55fb
commit 469ce0db51
17 files changed
+928 -549

No files matched your search

+73 -8
View File
@@ -4,6 +4,7 @@
//! actions are delegated to focused app submodules so the central match remains the routing layer.
use super::resize_reflow::trailing_run_start;
use super::session_lifecycle::ThreadAttachPresentation;
use super::*;
use crate::config_update::format_config_error;
use crate::external_agent_config_migration_flow::ExternalAgentConfigMigrationFlowOutcome;
@@ -182,7 +183,11 @@ impl App {
self.shutdown_current_thread(app_server).await;
match self
.replace_chat_widget_with_app_server_thread(
tui, app_server, forked, /*initial_user_message*/ None,
tui,
app_server,
forked,
ThreadAttachPresentation::SessionLineage,
/*initial_user_message*/ None,
)
.await
{
@@ -224,6 +229,72 @@ impl App {
tui.frame_requester().schedule_frame();
}
AppEvent::ForkSessionForPromptEdit {
thread_id,
nth_user_message,
mut prompt,
} => {
if self.chat_widget.thread_id() != Some(thread_id) {
return Ok(AppRunControl::Continue);
}
self.session_telemetry.counter(
"codex.thread.fork",
/*inc*/ 1,
&[("source", "transcript")],
);
self.refresh_in_memory_config_from_disk_best_effort("forking the thread")
.await;
let config = self.fresh_session_config();
let started = match app_server
.thread_read(thread_id, /*include_turns*/ true)
.await
{
Ok(thread) => match crate::app_backtrack::backtrack_fork_last_turn_id(
&thread.turns,
nth_user_message,
&mut prompt,
) {
Ok(Some(last_turn_id)) => {
app_server
.fork_thread_after(config.clone(), thread_id, last_turn_id)
.await
}
Ok(None) => {
app_server
.start_thread_with_session_start_source(
&config, /*session_start_source*/ None,
)
.await
}
Err(err) => Err(err),
},
Err(err) => Err(err),
};
match started {
Ok(forked) => {
self.shutdown_current_thread(app_server).await;
match self
.replace_chat_widget_with_app_server_thread(
tui,
app_server,
forked,
ThreadAttachPresentation::PromptEdit,
/*initial_user_message*/ None,
)
.await
{
Ok(()) => self.chat_widget.restore_user_message_to_composer(prompt),
Err(err) => {
self.restore_backtrack_prompt_after_branch_error(prompt, err);
}
}
}
Err(err) => {
self.restore_backtrack_prompt_after_branch_error(prompt, err);
}
}
tui.frame_requester().schedule_frame();
}
AppEvent::BeginInitialHistoryReplayBuffer => {
self.begin_initial_history_replay_buffer();
}
@@ -288,11 +359,6 @@ impl App {
self.chat_widget.note_stream_consolidation_completed();
self.insert_pending_usage_output_after_stream_shutdown(tui);
}
AppEvent::ApplyThreadRollback { num_turns } => {
if self.apply_non_pending_thread_rollback(num_turns) {
tui.frame_requester().schedule_frame();
}
}
AppEvent::StartCommitAnimation => {
if self
.commit_anim_running
@@ -400,11 +466,10 @@ impl App {
};
self.chat_widget.prepare_safety_buffering_retry();
self.handle_thread_rollback_response_with_origin(
self.handle_thread_rollback_response(
thread_id,
/*num_turns*/ 1,
&rollback_response,
super::thread_routing::ThreadRollbackOrigin::SafetyBufferingRetry,
)
.await;
+2 -1
View File
@@ -233,7 +233,8 @@ impl App {
&& self.chat_widget.composer_is_empty() =>
{
if let Some(selection) = self.confirm_backtrack_from_main() {
self.apply_backtrack_selection(tui, selection);
self.apply_backtrack_selection(selection);
tui.frame_requester().schedule_frame();
}
}
KeyEvent {
+19 -3
View File
@@ -6,6 +6,12 @@
use super::*;
#[derive(Clone, Copy)]
pub(super) enum ThreadAttachPresentation {
SessionLineage,
PromptEdit,
}
impl App {
pub(super) async fn open_agent_picker(&mut self, app_server: &mut AppServerSession) {
self.backfill_loaded_subagent_threads(app_server).await;
@@ -571,6 +577,7 @@ impl App {
tui,
app_server,
started,
ThreadAttachPresentation::SessionLineage,
initial_user_message,
)
.await
@@ -605,6 +612,7 @@ impl App {
tui: &mut tui::Tui,
app_server: &mut AppServerSession,
started: AppServerStartedThread,
presentation: ThreadAttachPresentation,
initial_user_message: Option<crate::chatwidget::UserMessage>,
) -> Result<()> {
// Initial messages are for freshly attached primary threads only. Thread switches and
@@ -617,8 +625,12 @@ impl App {
initial_user_message,
);
self.replace_chat_widget(ChatWidget::new_with_app_event(init));
self.enqueue_primary_thread_session(started.session, started.turns)
.await?;
self.enqueue_primary_thread_session_with_presentation(
started.session,
started.turns,
presentation,
)
.await?;
self.backfill_loaded_subagent_threads(app_server).await;
Ok(())
}
@@ -808,7 +820,11 @@ impl App {
.update_search_dir(self.config.cwd.to_path_buf());
match self
.replace_chat_widget_with_app_server_thread(
tui, app_server, resumed, /*initial_user_message*/ None,
tui,
app_server,
resumed,
ThreadAttachPresentation::SessionLineage,
/*initial_user_message*/ None,
)
.await
{
+286 -119
View File
@@ -98,7 +98,12 @@ use codex_protocol::models::ActivePermissionProfile;
use codex_protocol::models::FileSystemPermissions;
use codex_protocol::models::NetworkPermissions;
use codex_protocol::models::PermissionProfile;
use codex_protocol::protocol::EventMsg;
use codex_protocol::protocol::MAX_THREAD_GOAL_OBJECTIVE_CHARS;
use codex_protocol::protocol::RolloutItem;
use codex_protocol::protocol::TurnCompleteEvent;
use codex_protocol::protocol::TurnStartedEvent;
use codex_protocol::protocol::UserMessageEvent;
use codex_protocol::request_permissions::RequestPermissionProfile;
use codex_protocol::user_input::TextElement;
use codex_utils_absolute_path::AbsolutePathBuf;
@@ -5160,8 +5165,8 @@ async fn fresh_session_config_uses_current_service_tier() {
}
#[tokio::test]
async fn backtrack_selection_with_duplicate_history_targets_unique_turn() {
let (mut app, _app_event_rx, mut op_rx) = make_test_app_with_channels().await;
async fn backtrack_selection_preserves_selected_prompt_and_requests_branch() {
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
let user_cell = |text: &str,
text_elements: Vec<TextElement>,
@@ -5246,6 +5251,11 @@ async fn backtrack_selection_with_duplicate_history_targets_unique_turn() {
];
assert_eq!(user_count(&app.transcript_cells), 2);
let transcript_before: Vec<String> = app
.transcript_cells
.iter()
.map(|cell| lines_to_single_string(&cell.display_lines(/*width*/ 80)))
.collect();
let base_id = ThreadId::new();
app.chat_widget
@@ -5279,131 +5289,290 @@ async fn backtrack_selection_with_duplicate_history_targets_unique_turn() {
let selection = app
.confirm_backtrack_from_main()
.expect("backtrack selection");
assert_eq!(selection.nth_user_message, 1);
assert_eq!(selection.prefill, edited_text);
assert_eq!(selection.text_elements, edited_text_elements);
assert_eq!(selection.local_image_paths, edited_local_image_paths);
assert_eq!(
selection.remote_image_urls,
vec!["https://example.com/backtrack.png".to_string()]
let expected = BacktrackSelection {
thread_id: base_id,
nth_user_message: 1,
prompt: crate::chatwidget::UserMessage {
text: edited_text,
local_images: vec![crate::bottom_pane::LocalImageAttachment {
placeholder: placeholder.to_string(),
path: edited_local_image_paths[0].clone(),
}],
remote_image_urls: vec!["https://example.com/backtrack.png".to_string()],
text_elements: edited_text_elements,
mention_bindings: Vec::new(),
},
};
assert_eq!(selection, expected);
app.apply_backtrack_selection(selection);
let event = std::iter::from_fn(|| app_event_rx.try_recv().ok())
.find(|event| matches!(event, AppEvent::ForkSessionForPromptEdit { .. }))
.expect("prompt edit fork should be requested");
assert_matches!(
event,
AppEvent::ForkSessionForPromptEdit {
thread_id,
nth_user_message,
prompt,
} if thread_id == expected.thread_id
&& nth_user_message == expected.nth_user_message
&& prompt == expected.prompt
);
app.apply_backtrack_rollback(selection);
let transcript_after: Vec<String> = app
.transcript_cells
.iter()
.map(|cell| lines_to_single_string(&cell.display_lines(/*width*/ 80)))
.collect();
assert_eq!(transcript_after, transcript_before);
}
#[tokio::test]
async fn backtrack_branch_failure_restores_selected_prompt_snapshot() {
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
app.restore_backtrack_prompt_after_branch_error(
crate::chatwidget::UserMessage::from("edit this prompt"),
"branch unavailable",
);
assert_eq!(
app.chat_widget.composer_text_with_pending(),
"edit this prompt"
);
let cell = match app_event_rx.try_recv() {
Ok(AppEvent::InsertHistoryCell(cell)) => cell,
other => panic!("expected InsertHistoryCell event, got {other:?}"),
};
let rendered = lines_to_single_string(&cell.display_lines(/*width*/ 80));
assert_app_snapshot!(
"backtrack_branch_failure_restores_selected_prompt",
rendered
);
}
#[tokio::test]
async fn prompt_edit_forks_before_selected_prompt_and_preserves_source() -> Result<()> {
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
let config = app.chat_widget.config_ref().clone();
let filename_ts = "2025-01-05T12-00-00";
let source_thread_id = app_test_support::create_fake_rollout(
config.codex_home.as_path(),
filename_ts,
"2025-01-05T12:00:00Z",
"unused preview",
Some("test-provider"),
/*git_info*/ None,
)
.expect("materialized rollout should be created");
let source_path =
app_test_support::rollout_path(config.codex_home.as_path(), filename_ts, &source_thread_id);
let session_meta = std::fs::read_to_string(&source_path)?
.lines()
.next()
.expect("fake rollout should have session metadata")
.to_string();
std::fs::write(&source_path, format!("{session_meta}\n"))?;
for (turn_id, message, images, local_images) in [
("turn-1", "retained prompt", None, Vec::new()),
(
"turn-2",
"selected prompt [Image #1]",
Some(vec!["https://example.com/backtrack.png".to_string()]),
vec![PathBuf::from("/tmp/fake-image.png")],
),
] {
for item in [
RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {
turn_id: turn_id.to_string(),
trace_id: None,
started_at: None,
model_context_window: None,
collaboration_mode_kind: ModeKind::default(),
})),
RolloutItem::EventMsg(EventMsg::UserMessage(UserMessageEvent {
message: message.to_string(),
images,
local_images,
..Default::default()
})),
RolloutItem::EventMsg(EventMsg::TurnComplete(TurnCompleteEvent {
turn_id: turn_id.to_string(),
last_agent_message: None,
error: None,
started_at: None,
completed_at: None,
duration_ms: None,
time_to_first_token_ms: None,
})),
] {
codex_rollout::append_rollout_item_to_path(&source_path, &item).await?;
}
}
let source_thread_id = ThreadId::from_string(&source_thread_id)?;
let mut app_server = Box::pin(crate::start_embedded_app_server_for_picker(&config)).await?;
let started = app_server
.resume_thread(
config.clone(),
source_thread_id,
crate::app_server_session::ResumeModelSettings::OverrideFromCurrentConfig,
)
.await?;
app.enqueue_primary_thread_session(started.session, started.turns)
.await?;
while app_event_rx.try_recv().is_ok() {}
let source_before = std::fs::read_to_string(&source_path)?;
let mut tui = crate::tui::test_support::make_test_tui()?;
let prompt = crate::chatwidget::UserMessage {
text: "selected prompt [Image #1]".to_string(),
local_images: vec![crate::bottom_pane::LocalImageAttachment {
placeholder: "[Image #1]".to_string(),
path: PathBuf::from("/tmp/fake-image.png"),
}],
remote_image_urls: vec!["https://example.com/backtrack.png".to_string()],
text_elements: Vec::new(),
mention_bindings: Vec::new(),
};
let control = Box::pin(app.handle_event(
&mut tui,
&mut app_server,
AppEvent::ForkSessionForPromptEdit {
thread_id: source_thread_id,
nth_user_message: 1,
prompt: prompt.clone(),
},
))
.await?;
assert!(matches!(control, AppRunControl::Continue));
let forked_thread_id = app
.chat_widget
.thread_id()
.expect("prompt edit should switch to a forked thread");
assert_ne!(forked_thread_id, source_thread_id);
assert_eq!(app.chat_widget.composer_text_with_pending(), prompt.text);
assert_eq!(
app.chat_widget.remote_image_urls(),
vec!["https://example.com/backtrack.png".to_string()]
prompt.remote_image_urls
);
assert_eq!(std::fs::read_to_string(&source_path)?, source_before);
assert_eq!(
app_server
.thread_read(source_thread_id, /*include_turns*/ true)
.await?
.turns
.iter()
.map(|turn| turn.id.as_str())
.collect::<Vec<_>>(),
vec!["turn-1", "turn-2"]
);
assert_eq!(
app_server
.thread_read(forked_thread_id, /*include_turns*/ true)
.await?
.turns
.iter()
.map(|turn| turn.id.as_str())
.collect::<Vec<_>>(),
vec!["turn-1"]
);
let mut rollback_turns = None;
while let Ok(op) = op_rx.try_recv() {
if let Op::ThreadRollback { num_turns } = op {
rollback_turns = Some(num_turns);
}
}
let history = std::iter::from_fn(|| app_event_rx.try_recv().ok())
.filter_map(|event| match event {
AppEvent::InsertHistoryCell(cell) => {
Some(lines_to_single_string(&cell.display_lines(/*width*/ 120)))
}
_ => None,
})
.collect::<Vec<_>>();
let retained_index = history
.iter()
.position(|line| line.contains("retained prompt"))
.expect("forked history should replay the retained prompt");
let notice_index = history
.iter()
.position(|line| line == "• You’re continuing from this point in a new conversation")
.expect("prompt edit should emit the branch notice");
assert!(retained_index < notice_index);
assert!(
!history
.iter()
.any(|line| line.contains("Thread forked from"))
);
app_server.shutdown().await?;
assert_eq!(rollback_turns, Some(1));
Ok(())
}
#[tokio::test]
async fn backtrack_remote_image_only_selection_clears_existing_composer_draft() {
let (mut app, _app_event_rx, mut op_rx) = make_test_app_with_channels().await;
app.transcript_cells = vec![Arc::new(UserHistoryCell {
message: "original".to_string(),
text_elements: Vec::new(),
local_image_paths: Vec::new(),
remote_image_urls: Vec::new(),
}) as Arc<dyn HistoryCell>];
app.chat_widget
.set_composer_text("stale draft".to_string(), Vec::new(), Vec::new());
let remote_image_url = "https://example.com/remote-only.png".to_string();
app.apply_backtrack_rollback(BacktrackSelection {
nth_user_message: 0,
prefill: String::new(),
text_elements: Vec::new(),
local_image_paths: Vec::new(),
remote_image_urls: vec![remote_image_url.clone()],
});
assert_eq!(app.chat_widget.composer_text_with_pending(), "");
assert_eq!(app.chat_widget.remote_image_urls(), vec![remote_image_url]);
let mut rollback_turns = None;
while let Ok(op) = op_rx.try_recv() {
if let Op::ThreadRollback { num_turns } = op {
rollback_turns = Some(num_turns);
}
}
assert_eq!(rollback_turns, Some(1));
}
#[tokio::test]
async fn backtrack_resubmit_preserves_data_image_urls_in_user_turn() {
let (mut app, _app_event_rx, mut op_rx) = make_test_app_with_channels().await;
let thread_id = ThreadId::new();
app.chat_widget
.handle_thread_session(crate::session_state::ThreadSessionState {
thread_id,
forked_from_id: None,
fork_parent_title: None,
thread_name: None,
model: "gpt-test".to_string(),
model_provider_id: "test-provider".to_string(),
service_tier: None,
approval_policy: AskForApproval::Never,
approvals_reviewer: ApprovalsReviewer::User,
permission_profile: PermissionProfile::read_only(),
active_permission_profile: None,
cwd: test_path_buf("/home/user/project").abs(),
runtime_workspace_roots: Vec::new(),
instruction_source_paths: Vec::new(),
reasoning_effort: None,
collaboration_mode: None,
personality: None,
message_history: None,
network_proxy: None,
rollout_path: Some(PathBuf::new()),
});
let data_image_url = "data:image/png;base64,abc123".to_string();
app.transcript_cells = vec![Arc::new(UserHistoryCell {
message: "please inspect this".to_string(),
text_elements: Vec::new(),
local_image_paths: Vec::new(),
remote_image_urls: vec![data_image_url.clone()],
}) as Arc<dyn HistoryCell>];
app.apply_backtrack_rollback(BacktrackSelection {
nth_user_message: 0,
prefill: "please inspect this".to_string(),
text_elements: Vec::new(),
local_image_paths: Vec::new(),
remote_image_urls: vec![data_image_url.clone()],
});
app.chat_widget
.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
let mut saw_rollback = false;
let mut submitted_items: Option<Vec<UserInput>> = None;
while let Ok(op) = op_rx.try_recv() {
match op {
Op::ThreadRollback { .. } => saw_rollback = true,
Op::UserTurn { items, .. } => submitted_items = Some(items),
_ => {}
}
}
assert!(saw_rollback);
let items = submitted_items.expect("expected user turn after backtrack resubmit");
assert!(items.iter().any(|item| {
matches!(
item,
UserInput::Image { url, .. } if url == &data_image_url
async fn prompt_edit_before_first_prompt_starts_fresh_thread() -> Result<()> {
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
let config = app.chat_widget.config_ref().clone();
let source_thread_id = app_test_support::create_fake_rollout(
config.codex_home.as_path(),
"2025-01-05T12-00-00",
"2025-01-05T12:00:00Z",
"first prompt",
Some("test-provider"),
/*git_info*/ None,
)
.expect("materialized rollout should be created");
let source_thread_id = ThreadId::from_string(&source_thread_id)?;
let mut app_server = Box::pin(crate::start_embedded_app_server_for_picker(&config)).await?;
let started = app_server
.resume_thread(
config.clone(),
source_thread_id,
crate::app_server_session::ResumeModelSettings::OverrideFromCurrentConfig,
)
}));
.await?;
app.enqueue_primary_thread_session(started.session, started.turns)
.await?;
while app_event_rx.try_recv().is_ok() {}
let mut tui = crate::tui::test_support::make_test_tui()?;
let control = Box::pin(app.handle_event(
&mut tui,
&mut app_server,
AppEvent::ForkSessionForPromptEdit {
thread_id: source_thread_id,
nth_user_message: 0,
prompt: crate::chatwidget::UserMessage::from("first prompt"),
},
))
.await?;
assert!(matches!(control, AppRunControl::Continue));
let fresh_thread_id = app
.chat_widget
.thread_id()
.expect("first prompt edit should start a fresh thread");
assert_ne!(fresh_thread_id, source_thread_id);
assert_eq!(app.chat_widget.composer_text_with_pending(), "first prompt");
let history = std::iter::from_fn(|| app_event_rx.try_recv().ok())
.filter_map(|event| match event {
AppEvent::InsertHistoryCell(cell) => {
Some(lines_to_single_string(&cell.display_lines(/*width*/ 120)))
}
_ => None,
})
.collect::<Vec<_>>();
assert!(
history.iter().any(|line| {
line == "• You’re continuing from this point in a new conversation"
})
);
assert!(
!history
.iter()
.any(|line| line.contains("Thread forked from"))
);
app_server.shutdown().await?;
Ok(())
}
#[tokio::test]
@@ -5670,8 +5839,7 @@ async fn queued_rollback_syncs_overlay_and_clears_deferred_history() {
/*status_account_display*/ None, /*plan_type*/ None,
/*has_chatgpt_account*/ false, /*has_codex_backend_auth*/ true,
);
app.chat_widget
.set_composer_text("/usage daily".to_string(), Vec::new(), Vec::new());
app.chat_widget.insert_str("/usage daily");
app.chat_widget
.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
app.chat_widget
@@ -6271,7 +6439,6 @@ async fn clear_only_ui_reset_preserves_chat_session_state() {
assert!(!app.has_emitted_history_lines);
assert!(!app.backtrack.primed);
assert!(!app.backtrack.overlay_preview_active);
assert!(app.backtrack.pending_rollback.is_none());
assert!(!app.backtrack_render_pending);
assert_eq!(app.chat_widget.thread_id(), Some(thread_id));
assert_eq!(app.chat_widget.composer_text_with_pending(), "draft prompt");
+1 -2
View File
@@ -196,8 +196,7 @@ async fn stale_rate_limit_reads_preserve_newer_workspace_hard_stop_for_every_ori
credits: None,
}),
);
app.chat_widget
.set_composer_text("/usage".to_string(), Vec::new(), Vec::new());
app.chat_widget.insert_str("/usage");
app.chat_widget
.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
app.chat_widget
+27 -43
View File
@@ -4,20 +4,13 @@
//! channels, submits thread-scoped operations through the app server, and replays buffered events
//! when the visible thread changes.
use super::session_lifecycle::ThreadAttachPresentation;
use super::*;
use crate::session_resume::read_session_model;
#[derive(Clone, Copy)]
pub(super) enum ThreadRollbackOrigin {
Backtrack,
SafetyBufferingRetry,
}
impl App {
pub(super) async fn shutdown_current_thread(&mut self, app_server: &mut AppServerSession) {
if let Some(thread_id) = self.chat_widget.thread_id() {
// Clear any in-flight rollback guard when switching threads.
self.backtrack.pending_rollback = None;
if let Err(err) = app_server.thread_unsubscribe(thread_id).await {
tracing::warn!("failed to unsubscribe thread {thread_id}: {err}");
}
@@ -698,18 +691,6 @@ impl App {
.await?;
Ok(true)
}
AppCommand::ThreadRollback { num_turns } => {
let response = match app_server.thread_rollback(thread_id, *num_turns).await {
Ok(response) => response,
Err(err) => {
self.handle_backtrack_rollback_failed();
return Err(err);
}
};
self.handle_thread_rollback_response(thread_id, *num_turns, &response)
.await;
Ok(true)
}
AppCommand::Review { target } => {
let response = app_server.review_start(thread_id, target.clone()).await?;
let review_thread_id = ThreadId::from_string(&response.review_thread_id)
@@ -1110,6 +1091,20 @@ impl App {
&mut self,
session: ThreadSessionState,
turns: Vec<Turn>,
) -> Result<()> {
self.enqueue_primary_thread_session_with_presentation(
session,
turns,
ThreadAttachPresentation::SessionLineage,
)
.await
}
pub(super) async fn enqueue_primary_thread_session_with_presentation(
&mut self,
session: ThreadSessionState,
turns: Vec<Turn>,
presentation: ThreadAttachPresentation,
) -> Result<()> {
let thread_id = session.thread_id;
self.primary_thread_id = Some(thread_id);
@@ -1126,7 +1121,14 @@ impl App {
self.activate_thread_channel(thread_id).await;
self.chat_widget
.set_initial_user_message_submit_suppressed(/*suppressed*/ true);
self.chat_widget.handle_thread_session(session);
match presentation {
ThreadAttachPresentation::SessionLineage => {
self.chat_widget.handle_thread_session(session);
}
ThreadAttachPresentation::PromptEdit => {
self.chat_widget.handle_prompt_edit_thread_session(session);
}
}
let should_buffer_initial_replay = !turns.is_empty();
if should_buffer_initial_replay {
self.app_event_tx
@@ -1138,6 +1140,9 @@ impl App {
self.app_event_tx
.send(AppEvent::EndInitialHistoryReplayBuffer);
}
if matches!(presentation, ThreadAttachPresentation::PromptEdit) {
self.chat_widget.emit_prompt_edit_thread_event();
}
let pending = std::mem::take(&mut self.pending_primary_events);
for pending_event in pending {
match pending_event {
@@ -1411,22 +1416,6 @@ impl App {
thread_id: ThreadId,
num_turns: u32,
response: &ThreadRollbackResponse,
) {
self.handle_thread_rollback_response_with_origin(
thread_id,
num_turns,
response,
ThreadRollbackOrigin::Backtrack,
)
.await;
}
pub(super) async fn handle_thread_rollback_response_with_origin(
&mut self,
thread_id: ThreadId,
num_turns: u32,
response: &ThreadRollbackResponse,
origin: ThreadRollbackOrigin,
) {
if let Some(channel) = self.thread_event_channels.get(&thread_id) {
let mut store = channel.store.lock().await;
@@ -1453,12 +1442,7 @@ impl App {
self.clear_active_thread().await;
}
}
match origin {
ThreadRollbackOrigin::Backtrack => self.handle_backtrack_rollback_succeeded(num_turns),
ThreadRollbackOrigin::SafetyBufferingRetry => {
self.apply_non_pending_thread_rollback(num_turns);
}
}
self.apply_non_pending_thread_rollback(num_turns);
}
pub(super) fn handle_thread_event_now(&mut self, event: ThreadBufferedEvent) {