From bd66ec7c1588992a70d8050ad97826df123c028d Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Sun, 12 Apr 2026 19:51:14 -0700 Subject: [PATCH] codex: address PR review feedback (#17580) --- codex-rs/cli/src/queue_cmd.rs | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/codex-rs/cli/src/queue_cmd.rs b/codex-rs/cli/src/queue_cmd.rs index bad4d2940b..e5c87c8809 100644 --- a/codex-rs/cli/src/queue_cmd.rs +++ b/codex-rs/cli/src/queue_cmd.rs @@ -45,6 +45,7 @@ pub(crate) async fn run_queue_command( let thread_id = resolve_queue_thread_id(config.codex_home.as_path(), &cmd.thread).await?; let state_db = StateRuntime::init(config.sqlite_home.clone(), config.model_provider_id.clone()).await?; + ensure_queue_thread_belongs_to_state_db(&state_db, &thread_id).await?; let delivery = TimerDelivery::AfterTurn; let message_params = codex_state::ExternalMessageCreateParams::new( @@ -71,6 +72,21 @@ pub(crate) async fn run_queue_command( Ok(()) } +async fn ensure_queue_thread_belongs_to_state_db( + state_db: &StateRuntime, + thread_id: &str, +) -> anyhow::Result<()> { + let thread_id = ThreadId::from_string(thread_id) + .map_err(|err| anyhow::anyhow!("invalid resolved thread id `{thread_id}`: {err}"))?; + if state_db.get_thread(thread_id).await?.is_some() { + return Ok(()); + } + + anyhow::bail!( + "thread `{thread_id}` is not present in the configured sqlite state database; run codex queue with the profile that owns the thread" + ); +} + async fn remove_queued_message_if_thread_missing( codex_home: &Path, state_db: &StateRuntime, @@ -197,6 +213,29 @@ mod tests { .expect("queued messages feature should permit immediate queue command"); } + #[tokio::test] + async fn queue_requires_thread_in_configured_state_db() { + let sqlite_home = TempDir::new().expect("sqlite home tempdir"); + let runtime = StateRuntime::init( + sqlite_home.path().to_path_buf(), + "test-provider".to_string(), + ) + .await + .expect("initialize state runtime"); + let thread_id = ThreadId::new().to_string(); + + let err = ensure_queue_thread_belongs_to_state_db(&runtime, &thread_id) + .await + .expect_err("missing state thread should fail"); + + assert_eq!( + err.to_string(), + format!( + "thread `{thread_id}` is not present in the configured sqlite state database; run codex queue with the profile that owns the thread" + ) + ); + } + #[tokio::test] async fn queue_thread_resolves_thread_name() { let temp = TempDir::new().expect("tempdir");