Skip to content

Commit bc8b25e

Browse files
efrazer-oaicopyberry
authored andcommitted
Add durable user-message queue dispatch (#37204)
## What changed - Add a storage-neutral queue extension for listing, adding, editing, reordering, deleting, and explicitly starting queued user messages. - Dispatch queued messages in FIFO order when a thread becomes idle after a completed turn, while leaving them queued after interruptions or failures. - Wait for user input to be persisted before removing its queue item, and report hook rejection, task termination, and persistence failures distinctly. - Snapshot local image and audio attachments into validated data URLs before storing them, enforce input limits, and emit `ThreadQueueChanged` events after mutations. ## Testing - Cover queue mutations, automatic and explicit dispatch, interruption and failure behavior, hook rejection, invalid records, input limits, and local attachment snapshotting. GitOrigin-RevId: 14f39d7c8cbaccb767a6da84b82cced0edfcb4b9
1 parent 70b4653 commit bc8b25e

42 files changed

Lines changed: 2114 additions & 140 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎codex-rs/Cargo.lock‎

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎codex-rs/Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ members = [
6161
"ext/items",
6262
"ext/memories",
6363
"ext/mcp",
64+
"ext/queue",
6465
"ext/skills",
6566
"ext/web-search",
6667
"external-agent-migration",
@@ -226,6 +227,7 @@ codex-model-provider = { path = "model-provider" }
226227
codex-process-hardening = { path = "process-hardening" }
227228
codex-protocol = { path = "protocol" }
228229
codex-prompts = { path = "prompts" }
230+
codex-queue-extension = { path = "ext/queue" }
229231
codex-responses-api-proxy = { path = "responses-api-proxy" }
230232
codex-response-debug-context = { path = "response-debug-context" }
231233
codex-rmcp-client = { path = "rmcp-client" }
Binary file not shown.

‎codex-rs/app-server/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ codex-mcp-extension = { workspace = true }
7474
codex-model-provider = { workspace = true }
7575
codex-models-manager = { workspace = true }
7676
codex-protocol = { workspace = true }
77+
codex-queue-extension = { workspace = true }
7778
codex-app-server-protocol = { workspace = true }
7879
codex-app-server-transport = { workspace = true }
7980
codex-feedback = { workspace = true }

‎codex-rs/app-server/src/bespoke_event_handling.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,7 @@ pub(crate) async fn apply_bespoke_event_handling(
11861186
))
11871187
.await;
11881188
}
1189+
EventMsg::ThreadQueueChanged(_) => {}
11891190
EventMsg::ThreadSettingsApplied(thread_settings_event) => {
11901191
let thread_settings =
11911192
thread_settings_from_core_snapshot(thread_settings_event.thread_settings);

‎codex-rs/app-server/src/extensions.rs‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use codex_protocol::error::CodexErr;
2626
use codex_protocol::protocol::Event;
2727
use codex_protocol::protocol::EventMsg;
2828
use codex_rollout::state_db::StateDbHandle;
29-
use codex_thread_store::ThreadStore;
29+
use codex_thread_store::QueueStore;
3030

3131
use crate::outgoing_message::OutgoingMessageSender;
3232
use crate::outgoing_message::ThreadScopedOutgoingMessageSender;
@@ -44,8 +44,8 @@ pub(crate) struct ThreadExtensionDependencies {
4444
pub(crate) executor_skill_provider: Arc<dyn codex_skills_extension::SkillProvider>,
4545
pub(crate) git_attribution_base_url: String,
4646
pub(crate) http_client_factory: HttpClientFactory,
47-
/// Process-scoped persistence backend for extensions that need stored thread history.
48-
pub(crate) thread_store: Arc<dyn ThreadStore>,
47+
/// Process-scoped persistence backend for queued user messages.
48+
pub(crate) queue_store: Option<Arc<dyn QueueStore>>,
4949
}
5050

5151
pub(crate) fn thread_extensions<S>(
@@ -66,9 +66,17 @@ where
6666
executor_skill_provider,
6767
git_attribution_base_url,
6868
http_client_factory,
69-
thread_store: _thread_store,
69+
queue_store,
7070
} = dependencies;
71-
let mut builder = ExtensionRegistryBuilder::<Config>::with_event_sink(event_sink);
71+
let mut builder = ExtensionRegistryBuilder::<Config>::with_event_sink(Arc::clone(&event_sink));
72+
if let Some(queue) = queue_store {
73+
let queue_service = Arc::new(codex_queue_extension::QueuedItemService::new(
74+
queue,
75+
thread_manager.clone(),
76+
event_sink,
77+
));
78+
codex_queue_extension::install(&mut builder, queue_service);
79+
}
7280
if let Some(state_db) = state_db {
7381
codex_goal_extension::install_with_backend(
7482
&mut builder,

‎codex-rs/app-server/src/mcp_refresh.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ enabled = false
339339
executor_skill_provider: Arc::clone(&executor_skill_provider),
340340
git_attribution_base_url: good_config.chatgpt_base_url.clone(),
341341
http_client_factory: good_config.http_client_factory(),
342-
thread_store: Arc::clone(&thread_store),
342+
queue_store: None,
343343
},
344344
),
345345
Arc::new(CodexHomeUserInstructionsProvider::new(

‎codex-rs/app-server/src/message_processor.rs‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ use codex_chatgpt::workspace_settings;
6666
use codex_code_mode::CodeModeSessionProvider;
6767
use codex_core::ThreadManager;
6868
use codex_core::config::Config;
69+
use codex_core::config::ThreadStoreConfig;
6970
use codex_exec_server::EnvironmentManager;
7071
use codex_feedback::CodexFeedback;
7172
use codex_goal_extension::GoalService;
@@ -77,6 +78,8 @@ use codex_protocol::protocol::SessionSource;
7778
use codex_protocol::protocol::W3cTraceContext;
7879
use codex_rollout::StateDbHandle;
7980
use codex_state::log_db::LogDbLayer;
81+
use codex_thread_store::LocalQueueStore;
82+
use codex_thread_store::QueueStore;
8083
use tokio::sync::Mutex;
8184
use tokio::sync::Semaphore;
8285
use tokio::sync::broadcast;
@@ -247,6 +250,14 @@ impl MessageProcessor {
247250
// affect per-thread behavior, but they must not move newly started,
248251
// resumed, or forked threads to a different persistence backend/root.
249252
let thread_store = codex_core::thread_store_from_config(config.as_ref(), state_db.clone());
253+
// Queue persistence requires SQLite, so in-memory thread stores and
254+
// app servers without a state database do not have a queue backend.
255+
let queue_store: Option<Arc<dyn QueueStore>> = match &config.experimental_thread_store {
256+
ThreadStoreConfig::Local => state_db.as_ref().map(|state_db| {
257+
Arc::new(LocalQueueStore::new(Arc::clone(state_db))) as Arc<dyn QueueStore>
258+
}),
259+
ThreadStoreConfig::InMemory { .. } => None,
260+
};
250261
let environment_manager_for_requests = Arc::clone(&environment_manager);
251262
let environment_manager_for_extensions = Arc::clone(&environment_manager);
252263
let restriction_product = session_source.restriction_product();
@@ -281,7 +292,7 @@ impl MessageProcessor {
281292
executor_skill_provider: Arc::clone(&executor_skill_provider),
282293
git_attribution_base_url: config.chatgpt_base_url.clone(),
283294
http_client_factory: config.http_client_factory(),
284-
thread_store: Arc::clone(&thread_store),
295+
queue_store,
285296
},
286297
),
287298
Arc::new(CodexHomeUserInstructionsProvider::new(

‎codex-rs/app-server/src/request_processors/thread_goal_processor.rs‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,11 @@ impl ThreadGoalRequestProcessor {
6565
.map(|()| None)
6666
}
6767

68-
pub(crate) async fn emit_resume_goal_snapshot_and_continue(
69-
&self,
70-
thread_id: ThreadId,
71-
thread: &CodexThread,
72-
) {
68+
pub(crate) async fn emit_resume_goal_snapshot(&self, thread_id: ThreadId) {
7369
if !self.config.features.enabled(Feature::Goals) {
7470
return;
7571
}
7672
self.emit_thread_goal_snapshot(thread_id).await;
77-
// App-server owns resume response and snapshot ordering, so wait until
78-
// those are sent before letting extensions react to the idle thread.
79-
thread.emit_thread_idle_lifecycle_if_idle().await;
8073
}
8174

8275
pub(crate) async fn pending_resume_goal_state(

‎codex-rs/app-server/src/request_processors/thread_lifecycle.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::*;
22
use crate::extensions::send_thread_warning;
3+
use codex_extension_api::ThreadIdleCause;
34
use codex_protocol::config_types::MultiAgentMode;
45

56
pub(super) const THREAD_UNLOADING_DELAY: Duration = Duration::from_secs(30 * 60);
@@ -750,9 +751,9 @@ pub(super) async fn handle_pending_thread_resume_request(
750751
.await;
751752
// App-server owns resume response and snapshot ordering, so wait until
752753
// replay completes before letting extensions react to the idle thread.
753-
if pending.emit_thread_goal_update {
754-
conversation.emit_thread_idle_lifecycle_if_idle().await;
755-
}
754+
conversation
755+
.emit_thread_idle_lifecycle_if_idle(ThreadIdleCause::Completed)
756+
.await;
756757
}
757758

758759
pub(super) async fn send_thread_goal_snapshot_notification(

0 commit comments

Comments
 (0)