mirror of
https://github.com/openai/codex.git
synced 2026-12-04 00:51:02 +00:00
Simplify queued user message admission (#38092)
## What changed - Resolve user message admission when Core accepts the input as a new turn or a steer, without waiting for rollout persistence. - Remove persistence- and hook-specific admission errors and task bookkeeping. - Delete queued messages after Core accepts them for turn processing, including messages subsequently stopped by a prompt hook. ## Testing - Update concurrent admission and queue service tests for acceptance-based admission. GitOrigin-RevId: 7dcc311cfecd3d710733b420f2add546edb86153
This commit is contained in:
@@ -6,10 +6,8 @@ use std::sync::Weak;
|
||||
|
||||
use codex_core::CodexThread;
|
||||
use codex_core::ThreadManager;
|
||||
use codex_core::TryStartTurnIfIdleRejectionReason;
|
||||
use codex_core::TurnInput;
|
||||
use codex_core::UserMessageAdmission;
|
||||
use codex_core::UserMessageAdmissionError;
|
||||
use codex_extension_api::ExtensionEventSink;
|
||||
use codex_extension_api::ExtensionFuture;
|
||||
use codex_extension_api::ThreadIdleCause;
|
||||
@@ -191,7 +189,8 @@ impl QueuedItemService {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Starts or steers the exact queued message and removes it after admission.
|
||||
/// Starts or steers the exact queued message and removes it after Core
|
||||
/// accepts the input for turn processing.
|
||||
pub async fn start(
|
||||
&self,
|
||||
thread: &CodexThread,
|
||||
@@ -212,7 +211,7 @@ impl QueuedItemService {
|
||||
return Err(QueueServiceError::InvalidInput);
|
||||
};
|
||||
let admission = thread
|
||||
.submit_user_input_and_wait_for_persisted_admission(
|
||||
.submit_user_input_and_wait_for_admission(
|
||||
Op::UserInput {
|
||||
items: content,
|
||||
final_output_json_schema: None,
|
||||
@@ -223,16 +222,7 @@ impl QueuedItemService {
|
||||
trace,
|
||||
client_id,
|
||||
)
|
||||
.await;
|
||||
let admission = match admission {
|
||||
Ok(admission) => admission,
|
||||
Err(error) => {
|
||||
if matches!(&error, UserMessageAdmissionError::RejectedByHook) {
|
||||
self.delete_locked(thread_id, queued_item_id).await?;
|
||||
}
|
||||
return Err(QueueServiceError::Admission(error.into()));
|
||||
}
|
||||
};
|
||||
.await?;
|
||||
self.delete_locked(thread_id, queued_item_id).await?;
|
||||
Ok(admission)
|
||||
}
|
||||
@@ -272,10 +262,6 @@ impl QueuedItemService {
|
||||
}
|
||||
|
||||
if let Err(error) = thread.try_start_turn_if_idle(vec![input]).await {
|
||||
if error.reason() == TryStartTurnIfIdleRejectionReason::RejectedByHook {
|
||||
self.delete_locked(thread_id, queued_item_id).await?;
|
||||
continue;
|
||||
}
|
||||
tracing::warn!(
|
||||
%thread_id,
|
||||
%queued_item_id,
|
||||
|
||||
@@ -453,21 +453,16 @@ async fn rejected_queue_messages_are_consumed_without_retrying_or_blocking_follo
|
||||
assert!(queue.list(thread_id).await?.is_empty());
|
||||
|
||||
let rejected = staging.enqueue(thread_id, user_input("blocked")).await?;
|
||||
let error = tokio::time::timeout(
|
||||
let admission = tokio::time::timeout(
|
||||
Duration::from_secs(10),
|
||||
queue.start(test.codex.as_ref(), rejected.id, /*trace*/ None),
|
||||
)
|
||||
.await?
|
||||
.expect_err("explicitly started blocked input should be rejected");
|
||||
assert!(matches!(
|
||||
error,
|
||||
QueueServiceError::Admission(error)
|
||||
if matches!(
|
||||
error.details(),
|
||||
codex_protocol::error::CodexErrorDetails::InvalidRequest(message)
|
||||
if message == "user message was rejected by a hook"
|
||||
)
|
||||
));
|
||||
.await??;
|
||||
assert!(matches!(admission, UserMessageAdmission::Started { .. }));
|
||||
wait_for_event_match(test.codex.as_ref(), |event| {
|
||||
matches!(event, EventMsg::TurnComplete(_)).then_some(())
|
||||
})
|
||||
.await;
|
||||
assert!(queue.list(thread_id).await?.is_empty());
|
||||
let hook_log = std::fs::read_to_string(test.codex_home_path().join("queue_prompt_hook.log"))?;
|
||||
assert_eq!(
|
||||
@@ -732,7 +727,7 @@ async fn invalid_head_is_skipped_and_a_live_user_turn_is_accepted() -> anyhow::R
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn resumed_idle_dispatches_input_persisted_without_a_loaded_manager() -> anyhow::Result<()> {
|
||||
async fn resumed_idle_dispatches_input_without_a_loaded_manager() -> anyhow::Result<()> {
|
||||
let server = start_mock_server().await;
|
||||
responses::mount_sse_once(&server, responses::sse_completed("resumed-turn")).await;
|
||||
let test = test_codex().build_with_auto_env(&server).await?;
|
||||
|
||||
Reference in New Issue
Block a user