mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Use app-server metadata for TUI session restoration (#43360)
## What changed - Carry the working directory from `thread/list` and `thread/read` in session selections, and use app-server metadata to resolve resume and fork directories. - Use the model reported by thread reads and thread-started notifications when restoring session state. - Remove TUI helpers that read session IDs, working directories, and models directly from rollout files or the state database. Picker selection now requires a thread ID in the selected row. ## Testing Extend picker coverage to verify that selections preserve the working directory, and add a snapshot asserting that switching to a read thread displays the server-reported model. GitOrigin-RevId: c9d13e1e56ea2139d3e96344d72ca9ee2de73396
This commit is contained in:
1 parent
21bd5d3cdc
commit
694b6319d3
15 files changed
+117
-462
No files matched your search
@@ -369,6 +369,7 @@ impl App {
|
||||
let target_session = SessionTarget {
|
||||
path: target_thread.path.clone(),
|
||||
thread_id: root_thread_id,
|
||||
cwd: Some(target_thread.cwd.to_path_buf()),
|
||||
history_mode: Some(target_thread.history_mode),
|
||||
};
|
||||
match self
|
||||
|
||||
@@ -1849,6 +1849,7 @@ async fn resuming_active_session_closes_command_center() -> Result<()> {
|
||||
SessionSelection::Resume(SessionTarget {
|
||||
path: None,
|
||||
thread_id,
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
})
|
||||
)
|
||||
@@ -1907,6 +1908,7 @@ async fn resume_picker_round_trip_preserves_each_threads_input() -> Result<()> {
|
||||
&id,
|
||||
)),
|
||||
thread_id: ThreadId::from_string(&id)?,
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
});
|
||||
}
|
||||
@@ -2006,6 +2008,7 @@ async fn command_center_handles_resume_failure_and_success() -> Result<()> {
|
||||
SessionSelection::Resume(SessionTarget {
|
||||
path: None,
|
||||
thread_id: ThreadId::new(),
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
})
|
||||
)
|
||||
@@ -2029,6 +2032,7 @@ async fn command_center_handles_resume_failure_and_success() -> Result<()> {
|
||||
SessionSelection::Resume(SessionTarget {
|
||||
path: Some(path),
|
||||
thread_id,
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
})
|
||||
)
|
||||
|
||||
@@ -264,6 +264,7 @@ impl App {
|
||||
.as_ref()
|
||||
.and_then(|session| session.rollout_path.clone()),
|
||||
thread_id,
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
};
|
||||
let _ = self.resume_target_session(tui, app_server, target).await;
|
||||
|
||||
@@ -9,7 +9,7 @@ impl App {
|
||||
pub(super) async fn resume_config_for_target(
|
||||
&mut self,
|
||||
tui: &mut tui::Tui,
|
||||
app_server: &AppServerSession,
|
||||
app_server: &mut AppServerSession,
|
||||
target_session: &SessionTarget,
|
||||
) -> std::result::Result<(Config, crate::local_settings::LocalSettings), AppRunControl> {
|
||||
self.refresh_in_memory_config_from_disk_best_effort("resuming a thread")
|
||||
@@ -18,7 +18,9 @@ impl App {
|
||||
.runtime_working_directory_override
|
||||
.as_deref()
|
||||
.or(self.harness_overrides.cwd.as_deref())
|
||||
.or_else(|| app_server.remote_cwd_override());
|
||||
.or_else(|| app_server.remote_cwd_override())
|
||||
.map(Path::to_path_buf);
|
||||
let cwd_override = cwd_override.as_deref();
|
||||
let resume_cwd_mode = crate::session_resume::effective_resume_cwd_mode(
|
||||
self.local_settings.tui.resume_cwd,
|
||||
cwd_override,
|
||||
@@ -47,11 +49,17 @@ impl App {
|
||||
let resume_cwd = if self.app_server_target.uses_remote_workspace() {
|
||||
current_cwd.clone()
|
||||
} else {
|
||||
let history_cwd = if matches!(resume_cwd_mode, Some(ResumeCwdMode::Current)) {
|
||||
None
|
||||
} else {
|
||||
crate::session_resume::read_session_cwd(app_server, target_session.thread_id)
|
||||
.await
|
||||
.or_else(|| target_session.cwd.clone())
|
||||
};
|
||||
let outcome = crate::session_resume::resolve_cwd_for_resume_or_fork(
|
||||
tui,
|
||||
&self.config,
|
||||
self.state_db.as_deref(),
|
||||
target_session,
|
||||
history_cwd,
|
||||
CwdPromptAction::Resume,
|
||||
crate::session_resume::ResumeCwdContext {
|
||||
current_cwd: ¤t_cwd,
|
||||
|
||||
@@ -4354,18 +4354,6 @@ async fn inactive_thread_started_notification_initializes_replay_session() -> Re
|
||||
);
|
||||
|
||||
let rollout_path = temp_dir.path().join("agent-rollout.jsonl");
|
||||
let rollout = serde_json::json!({
|
||||
"timestamp": "t0",
|
||||
"type": "turn_context",
|
||||
"payload": {
|
||||
"cwd": test_path_buf("/tmp/agent"),
|
||||
"model": "gpt-agent",
|
||||
},
|
||||
});
|
||||
std::fs::write(
|
||||
&rollout_path,
|
||||
format!("{}\n", serde_json::to_string(&rollout)?),
|
||||
)?;
|
||||
app.enqueue_thread_notification(
|
||||
agent_thread_id,
|
||||
ServerNotification::ThreadStarted(ThreadStartedNotification {
|
||||
@@ -4385,7 +4373,7 @@ async fn inactive_thread_started_notification_initializes_replay_session() -> Re
|
||||
daybreak_enabled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "agent-provider".to_string(),
|
||||
model: None,
|
||||
model: Some("gpt-agent".to_string()),
|
||||
reasoning_effort: None,
|
||||
created_at: 1,
|
||||
updated_at: 2,
|
||||
@@ -4560,7 +4548,7 @@ async fn thread_read_session_state_does_not_reuse_primary_permission_profile() {
|
||||
daybreak_enabled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "read-provider".to_string(),
|
||||
model: None,
|
||||
model: Some("server-reported-model".to_string()),
|
||||
reasoning_effort: None,
|
||||
created_at: 1,
|
||||
updated_at: 2,
|
||||
@@ -4584,6 +4572,7 @@ async fn thread_read_session_state_does_not_reuse_primary_permission_profile() {
|
||||
.await;
|
||||
|
||||
assert_eq!(session.thread_id, read_thread_id);
|
||||
assert_eq!(session.model, "server-reported-model");
|
||||
assert_eq!(session.cwd.as_path(), test_path_buf("/tmp/read").as_path());
|
||||
assert_eq!(
|
||||
session.runtime_workspace_roots,
|
||||
@@ -4600,6 +4589,17 @@ async fn thread_read_session_state_does_not_reuse_primary_permission_profile() {
|
||||
"thread/read does not return fresh server permissions; the fallback profile must use the \
|
||||
active widget permissions rather than reusing the cached primary session profile"
|
||||
);
|
||||
|
||||
app.enqueue_primary_thread_session(session, Vec::new())
|
||||
.await
|
||||
.expect("switch to read thread");
|
||||
let header =
|
||||
lines_to_single_string(&app.clear_ui_header_lines_with_version(/*width*/ 80, "<VERSION>"));
|
||||
let model_line = header
|
||||
.lines()
|
||||
.find(|line| line.contains("model:"))
|
||||
.expect("rendered model line");
|
||||
assert_app_snapshot!("thread_read_model_after_switch", model_line);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -7263,6 +7263,7 @@ async fn remote_resume_current_cwd_rejection_snapshot() -> Result<()> {
|
||||
crate::resume_picker::SessionTarget {
|
||||
path: None,
|
||||
thread_id: ThreadId::new(),
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
},
|
||||
)
|
||||
@@ -7306,6 +7307,7 @@ async fn remote_exec_resume_current_cwd_is_rejected() -> Result<()> {
|
||||
crate::resume_picker::SessionTarget {
|
||||
path: None,
|
||||
thread_id: ThreadId::new(),
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
},
|
||||
)
|
||||
@@ -7344,6 +7346,7 @@ async fn in_app_resume_session_cwd_without_metadata_is_non_fatal() -> Result<()>
|
||||
crate::resume_picker::SessionTarget {
|
||||
path: None,
|
||||
thread_id: ThreadId::new(),
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
},
|
||||
)
|
||||
@@ -7425,6 +7428,7 @@ async fn remote_resume_keeps_server_only_cwd_out_of_local_config() -> Result<()>
|
||||
crate::resume_picker::SessionTarget {
|
||||
path: Some(rollout_path),
|
||||
thread_id: ThreadId::from_string(&thread_id)?,
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
},
|
||||
)
|
||||
@@ -7566,6 +7570,7 @@ async fn in_app_resume_uses_configured_or_explicit_cwd() -> Result<()> {
|
||||
crate::resume_picker::SessionTarget {
|
||||
path: Some(rollout_path),
|
||||
thread_id,
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
},
|
||||
)
|
||||
@@ -7671,6 +7676,7 @@ async fn remembered_current_cwd_stays_at_launch_across_in_app_resumes() -> Resul
|
||||
targets.push(crate::resume_picker::SessionTarget {
|
||||
path: Some(rollout_path),
|
||||
thread_id: ThreadId::from_string(&thread_id)?,
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -120,6 +120,7 @@ async fn same_thread_retry_keeps_subscription_and_restores_draft() -> Result<()>
|
||||
crate::resume_picker::SessionTarget {
|
||||
path,
|
||||
thread_id,
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
},
|
||||
)
|
||||
@@ -3844,6 +3845,7 @@ fn session_lifecycle_avoids_redundant_subagent_metadata_reads() -> Result<()> {
|
||||
crate::resume_picker::SessionTarget {
|
||||
path: Some(root_rollout_path),
|
||||
thread_id: root_thread_id,
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -148,6 +148,7 @@ fn startup_waiting_gate_is_only_for_fresh_or_exit_session_selection() {
|
||||
crate::resume_picker::SessionTarget {
|
||||
path: Some(PathBuf::from("/tmp/restore")),
|
||||
thread_id: ThreadId::new(),
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
}
|
||||
)),
|
||||
@@ -158,6 +159,7 @@ fn startup_waiting_gate_is_only_for_fresh_or_exit_session_selection() {
|
||||
crate::resume_picker::SessionTarget {
|
||||
path: Some(PathBuf::from("/tmp/fork")),
|
||||
thread_id: ThreadId::new(),
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
}
|
||||
)),
|
||||
@@ -170,11 +172,13 @@ fn startup_paused_goal_prompt_gate_is_only_for_quiet_resume() {
|
||||
let resume = SessionSelection::Resume(crate::resume_picker::SessionTarget {
|
||||
path: Some(PathBuf::from("/tmp/restore")),
|
||||
thread_id: ThreadId::new(),
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
});
|
||||
let fork = SessionSelection::Fork(crate::resume_picker::SessionTarget {
|
||||
path: Some(PathBuf::from("/tmp/fork")),
|
||||
thread_id: ThreadId::new(),
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
});
|
||||
let no_images: Vec<PathBuf> = Vec::new();
|
||||
@@ -244,6 +248,7 @@ fn startup_waiting_gate_not_applied_for_resume_or_fork_session_selection() {
|
||||
crate::resume_picker::SessionTarget {
|
||||
path: Some(PathBuf::from("/tmp/restore")),
|
||||
thread_id: ThreadId::new(),
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
},
|
||||
));
|
||||
@@ -258,6 +263,7 @@ fn startup_waiting_gate_not_applied_for_resume_or_fork_session_selection() {
|
||||
crate::resume_picker::SessionTarget {
|
||||
path: Some(PathBuf::from("/tmp/fork")),
|
||||
thread_id: ThreadId::new(),
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
},
|
||||
));
|
||||
@@ -1335,6 +1341,7 @@ async fn ignore_same_thread_resume_reports_noop_for_current_thread() {
|
||||
let ignored = app.ignore_same_thread_resume(&crate::resume_picker::SessionTarget {
|
||||
path: Some(test_path_buf("/tmp/project")),
|
||||
thread_id,
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
});
|
||||
|
||||
@@ -1360,6 +1367,7 @@ async fn ignore_same_thread_resume_allows_reattaching_displayed_inactive_thread(
|
||||
let ignored = app.ignore_same_thread_resume(&crate::resume_picker::SessionTarget {
|
||||
path: Some(test_path_buf("/tmp/project")),
|
||||
thread_id,
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
});
|
||||
|
||||
@@ -1386,6 +1394,7 @@ async fn ignore_same_thread_resume_allows_retrying_read_only_view() -> Result<()
|
||||
!app.ignore_same_thread_resume(&crate::resume_picker::SessionTarget {
|
||||
path: Some(test_path_buf("/tmp/project")),
|
||||
thread_id,
|
||||
cwd: None,
|
||||
history_mode: None,
|
||||
})
|
||||
);
|
||||
|
||||
@@ -8,7 +8,6 @@ use super::session_lifecycle::ThreadAttachPresentation;
|
||||
use super::*;
|
||||
use crate::app_event::ThreadTitleDestination;
|
||||
use crate::chatwidget::ThreadInputStateRestoreMode;
|
||||
use crate::session_resume::read_session_model;
|
||||
use codex_app_server_protocol::ThreadStartedNotification;
|
||||
use codex_app_server_protocol::TurnInterruptParams;
|
||||
use codex_app_server_protocol::TurnInterruptResponse;
|
||||
@@ -1252,10 +1251,8 @@ impl App {
|
||||
session
|
||||
.set_cwd_retargeting_implicit_runtime_workspace_root(notification.thread.cwd.clone());
|
||||
let rollout_path = notification.thread.path.clone();
|
||||
if let Some(model) =
|
||||
read_session_model(self.state_db.as_deref(), thread_id, rollout_path.as_deref()).await
|
||||
{
|
||||
session.model = model;
|
||||
if let Some(model) = ¬ification.thread.model {
|
||||
session.model = model.clone();
|
||||
} else if rollout_path.is_some() {
|
||||
session.model.clear();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use super::App;
|
||||
use crate::session_resume::read_session_model;
|
||||
use crate::session_state::ThreadSessionState;
|
||||
use codex_app_server_protocol::AskForApproval;
|
||||
use codex_app_server_protocol::Thread;
|
||||
@@ -80,7 +79,7 @@ impl App {
|
||||
let active_permission_profile = self.current_active_permission_profile();
|
||||
let mut session = if let Some(mut session) = self.primary_session_configured.clone() {
|
||||
if session.thread_id != thread_id {
|
||||
// `thread/read` does not include thread settings, so do not carry
|
||||
// `thread/read` does not include all thread settings, so do not carry
|
||||
// thread-scoped state from the currently active session.
|
||||
session.collaboration_mode = None;
|
||||
session.personality = None;
|
||||
@@ -120,10 +119,8 @@ impl App {
|
||||
session.active_permission_profile = active_permission_profile;
|
||||
session.instruction_source_paths = Vec::new();
|
||||
session.rollout_path = thread.path.clone();
|
||||
if let Some(model) =
|
||||
read_session_model(self.state_db.as_deref(), thread_id, thread.path.as_deref()).await
|
||||
{
|
||||
session.model = model;
|
||||
if let Some(model) = &thread.model {
|
||||
session.model = model.clone();
|
||||
} else if thread.path.is_some() {
|
||||
session.model.clear();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user