mirror of
https://github.com/openai/codex.git
synced 2026-11-24 15:21:20 +00:00
Restore saved threads when the managed daemon restarts (#44314)
## Why Saved threads need to resume after a managed daemon restart so active goals can continue without waiting for a client to reconnect. ## What changed - Consume the recovery snapshot at startup and restore threads in the background through the shared cold-resume path. - Trigger idle lifecycle work without attaching a client subscription, and leave already-loaded threads untouched. - Continue recovery after individual thread failures and abort background recovery during shutdown. ## Testing Extend the daemon restart integration test to verify goal continuation before client reconnection, restored conversation history and tools, idle-thread restoration, and recovery snapshot consumption. Include malformed snapshots and an invalid thread ID. GitOrigin-RevId: 90e7b8f74ddc0ae327bacde1b2108b9749c65f2a
This commit is contained in:
1 parent
434efa95e6
commit
e1b23086ac
6 files changed
+252
-96
No files matched your search
@@ -985,14 +985,22 @@ pub async fn run_main_with_transport_options(
|
||||
let mut remote_control_status = remote_control_status_rx.borrow().clone();
|
||||
let transport_shutdown_token = transport_shutdown_token.clone();
|
||||
async move {
|
||||
// This process must never hand an earlier generation's candidates to
|
||||
// its successor, including when the snapshot writer cannot start.
|
||||
if managed_daemon
|
||||
&& let Err(err) = tokio::fs::remove_file(&recovery_file).await
|
||||
&& err.kind() != std::io::ErrorKind::NotFound
|
||||
{
|
||||
warn!("failed to clear stale daemon recovery file: {err}");
|
||||
}
|
||||
let recovery_task = if managed_daemon {
|
||||
match daemon_thread_recovery::start_recovery(
|
||||
recovery_file.clone(),
|
||||
Arc::clone(&processor),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(task) => Some(task),
|
||||
Err(err) => {
|
||||
warn!("failed to consume daemon recovery snapshot: {err}");
|
||||
None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut listen_for_threads = true;
|
||||
// Keep force signals and daemon control events responsive while saving.
|
||||
let mut snapshot = Box::pin(async {
|
||||
@@ -1016,6 +1024,9 @@ pub async fn run_main_with_transport_options(
|
||||
ShutdownAction::Finish
|
||||
);
|
||||
if ready_to_exit {
|
||||
if let Some(task) = &recovery_task {
|
||||
task.abort();
|
||||
}
|
||||
let finished = snapshot_finished || shutdown_state.forced();
|
||||
if finished {
|
||||
transport_shutdown_token.cancel();
|
||||
@@ -1275,6 +1286,9 @@ pub async fn run_main_with_transport_options(
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(task) = recovery_task {
|
||||
task.abort();
|
||||
}
|
||||
drop(snapshot);
|
||||
if !shutdown_state.forced() {
|
||||
futures::future::join_all(connections.iter().map(
|
||||
|
||||
Reference in new issue
Block a user