Add opt-in code-mode yielding on new user input (#48135)

## Why

User input queued during a long-running code-mode `exec` or `wait` can remain pending until the call returns. Allow these calls to yield early so Codex can receive the new input while the cell continues running.

## What changed

- Add the `instant_interrupt` feature flag, disabled by default.
- Watch queued user input for each sampling request and pass a shared preemption signal to code-mode `exec` and `wait` calls, including calls received later in the same response.
- Yield running cell IDs without stopping the cells, allowing subsequent `wait` calls to collect their results.

## Testing

Add integration coverage for enabled and disabled behavior, repeated steering during `exec` and `wait`, input deferred during compaction, and later calls in the same response. Verify that direct tool results and queued user messages are preserved, and add a scenario snapshot showing continuation after a cell yields.

GitOrigin-RevId: e33466a980d98e113bfb6c6a45c59de0cc7b3c1d
This commit is contained in:
pakrym-oai
2026-09-25 16:28:36 +00:00
committed by copyberry
parent d9275a63ed
commit 1bf73324ca
13 changed files with 1011 additions and 6 deletions
+4 -2
View File
@@ -133,21 +133,23 @@ impl CodeModeService {
request
.yield_time_ms
.get_or_insert(self.default_exec_yield_time_ms);
let preempt = step_context.preempt.clone();
let delegate = Arc::new(CodeModeCellDelegate {
broker: Arc::clone(&self.dispatch_broker),
step_context,
});
self.session()
.await?
.execute(request, delegate, /*preempt*/ None)
.execute(request, delegate, preempt)
.await
}
pub(crate) async fn wait(
&self,
request: codex_code_mode::WaitRequest,
preempt: Option<CancellationToken>,
) -> Result<codex_code_mode::WaitOutcome, String> {
self.session().await?.wait(request, /*preempt*/ None).await
self.session().await?.wait(request, preempt).await
}
pub(crate) async fn terminate(
@@ -134,10 +134,13 @@ impl CodeModeWaitHandler {
exec.session
.services
.code_mode_service
.wait(codex_code_mode::WaitRequest {
cell_id,
yield_time_ms: args.yield_time_ms,
})
.wait(
codex_code_mode::WaitRequest {
cell_id,
yield_time_ms: args.yield_time_ms,
},
step_context.preempt.clone(),
)
.await
}
.map_err(|error| {