From 74ec7c1be5b9977ef358747481a10e1edf601977 Mon Sep 17 00:00:00 2001 From: Charles Cunningham Date: Tue, 24 Mar 2026 15:06:36 -0700 Subject: [PATCH] Make app-server state DB init atomic Co-authored-by: Codex --- .../app-server/src/codex_message_processor.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/codex-rs/app-server/src/codex_message_processor.rs b/codex-rs/app-server/src/codex_message_processor.rs index d283e47e78..00f855156c 100644 --- a/codex-rs/app-server/src/codex_message_processor.rs +++ b/codex-rs/app-server/src/codex_message_processor.rs @@ -486,18 +486,12 @@ impl CodexMessageProcessor { } async fn app_server_state_db(&self) -> Option { - if let Some(state_db_ctx) = self.app_server_state_db_cell.get() { - return Some(state_db_ctx.clone()); - } - - let state_db_ctx = get_state_db(&self.config).await?; - let _ = self.app_server_state_db_cell.set(state_db_ctx.clone()); - Some( - self.app_server_state_db_cell - .get() - .cloned() - .unwrap_or(state_db_ctx), - ) + let config = Arc::clone(&self.config); + self.app_server_state_db_cell + .get_or_try_init(|| async move { get_state_db(&config).await.ok_or(()) }) + .await + .ok() + .cloned() } async fn find_thread_path_by_id_with_state_db(