mirror of
https://github.com/openai/codex.git
synced 2026-11-28 23:34:06 +00:00
Restore thread cwd from owned settings snapshots (#41567)
## Why Resuming a thread without an explicit `cwd` should restore that thread's latest retained setting. Forked history can contain settings copied from another thread, while compaction can move the latest setting outside the replay window. ## What changed - Record the owning thread ID on new settings snapshots and only use snapshots owned by the resumed thread when restoring `cwd`. Older snapshots without an owner remain readable but do not override the startup `cwd`. - Checkpoint the current settings after compaction and serialize checkpoints with settings updates so the retained history contains an accepted, current snapshot. - Cover resume behavior across compaction, forks, reverts, legacy histories, and concurrent settings updates. GitOrigin-RevId: 1efc9cf55472d6b88c465c4efe44672a232dbf64
This commit is contained in:
1 parent
4210c08def
commit
f5636bb733
20 files changed
+462
-35
No files matched your search
@@ -28,6 +28,7 @@ fn settings_item(
|
||||
) -> RolloutItem {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(
|
||||
ThreadSettingsAppliedEvent {
|
||||
thread_id: None,
|
||||
thread_settings: ThreadSettingsSnapshot {
|
||||
model: "gpt-5".to_string(),
|
||||
model_provider_id: "openai".to_string(),
|
||||
|
||||
@@ -176,7 +176,7 @@ impl ThreadGoalRequestProcessor {
|
||||
// rollout. Once materialized, normal settings updates own this event.
|
||||
let persisted_settings = thread.thread_settings_snapshot().await;
|
||||
let items = [
|
||||
thread_settings_applied_item(persisted_settings.clone()),
|
||||
thread_settings_applied_item(thread_id, persisted_settings.clone()),
|
||||
outcome.thread_goal_updated_item(),
|
||||
];
|
||||
match thread.append_rollout_items(&items).await {
|
||||
@@ -189,6 +189,7 @@ impl ThreadGoalRequestProcessor {
|
||||
} else {
|
||||
thread
|
||||
.append_rollout_items(&[thread_settings_applied_item(
|
||||
thread_id,
|
||||
current_settings,
|
||||
)])
|
||||
.await
|
||||
@@ -480,9 +481,15 @@ impl ThreadGoalRequestProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
fn thread_settings_applied_item(thread_settings: ThreadSettingsSnapshot) -> RolloutItem {
|
||||
fn thread_settings_applied_item(
|
||||
thread_id: ThreadId,
|
||||
thread_settings: ThreadSettingsSnapshot,
|
||||
) -> RolloutItem {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(
|
||||
ThreadSettingsAppliedEvent { thread_settings },
|
||||
ThreadSettingsAppliedEvent {
|
||||
thread_id: Some(thread_id),
|
||||
thread_settings,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@@ -3739,7 +3739,21 @@ impl ThreadRequestProcessor {
|
||||
};
|
||||
}
|
||||
|
||||
let history_cwd = thread_history.session_cwd();
|
||||
// Copied or referenced history can contain another thread's settings. Only snapshots
|
||||
// explicitly owned by this thread can override its startup cwd.
|
||||
let history_cwd = if let InitialHistory::Resumed(resumed) = &thread_history {
|
||||
resumed.history.iter().rev().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event))
|
||||
if event.thread_id == Some(resumed.conversation_id) =>
|
||||
{
|
||||
Some(event.thread_settings.cwd.to_path_buf())
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let history_cwd = history_cwd.or_else(|| thread_history.session_cwd());
|
||||
let runtime_workspace_roots = runtime_workspace_roots.map(resolve_runtime_workspace_roots);
|
||||
let mut typesafe_overrides = self.build_thread_config_overrides(
|
||||
model,
|
||||
|
||||
Reference in new issue
Block a user