From 2c5eeb6b1fb32776b9c4d3d3ff62b55aa3c464a3 Mon Sep 17 00:00:00 2001 From: jif-oai Date: Wed, 11 Feb 2026 10:23:18 +0000 Subject: [PATCH] fix: flaky test (#11428) stage1_concurrent_claims_respect_running_cap was flaky due to SQLite lock contention, not cap logic correctness. The claim flow used deferred transactions (BEGIN) with read-then-write behavior, which can fail under concurrency with SQLITE_BUSY_SNAPSHOT/database is locked when upgrading a read transaction to a write transaction. We fixed this by using BEGIN IMMEDIATE for stage1 and phase2 claim paths, so lock acquisition happens up front and contenders serialize cleanly instead of failing during upgrade. After the change, codex-state tests pass and stress reruns of the flaky path no longer reproduced the failure. --- codex-rs/state/src/runtime.rs | 1 - codex-rs/state/src/runtime/memories.rs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/codex-rs/state/src/runtime.rs b/codex-rs/state/src/runtime.rs index dcb472022..541e02ad3 100644 --- a/codex-rs/state/src/runtime.rs +++ b/codex-rs/state/src/runtime.rs @@ -1272,7 +1272,6 @@ WHERE id = 1 } #[tokio::test] - #[ignore = "TODO(jif): flaky"] async fn stage1_concurrent_claims_respect_running_cap() { let codex_home = unique_temp_dir(); let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string(), None) diff --git a/codex-rs/state/src/runtime/memories.rs b/codex-rs/state/src/runtime/memories.rs index e32162221..def408c6e 100644 --- a/codex-rs/state/src/runtime/memories.rs +++ b/codex-rs/state/src/runtime/memories.rs @@ -174,7 +174,7 @@ LIMIT ? let thread_id = thread_id.to_string(); let worker_id = worker_id.to_string(); - let mut tx = self.pool.begin().await?; + let mut tx = self.pool.begin_with("BEGIN IMMEDIATE").await?; let existing_output = sqlx::query( r#" @@ -424,7 +424,7 @@ WHERE kind = ? AND job_key = ? let ownership_token = Uuid::new_v4().to_string(); let worker_id = worker_id.to_string(); - let mut tx = self.pool.begin().await?; + let mut tx = self.pool.begin_with("BEGIN IMMEDIATE").await?; let existing_job = sqlx::query( r#"