code-mode: expose create and observe operations

This commit is contained in:
Channing Conger
2026-06-22 08:20:43 +00:00
parent bc923b0be6
commit 96581e99cf
20 changed files with 1104 additions and 479 deletions
@@ -1,5 +1,5 @@
use codex_code_mode_protocol::CodeModeToolKind;
use codex_code_mode_protocol::ExecuteRequest;
use codex_code_mode_protocol::CreateCellRequest;
use codex_code_mode_protocol::FunctionCallOutputContentItem;
use codex_code_mode_protocol::ImageDetail;
use codex_code_mode_protocol::ToolDefinition;
@@ -10,8 +10,8 @@ use crate::session_runtime::ImageDetail as CellImageDetail;
use crate::session_runtime::OutputItem as CellOutputItem;
use crate::session_runtime::ToolKind as CellToolKind;
pub(super) fn runtime_request(request: CellRequest) -> ExecuteRequest {
ExecuteRequest {
pub(super) fn runtime_request(request: CellRequest) -> CreateCellRequest {
CreateCellRequest {
tool_call_id: request.tool_call_id,
enabled_tools: request
.enabled_tools
@@ -32,8 +32,6 @@ pub(super) fn runtime_request(request: CellRequest) -> ExecuteRequest {
})
.collect(),
source: request.source,
yield_time_ms: None,
max_output_tokens: None,
}
}
+2 -4
View File
@@ -5,7 +5,7 @@ use std::sync::atomic::Ordering;
use std::sync::mpsc as std_mpsc;
use std::time::Duration;
use codex_code_mode_protocol::ExecuteRequest;
use codex_code_mode_protocol::CreateCellRequest;
use codex_code_mode_protocol::FunctionCallOutputContentItem;
use pretty_assertions::assert_eq;
use serde_json::Value as JsonValue;
@@ -120,12 +120,10 @@ fn spawn_cell_actor_harness_with_policy<H: CellHost>(
let (runtime_event_tx, runtime_event_rx) = mpsc::unbounded_channel();
let (runtime_tx, runtime_pause_tx, runtime_terminate_handle) = spawn_runtime(
HashMap::new(),
ExecuteRequest {
CreateCellRequest {
tool_call_id: "call-1".to_string(),
enabled_tools: Vec::new(),
source: "await new Promise(() => {});".to_string(),
yield_time_ms: None,
max_output_tokens: None,
},
runtime_event_tx,
PendingRuntimeMode::PauseUntilResumed,
@@ -20,6 +20,7 @@ use crate::session_runtime::ToolName;
pub(crate) type CellEventFuture =
Pin<Box<dyn Future<Output = Result<CellEvent, CellError>> + Send + 'static>>;
#[allow(dead_code)]
pub(crate) type ResumeFuture =
Pin<Box<dyn Future<Output = Result<ResumeOutcome, CellError>> + Send + 'static>>;
@@ -121,6 +122,7 @@ impl CellHandle {
response_event(response_rx)
}
#[allow(dead_code)]
pub(crate) fn resume(&self, generation: PendingGeneration) -> ResumeFuture {
if !self.state.accepting_observations() {
return closed_resume();
@@ -503,6 +505,7 @@ pub(super) enum CellCommand {
mode: ObserveMode,
response_tx: oneshot::Sender<Result<CellEvent, CellError>>,
},
#[allow(dead_code)]
Resume {
generation: PendingGeneration,
response_tx: oneshot::Sender<Result<ResumeOutcome, CellError>>,
@@ -521,6 +524,7 @@ fn closed_event() -> CellEventFuture {
Box::pin(async { Err(CellError::Closed) })
}
#[allow(dead_code)]
fn closed_resume() -> ResumeFuture {
Box::pin(async { Err(CellError::Closed) })
}
+5 -7
View File
@@ -10,8 +10,8 @@ use std::sync::mpsc as std_mpsc;
use std::thread;
use codex_code_mode_protocol::CodeModeToolKind;
use codex_code_mode_protocol::CreateCellRequest;
use codex_code_mode_protocol::EnabledToolMetadata;
use codex_code_mode_protocol::ExecuteRequest;
use codex_code_mode_protocol::FunctionCallOutputContentItem;
use codex_code_mode_protocol::enabled_tool_metadata;
use codex_protocol::ToolName;
@@ -67,7 +67,7 @@ pub(crate) enum RuntimeEvent {
pub(crate) fn spawn_runtime(
stored_values: HashMap<String, JsonValue>,
request: ExecuteRequest,
request: CreateCellRequest,
event_tx: mpsc::UnboundedSender<RuntimeEvent>,
pending_mode: PendingRuntimeMode,
) -> Result<
@@ -341,7 +341,7 @@ mod tests {
use pretty_assertions::assert_eq;
use tokio::sync::mpsc;
use super::ExecuteRequest;
use super::CreateCellRequest;
use super::PendingRuntimeMode;
use super::RuntimeCommand;
use super::RuntimeControlCommand;
@@ -349,13 +349,11 @@ mod tests {
use super::spawn_runtime;
use crate::FunctionCallOutputContentItem;
fn execute_request(source: &str) -> ExecuteRequest {
ExecuteRequest {
fn execute_request(source: &str) -> CreateCellRequest {
CreateCellRequest {
tool_call_id: "call_1".to_string(),
enabled_tools: Vec::new(),
source: source.to_string(),
yield_time_ms: Some(1),
max_output_tokens: None,
}
}
+111 -90
View File
@@ -10,27 +10,46 @@ use codex_code_mode_protocol::CodeModeSessionProvider;
use codex_code_mode_protocol::CodeModeSessionProviderFuture;
use codex_code_mode_protocol::CodeModeSessionResultFuture;
use codex_code_mode_protocol::CodeModeToolKind;
use codex_code_mode_protocol::DEFAULT_EXEC_YIELD_TIME_MS;
use codex_code_mode_protocol::ExecuteRequest;
use codex_code_mode_protocol::ExecuteToPendingOutcome;
use codex_code_mode_protocol::CreateCellRequest;
use codex_code_mode_protocol::FunctionCallOutputContentItem;
use codex_code_mode_protocol::ImageDetail;
use codex_code_mode_protocol::NotificationFuture;
use codex_code_mode_protocol::ObserveOutcome;
use codex_code_mode_protocol::ObserveRequest;
#[cfg(test)]
use codex_code_mode_protocol::RuntimeResponse;
use codex_code_mode_protocol::StartedCell;
use codex_code_mode_protocol::TerminateOutcome;
use codex_code_mode_protocol::ToolInvocationFuture;
use codex_code_mode_protocol::WaitOutcome;
use codex_code_mode_protocol::WaitRequest;
use codex_code_mode_protocol::WaitToPendingOutcome;
use codex_code_mode_protocol::WaitToPendingRequest;
use serde_json::Value as JsonValue;
use tokio::sync::Mutex;
use tokio::sync::oneshot;
use tokio_util::sync::CancellationToken;
use crate::session_runtime as runtime;
use crate::session_runtime::SessionRuntime;
#[cfg(test)]
struct ObserveToPendingRequest {
cell_id: CellId,
}
#[cfg(test)]
#[derive(Debug, PartialEq)]
enum PendingOutcome {
Pending {
cell_id: CellId,
content_items: Vec<FunctionCallOutputContentItem>,
pending_tool_call_ids: Vec<String>,
},
Completed(RuntimeResponse),
}
#[cfg(test)]
#[derive(Debug, PartialEq)]
enum ObserveToPendingOutcome {
LiveCell(PendingOutcome),
MissingCell(RuntimeResponse),
}
pub struct NoopCodeModeSessionDelegate;
impl CodeModeSessionDelegate for NoopCodeModeSessionDelegate {
@@ -91,60 +110,34 @@ impl CodeModeService {
}
}
pub async fn execute(&self, request: ExecuteRequest) -> Result<StartedCell, String> {
let yield_time_ms = request.yield_time_ms.unwrap_or(DEFAULT_EXEC_YIELD_TIME_MS);
pub async fn create_cell(&self, request: CreateCellRequest) -> Result<CellId, String> {
let cell = self
.runtime
.create_cell(runtime_request(request))
.await
.map_err(|error| error.to_string())?;
let pending_event = self
.runtime
.begin_wait(&cell, Duration::from_millis(yield_time_ms))
.await
.map_err(|error| error.to_string())?;
let cell_id = protocol_cell_id(cell.id());
let response_cell_id = cell_id.clone();
let (response_tx, response_rx) = oneshot::channel();
tokio::spawn(async move {
let response = pending_event
.event()
.await
.map_err(|error| error.to_string())
.and_then(|event| runtime_response(&response_cell_id, event));
let _ = response_tx.send(response);
});
Ok(StartedCell::from_result_receiver(cell_id, response_rx))
Ok(protocol_cell_id(cell.id()))
}
pub async fn execute_to_pending(
&self,
request: ExecuteRequest,
) -> Result<ExecuteToPendingOutcome, String> {
#[cfg(test)]
async fn create_pausable_cell(&self, request: CreateCellRequest) -> Result<CellId, String> {
let cell = self
.runtime
.create_pausable_cell(runtime_request(request))
.await
.map_err(|error| error.to_string())?;
let cell_id = protocol_cell_id(cell.id());
let event = self
.runtime
.wait_to_pending(&cell)
.await
.map_err(|error| error.to_string())?;
self.record_pending_generation(cell.id(), &event).await;
pending_outcome(&cell_id, event)
Ok(protocol_cell_id(cell.id()))
}
pub async fn wait(&self, request: WaitRequest) -> Result<WaitOutcome, String> {
self.begin_wait(request).await.await
pub async fn observe(&self, request: ObserveRequest) -> Result<ObserveOutcome, String> {
self.begin_observe(request).await.await
}
async fn begin_wait(
async fn begin_observe(
&self,
request: WaitRequest,
) -> CodeModeSessionResultFuture<'static, WaitOutcome> {
let WaitRequest {
request: ObserveRequest,
) -> CodeModeSessionResultFuture<'static, ObserveOutcome> {
let ObserveRequest {
cell_id,
yield_time_ms,
} = request;
@@ -152,7 +145,7 @@ impl CodeModeService {
let cell = match self.runtime.cell(&runtime_cell_id).await {
Ok(cell) => cell,
Err(runtime::Error::MissingCell(_) | runtime::Error::ClosedCell(_)) => {
return missing_wait(cell_id);
return missing_observation(cell_id);
}
Err(error) => return Box::pin(async move { Err(error.to_string()) }),
};
@@ -163,26 +156,26 @@ impl CodeModeService {
{
Ok(pending_event) => Box::pin(async move {
match pending_event.event().await {
Ok(event) => Ok(WaitOutcome::LiveCell(runtime_response(&cell_id, event)?)),
Ok(event) => Ok(observe_outcome(&cell_id, event)),
Err(runtime::Error::MissingCell(_) | runtime::Error::ClosedCell(_)) => {
Ok(WaitOutcome::MissingCell(missing_cell_response(cell_id)))
Ok(ObserveOutcome::Missing { cell_id })
}
Err(error) => Err(error.to_string()),
}
}),
Err(runtime::Error::MissingCell(_) | runtime::Error::ClosedCell(_)) => {
missing_wait(cell_id)
missing_observation(cell_id)
}
Err(error) => Box::pin(async move { Err(error.to_string()) }),
}
}
pub async fn terminate(&self, cell_id: CellId) -> Result<WaitOutcome, String> {
pub async fn terminate(&self, cell_id: CellId) -> Result<TerminateOutcome, String> {
let runtime_cell_id = runtime_cell_id(&cell_id);
let outcome = match self.runtime.terminate(&runtime_cell_id).await {
Ok(event) => Ok(WaitOutcome::LiveCell(runtime_response(&cell_id, event)?)),
Ok(event) => terminate_outcome(&cell_id, event),
Err(runtime::Error::MissingCell(_) | runtime::Error::ClosedCell(_)) => {
Ok(WaitOutcome::MissingCell(missing_cell_response(cell_id)))
Ok(TerminateOutcome::Missing { cell_id })
}
Err(error) => Err(error.to_string()),
};
@@ -193,16 +186,17 @@ impl CodeModeService {
outcome
}
pub async fn wait_to_pending(
#[cfg(test)]
async fn observe_to_pending(
&self,
request: WaitToPendingRequest,
) -> Result<WaitToPendingOutcome, String> {
request: ObserveToPendingRequest,
) -> Result<ObserveToPendingOutcome, String> {
let cell_id = request.cell_id;
let runtime_cell_id = runtime_cell_id(&cell_id);
let cell = match self.runtime.pausable_cell(&runtime_cell_id).await {
Ok(cell) => cell,
Err(runtime::Error::MissingCell(_) | runtime::Error::ClosedCell(_)) => {
return Ok(WaitToPendingOutcome::MissingCell(missing_cell_response(
return Ok(ObserveToPendingOutcome::MissingCell(missing_cell_response(
cell_id,
)));
}
@@ -225,17 +219,18 @@ impl CodeModeService {
Ok(event) => {
self.record_pending_generation(&runtime_cell_id, &event)
.await;
Ok(WaitToPendingOutcome::LiveCell(pending_outcome(
Ok(ObserveToPendingOutcome::LiveCell(pending_outcome(
&cell_id, event,
)?))
}
Err(runtime::Error::MissingCell(_) | runtime::Error::ClosedCell(_)) => Ok(
WaitToPendingOutcome::MissingCell(missing_cell_response(cell_id)),
ObserveToPendingOutcome::MissingCell(missing_cell_response(cell_id)),
),
Err(error) => Err(error.to_string()),
}
}
#[cfg(test)]
async fn record_pending_generation(
&self,
cell_id: &runtime::CellId,
@@ -275,18 +270,24 @@ impl CodeModeSession for CodeModeService {
self.runtime.is_alive()
}
fn execute<'a>(
fn create_cell<'a>(
&'a self,
request: ExecuteRequest,
) -> CodeModeSessionResultFuture<'a, StartedCell> {
Box::pin(CodeModeService::execute(self, request))
request: CreateCellRequest,
) -> CodeModeSessionResultFuture<'a, CellId> {
Box::pin(CodeModeService::create_cell(self, request))
}
fn wait<'a>(&'a self, request: WaitRequest) -> CodeModeSessionResultFuture<'a, WaitOutcome> {
Box::pin(CodeModeService::wait(self, request))
fn observe<'a>(
&'a self,
request: ObserveRequest,
) -> CodeModeSessionResultFuture<'a, ObserveOutcome> {
Box::pin(CodeModeService::observe(self, request))
}
fn terminate<'a>(&'a self, cell_id: CellId) -> CodeModeSessionResultFuture<'a, WaitOutcome> {
fn terminate<'a>(
&'a self,
cell_id: CellId,
) -> CodeModeSessionResultFuture<'a, TerminateOutcome> {
Box::pin(CodeModeService::terminate(self, cell_id))
}
@@ -347,7 +348,7 @@ impl runtime::SessionRuntimeDelegate for ProtocolDelegate {
}
}
fn runtime_request(request: ExecuteRequest) -> runtime::CreateCellRequest {
fn runtime_request(request: CreateCellRequest) -> runtime::CreateCellRequest {
let idempotency_key = format!("{}:{}", request.tool_call_id, request.source);
runtime::CreateCellRequest {
idempotency_key,
@@ -380,16 +381,17 @@ fn protocol_cell_id(cell_id: &runtime::CellId) -> CellId {
CellId::new(cell_id.as_str().to_string())
}
#[cfg(test)]
fn pending_outcome(
cell_id: &CellId,
event: runtime::PausableCellEvent,
) -> Result<ExecuteToPendingOutcome, String> {
) -> Result<PendingOutcome, String> {
match event {
runtime::PausableCellEvent::Pending(runtime::PendingFrontier {
content_items,
pending_tool_call_ids,
..
}) => Ok(ExecuteToPendingOutcome::Pending {
}) => Ok(PendingOutcome::Pending {
cell_id: cell_id.clone(),
content_items: content_items.into_iter().map(output_item).collect(),
pending_tool_call_ids,
@@ -397,40 +399,58 @@ fn pending_outcome(
runtime::PausableCellEvent::Completed {
content_items,
error_text,
} => Ok(ExecuteToPendingOutcome::Completed(
RuntimeResponse::Result {
} => Ok(PendingOutcome::Completed(RuntimeResponse::Result {
cell_id: cell_id.clone(),
content_items: content_items.into_iter().map(output_item).collect(),
error_text,
})),
runtime::PausableCellEvent::Terminated { content_items } => {
Ok(PendingOutcome::Completed(RuntimeResponse::Terminated {
cell_id: cell_id.clone(),
content_items: content_items.into_iter().map(output_item).collect(),
error_text,
},
)),
runtime::PausableCellEvent::Terminated { content_items } => Ok(
ExecuteToPendingOutcome::Completed(RuntimeResponse::Terminated {
cell_id: cell_id.clone(),
content_items: content_items.into_iter().map(output_item).collect(),
}),
),
}))
}
}
}
fn runtime_response(
cell_id: &CellId,
event: runtime::CellEvent,
) -> Result<RuntimeResponse, String> {
fn observe_outcome(cell_id: &CellId, event: runtime::CellEvent) -> ObserveOutcome {
match event {
runtime::CellEvent::Yielded { content_items } => Ok(RuntimeResponse::Yielded {
runtime::CellEvent::Yielded { content_items } => ObserveOutcome::Yielded {
cell_id: cell_id.clone(),
content_items: content_items.into_iter().map(output_item).collect(),
}),
},
runtime::CellEvent::Completed {
content_items,
error_text,
} => Ok(RuntimeResponse::Result {
} => ObserveOutcome::Completed {
cell_id: cell_id.clone(),
content_items: content_items.into_iter().map(output_item).collect(),
error_text,
},
runtime::CellEvent::Terminated { content_items } => ObserveOutcome::Terminated {
cell_id: cell_id.clone(),
content_items: content_items.into_iter().map(output_item).collect(),
},
}
}
fn terminate_outcome(
cell_id: &CellId,
event: runtime::CellEvent,
) -> Result<TerminateOutcome, String> {
match event {
runtime::CellEvent::Yielded { .. } => Err(format!(
"termination of code-mode cell {cell_id} unexpectedly yielded"
)),
runtime::CellEvent::Completed {
content_items,
error_text,
} => Ok(TerminateOutcome::Completed {
cell_id: cell_id.clone(),
content_items: content_items.into_iter().map(output_item).collect(),
error_text,
}),
runtime::CellEvent::Terminated { content_items } => Ok(RuntimeResponse::Terminated {
runtime::CellEvent::Terminated { content_items } => Ok(TerminateOutcome::Terminated {
cell_id: cell_id.clone(),
content_items: content_items.into_iter().map(output_item).collect(),
}),
@@ -454,6 +474,7 @@ fn output_item(item: runtime::OutputItem) -> FunctionCallOutputContentItem {
}
}
#[cfg(test)]
fn missing_cell_response(cell_id: CellId) -> RuntimeResponse {
RuntimeResponse::Result {
error_text: Some(format!("exec cell {cell_id} not found")),
@@ -462,8 +483,8 @@ fn missing_cell_response(cell_id: CellId) -> RuntimeResponse {
}
}
fn missing_wait(cell_id: CellId) -> CodeModeSessionResultFuture<'static, WaitOutcome> {
Box::pin(async move { Ok(WaitOutcome::MissingCell(missing_cell_response(cell_id))) })
fn missing_observation(cell_id: CellId) -> CodeModeSessionResultFuture<'static, ObserveOutcome> {
Box::pin(async move { Ok(ObserveOutcome::Missing { cell_id }) })
}
#[cfg(test)]
+140 -108
View File
@@ -154,13 +154,45 @@ fn cell_id(value: &str) -> CellId {
CellId::new(value.to_string())
}
fn execute_request(source: &str) -> ExecuteRequest {
ExecuteRequest {
fn execute_request(source: &str) -> CreateCellRequest {
CreateCellRequest {
tool_call_id: "call-1".to_string(),
enabled_tools: Vec::new(),
source: source.to_string(),
yield_time_ms: Some(1),
max_output_tokens: None,
}
}
async fn execute(service: &CodeModeService, request: CreateCellRequest) -> RuntimeResponse {
execute_with_yield_time(service, request, /*yield_time_ms*/ 1).await
}
async fn execute_with_yield_time(
service: &CodeModeService,
request: CreateCellRequest,
yield_time_ms: u64,
) -> RuntimeResponse {
let cell_id = service.create_cell(request).await.unwrap();
service
.observe(ObserveRequest {
cell_id,
yield_time_ms,
})
.await
.unwrap()
.into()
}
async fn create_and_observe_to_pending(
service: &CodeModeService,
request: CreateCellRequest,
) -> Result<PendingOutcome, String> {
let cell_id = service.create_pausable_cell(request).await?;
match service
.observe_to_pending(ObserveToPendingRequest { cell_id })
.await?
{
ObserveToPendingOutcome::LiveCell(outcome) => Ok(outcome),
ObserveToPendingOutcome::MissingCell(response) => Ok(PendingOutcome::Completed(response)),
}
}
@@ -185,17 +217,18 @@ async fn next_event(events_rx: &mut mpsc::UnboundedReceiver<DelegateEvent>) -> D
#[tokio::test]
async fn yields_and_resumes() {
let service = CodeModeService::new();
let cell = service
.execute(ExecuteRequest {
let cell = execute_with_yield_time(
&service,
CreateCellRequest {
source: r#"text("before"); yield_control(); text("after");"#.to_string(),
yield_time_ms: Some(60_000),
..execute_request("")
})
.await
.unwrap();
},
/*yield_time_ms*/ 60_000,
)
.await;
assert_eq!(
cell.initial_response().await.unwrap(),
cell,
RuntimeResponse::Yielded {
cell_id: cell_id("1"),
content_items: vec![FunctionCallOutputContentItem::InputText {
@@ -205,19 +238,19 @@ async fn yields_and_resumes() {
);
assert_eq!(
service
.wait(WaitRequest {
.observe(ObserveRequest {
cell_id: cell_id("1"),
yield_time_ms: 60_000,
})
.await
.unwrap(),
WaitOutcome::LiveCell(RuntimeResponse::Result {
ObserveOutcome::Completed {
cell_id: cell_id("1"),
content_items: vec![FunctionCallOutputContentItem::InputText {
text: "after".to_string(),
}],
error_text: None,
})
}
);
}
@@ -227,20 +260,21 @@ async fn returns_and_resumes_from_the_pending_frontier() {
let service = CodeModeService::with_delegate(delegate.clone());
assert_eq!(
service
.execute_to_pending(ExecuteRequest {
create_and_observe_to_pending(
&service,
CreateCellRequest {
enabled_tools: vec![blocking_tool()],
source: r#"
await tools.block({});
text("after");
"#
.to_string(),
yield_time_ms: Some(60_000),
..execute_request("")
})
.await
.unwrap(),
ExecuteToPendingOutcome::Pending {
},
)
.await
.unwrap(),
PendingOutcome::Pending {
cell_id: cell_id("1"),
content_items: Vec::new(),
pending_tool_call_ids: vec!["tool-1".to_string()],
@@ -252,56 +286,54 @@ text("after");
assert_eq!(
service
.wait_to_pending(WaitToPendingRequest {
.observe_to_pending(ObserveToPendingRequest {
cell_id: cell_id("1"),
})
.await
.unwrap(),
WaitToPendingOutcome::LiveCell(ExecuteToPendingOutcome::Completed(
RuntimeResponse::Result {
cell_id: cell_id("1"),
content_items: vec![FunctionCallOutputContentItem::InputText {
text: "after".to_string(),
}],
error_text: None,
}
))
ObserveToPendingOutcome::LiveCell(PendingOutcome::Completed(RuntimeResponse::Result {
cell_id: cell_id("1"),
content_items: vec![FunctionCallOutputContentItem::InputText {
text: "after".to_string(),
}],
error_text: None,
}))
);
}
#[tokio::test]
async fn observed_natural_completion_wins_over_termination() {
let service = CodeModeService::new();
let cell = service
.execute(execute_request(
r#"yield_control(); store("finished", true); text("done");"#,
))
.await
.unwrap();
let mut probe_generation = 0;
let cell = execute(
&service,
execute_request(r#"yield_control(); store("finished", true); text("done");"#),
)
.await;
assert_eq!(
cell.initial_response().await.unwrap(),
cell,
RuntimeResponse::Yielded {
cell_id: cell_id("1"),
content_items: Vec::new(),
}
);
tokio::time::timeout(Duration::from_secs(1), async {
let mut probe_index = 0;
tokio::time::timeout(Duration::from_secs(10), async {
loop {
probe_index += 1;
let response = service
.execute(ExecuteRequest {
tool_call_id: format!("probe-{probe_index}"),
yield_time_ms: Some(60_000),
probe_generation += 1;
// Observe the synchronous probe through completion so scheduler load
// cannot turn its short yield deadline into a false lifecycle failure.
let response = create_and_observe_to_pending(
&service,
CreateCellRequest {
tool_call_id: format!("completion-probe-{probe_generation}"),
..execute_request(r#"text(String(load("finished")));"#)
})
.await
.unwrap()
.initial_response()
.await
.unwrap();
let RuntimeResponse::Result { content_items, .. } = response else {
},
)
.await
.unwrap();
let PendingOutcome::Completed(RuntimeResponse::Result { content_items, .. }) = response
else {
panic!("expected stored-value probe to complete");
};
if content_items
@@ -318,13 +350,13 @@ async fn observed_natural_completion_wins_over_termination() {
.unwrap();
assert_eq!(
service.terminate(cell_id("1")).await.unwrap(),
WaitOutcome::LiveCell(RuntimeResponse::Result {
TerminateOutcome::Completed {
cell_id: cell_id("1"),
content_items: vec![FunctionCallOutputContentItem::InputText {
text: "done".to_string(),
}],
error_text: None,
})
}
);
}
@@ -332,19 +364,18 @@ async fn observed_natural_completion_wins_over_termination() {
async fn termination_cancels_pending_callbacks_before_responding() {
let (delegate, mut events_rx) = BlockingDelegate::new();
let service = CodeModeService::with_delegate(delegate.clone());
let cell = service
.execute(execute_request(
r#"notify("pending"); await new Promise(() => {});"#,
))
.await
.unwrap();
let cell = execute(
&service,
execute_request(r#"notify("pending"); await new Promise(() => {});"#),
)
.await;
assert_eq!(
next_event(&mut events_rx).await,
DelegateEvent::NotificationStarted
);
assert_eq!(
cell.initial_response().await.unwrap(),
cell,
RuntimeResponse::Yielded {
cell_id: cell_id("1"),
content_items: Vec::new(),
@@ -352,10 +383,10 @@ async fn termination_cancels_pending_callbacks_before_responding() {
);
assert_eq!(
service.terminate(cell_id("1")).await.unwrap(),
WaitOutcome::LiveCell(RuntimeResponse::Terminated {
TerminateOutcome::Terminated {
cell_id: cell_id("1"),
content_items: Vec::new(),
})
}
);
assert!(delegate.notification_finished.load(Ordering::Acquire));
assert_eq!(
@@ -372,15 +403,14 @@ async fn termination_cancels_pending_callbacks_before_responding() {
async fn termination_discards_stored_writes_before_the_next_cell_can_load_them() {
let (delegate, mut events_rx) = BlockingDelegate::new();
let service = CodeModeService::with_delegate(delegate.clone());
let cell = service
.execute(ExecuteRequest {
let created_cell_id = service
.create_cell(CreateCellRequest {
enabled_tools: vec![blocking_tool()],
source: r#"
store("candidate", "leaked");
await tools.block({});
"#
.to_string(),
yield_time_ms: Some(60_000),
..execute_request("")
})
.await
@@ -389,11 +419,11 @@ await tools.block({});
// Reaching the delegate proves that the store ran before execution became gated.
assert_eq!(next_event(&mut events_rx).await, DelegateEvent::ToolStarted);
assert_eq!(
service.terminate(cell.cell_id).await.unwrap(),
WaitOutcome::LiveCell(RuntimeResponse::Terminated {
service.terminate(created_cell_id).await.unwrap(),
TerminateOutcome::Terminated {
cell_id: cell_id("1"),
content_items: Vec::new(),
})
}
);
assert!(delegate.tool_finished.load(Ordering::Acquire));
assert_eq!(
@@ -406,16 +436,12 @@ await tools.block({});
);
assert_eq!(
service
.execute(ExecuteRequest {
yield_time_ms: Some(60_000),
..execute_request(r#"text(String(load("candidate")));"#)
})
.await
.unwrap()
.initial_response()
.await
.unwrap(),
execute_with_yield_time(
&service,
execute_request(r#"text(String(load("candidate")));"#),
/*yield_time_ms*/ 60_000,
)
.await,
RuntimeResponse::Result {
cell_id: cell_id("2"),
content_items: vec![FunctionCallOutputContentItem::InputText {
@@ -431,7 +457,7 @@ async fn shutdown_cancels_notifications_while_natural_completion_is_draining() {
let (delegate, mut events_rx) = HeldNotificationDelegate::new();
let service = Arc::new(CodeModeService::with_delegate(delegate.clone()));
service
.execute(execute_request(r#"notify("pending");"#))
.create_cell(execute_request(r#"notify("pending");"#))
.await
.unwrap();
@@ -460,19 +486,18 @@ async fn shutdown_cancels_notifications_while_natural_completion_is_draining() {
async fn repeated_termination_is_rejected_while_callback_cleanup_is_pending() {
let (delegate, mut events_rx) = HeldNotificationDelegate::new();
let service = Arc::new(CodeModeService::with_delegate(delegate.clone()));
let cell = service
.execute(execute_request(
r#"notify("pending"); await new Promise(() => {});"#,
))
.await
.unwrap();
let cell = execute(
&service,
execute_request(r#"notify("pending"); await new Promise(() => {});"#),
)
.await;
assert_eq!(
next_event(&mut events_rx).await,
DelegateEvent::NotificationStarted
);
assert_eq!(
cell.initial_response().await.unwrap(),
cell,
RuntimeResponse::Yielded {
cell_id: cell_id("1"),
content_items: Vec::new(),
@@ -496,10 +521,10 @@ async fn repeated_termination_is_rejected_while_callback_cleanup_is_pending() {
);
assert_eq!(
first_termination.await.unwrap().unwrap(),
WaitOutcome::LiveCell(RuntimeResponse::Terminated {
TerminateOutcome::Terminated {
cell_id: cell_id("1"),
content_items: Vec::new(),
})
}
);
assert_eq!(
next_event(&mut events_rx).await,
@@ -510,13 +535,10 @@ async fn repeated_termination_is_rejected_while_callback_cleanup_is_pending() {
#[tokio::test]
async fn second_observer_is_rejected_without_displacing_the_first() {
let service = CodeModeService::new();
let cell = service
.execute(execute_request("await new Promise(() => {});"))
.await
.unwrap();
let cell = execute(&service, execute_request("await new Promise(() => {});")).await;
assert_eq!(
cell.initial_response().await.unwrap(),
cell,
RuntimeResponse::Yielded {
cell_id: cell_id("1"),
content_items: Vec::new(),
@@ -524,14 +546,14 @@ async fn second_observer_is_rejected_without_displacing_the_first() {
);
let first_observer = service
.begin_wait(WaitRequest {
.begin_observe(ObserveRequest {
cell_id: cell_id("1"),
yield_time_ms: 60_000,
})
.await;
assert_eq!(
service
.wait(WaitRequest {
.observe(ObserveRequest {
cell_id: cell_id("1"),
yield_time_ms: 60_000,
})
@@ -540,17 +562,17 @@ async fn second_observer_is_rejected_without_displacing_the_first() {
"exec cell 1 already has an active observer"
);
let terminated = RuntimeResponse::Terminated {
let terminated = TerminateOutcome::Terminated {
cell_id: cell_id("1"),
content_items: Vec::new(),
};
assert_eq!(
service.terminate(cell_id("1")).await.unwrap(),
WaitOutcome::LiveCell(terminated.clone())
);
assert_eq!(service.terminate(cell_id("1")).await.unwrap(), terminated);
assert_eq!(
first_observer.await.unwrap(),
WaitOutcome::LiveCell(terminated)
ObserveOutcome::Terminated {
cell_id: cell_id("1"),
content_items: Vec::new(),
}
);
}
@@ -558,11 +580,15 @@ async fn second_observer_is_rejected_without_displacing_the_first() {
async fn natural_completion_cleans_up_callbacks_before_responding() {
let (delegate, mut events_rx) = BlockingDelegate::new();
let service = CodeModeService::with_delegate(delegate.clone());
let cell = service
.execute(ExecuteRequest {
let created_cell_id = service
.create_cell(CreateCellRequest {
enabled_tools: vec![blocking_tool()],
source: r#"tools.block({}); text("done");"#.to_string(),
yield_time_ms: Some(60_000),
source: concat!(
"tools.block({});",
"await new Promise(resolve => setTimeout(resolve, 100));",
"text('done');",
)
.to_string(),
..execute_request("")
})
.await
@@ -570,8 +596,14 @@ async fn natural_completion_cleans_up_callbacks_before_responding() {
assert_eq!(next_event(&mut events_rx).await, DelegateEvent::ToolStarted);
assert_eq!(
cell.initial_response().await.unwrap(),
RuntimeResponse::Result {
service
.observe(ObserveRequest {
cell_id: created_cell_id,
yield_time_ms: 60_000,
})
.await
.unwrap(),
ObserveOutcome::Completed {
cell_id: cell_id("1"),
content_items: vec![FunctionCallOutputContentItem::InputText {
text: "done".to_string(),
+141 -129
View File
@@ -6,15 +6,16 @@ use super::CodeModeNestedToolCall;
use super::CodeModeService;
use super::CodeModeSessionDelegate;
use super::NotificationFuture;
use super::ObserveOutcome;
use super::ObserveRequest;
use super::ObserveToPendingOutcome;
use super::ObserveToPendingRequest;
use super::PendingOutcome;
use super::RuntimeResponse;
use super::TerminateOutcome;
use super::ToolInvocationFuture;
use super::WaitOutcome;
use super::WaitRequest;
use super::WaitToPendingOutcome;
use super::WaitToPendingRequest;
use crate::CodeModeToolKind;
use crate::ExecuteRequest;
use crate::ExecuteToPendingOutcome;
use crate::CreateCellRequest;
use crate::FunctionCallOutputContentItem;
use crate::ToolDefinition;
use codex_protocol::ToolName;
@@ -61,13 +62,11 @@ impl CodeModeSessionDelegate for ReleasableToolDelegate {
fn cell_closed(&self, _cell_id: &CellId) {}
}
fn execute_request(source: &str) -> ExecuteRequest {
ExecuteRequest {
fn execute_request(source: &str) -> CreateCellRequest {
CreateCellRequest {
tool_call_id: "call_1".to_string(),
enabled_tools: Vec::new(),
source: source.to_string(),
yield_time_ms: Some(1),
max_output_tokens: None,
}
}
@@ -86,14 +85,38 @@ fn echo_tool() -> ToolDefinition {
}
}
async fn execute(service: &CodeModeService, request: ExecuteRequest) -> RuntimeResponse {
async fn execute(service: &CodeModeService, request: CreateCellRequest) -> RuntimeResponse {
execute_with_yield_time(service, request, /*yield_time_ms*/ 10_000).await
}
async fn execute_with_yield_time(
service: &CodeModeService,
request: CreateCellRequest,
yield_time_ms: u64,
) -> RuntimeResponse {
let cell_id = service.create_cell(request).await.unwrap();
service
.execute(request)
.await
.unwrap()
.initial_response()
.observe(ObserveRequest {
cell_id,
yield_time_ms,
})
.await
.unwrap()
.into()
}
async fn create_and_observe_to_pending(
service: &CodeModeService,
request: CreateCellRequest,
) -> Result<PendingOutcome, String> {
let cell_id = service.create_pausable_cell(request).await?;
match service
.observe_to_pending(ObserveToPendingRequest { cell_id })
.await?
{
ObserveToPendingOutcome::LiveCell(outcome) => Ok(outcome),
ObserveToPendingOutcome::MissingCell(response) => Ok(PendingOutcome::Completed(response)),
}
}
#[tokio::test]
@@ -102,9 +125,8 @@ async fn synchronous_exit_returns_successfully() {
let response = execute(
&service,
ExecuteRequest {
CreateCellRequest {
source: r#"text("before"); exit(); text("after");"#.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -129,9 +151,8 @@ async fn stored_values_are_shared_between_cells_but_not_sessions() {
let write_response = execute(
&first_session,
ExecuteRequest {
CreateCellRequest {
source: r#"store("key", "visible");"#.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -139,18 +160,16 @@ async fn stored_values_are_shared_between_cells_but_not_sessions() {
let same_session = execute(
&first_session,
ExecuteRequest {
CreateCellRequest {
source: r#"text(String(load("key")));"#.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
.await;
let other_session = execute(
&second_session,
ExecuteRequest {
CreateCellRequest {
source: r#"text(String(load("key")));"#.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -190,15 +209,17 @@ async fn stored_values_are_shared_between_cells_but_not_sessions() {
async fn shutdown_interrupts_cpu_bound_cells() {
let service = CodeModeService::new();
let cell = service
.execute(ExecuteRequest {
let response = execute_with_yield_time(
&service,
CreateCellRequest {
source: "while (true) {}".to_string(),
..execute_request("")
})
.await
.unwrap();
},
/*yield_time_ms*/ 1,
)
.await;
assert_eq!(
cell.initial_response().await.unwrap(),
response,
RuntimeResponse::Yielded {
cell_id: cell_id("1"),
content_items: Vec::new(),
@@ -217,7 +238,7 @@ async fn start_cell_rejects_new_cell_after_shutdown_begins() {
service.shutdown().await.unwrap();
let error = service
.execute(execute_request("text('late');"))
.create_cell(execute_request("text('late');"))
.await
.err()
.unwrap();
@@ -226,21 +247,22 @@ async fn start_cell_rejects_new_cell_after_shutdown_begins() {
}
#[tokio::test]
async fn execute_to_pending_returns_completed_for_synchronous_results() {
async fn create_and_observe_to_pending_returns_completed_for_synchronous_results() {
let service = CodeModeService::new();
let response = service
.execute_to_pending(ExecuteRequest {
let response = create_and_observe_to_pending(
&service,
CreateCellRequest {
source: r#"text("done");"#.to_string(),
yield_time_ms: Some(60_000),
..execute_request("")
})
.await
.unwrap();
},
)
.await
.unwrap();
assert_eq!(
response,
ExecuteToPendingOutcome::Completed(RuntimeResponse::Result {
PendingOutcome::Completed(RuntimeResponse::Result {
cell_id: cell_id("1"),
content_items: vec![FunctionCallOutputContentItem::InputText {
text: "done".to_string(),
@@ -251,16 +273,18 @@ async fn execute_to_pending_returns_completed_for_synchronous_results() {
}
#[tokio::test]
async fn execute_to_pending_returns_once_the_runtime_is_quiescent() {
async fn create_and_observe_to_pending_returns_once_the_runtime_is_quiescent() {
let service = CodeModeService::new();
let response = tokio::time::timeout(
Duration::from_secs(1),
service.execute_to_pending(ExecuteRequest {
source: r#"text("before"); await new Promise(() => {});"#.to_string(),
yield_time_ms: Some(60_000),
..execute_request("")
}),
create_and_observe_to_pending(
&service,
CreateCellRequest {
source: r#"text("before"); await new Promise(() => {});"#.to_string(),
..execute_request("")
},
),
)
.await
.unwrap()
@@ -268,7 +292,7 @@ async fn execute_to_pending_returns_once_the_runtime_is_quiescent() {
assert_eq!(
response,
ExecuteToPendingOutcome::Pending {
PendingOutcome::Pending {
cell_id: cell_id("1"),
content_items: vec![FunctionCallOutputContentItem::InputText {
text: "before".to_string(),
@@ -281,19 +305,20 @@ async fn execute_to_pending_returns_once_the_runtime_is_quiescent() {
assert_eq!(
termination,
WaitOutcome::LiveCell(RuntimeResponse::Terminated {
TerminateOutcome::Terminated {
cell_id: cell_id("1"),
content_items: Vec::new(),
})
}
);
}
#[tokio::test]
async fn execute_to_pending_identifies_tool_calls_in_paused_frontier() {
async fn create_and_observe_to_pending_identifies_tool_calls_in_paused_frontier() {
let service = CodeModeService::new();
let response = service
.execute_to_pending(ExecuteRequest {
let response = create_and_observe_to_pending(
&service,
CreateCellRequest {
enabled_tools: vec![echo_tool()],
source: r#"
await Promise.all([
@@ -302,15 +327,15 @@ await Promise.all([
]);
"#
.to_string(),
yield_time_ms: Some(60_000),
..execute_request("")
})
.await
.unwrap();
},
)
.await
.unwrap();
assert_eq!(
response,
ExecuteToPendingOutcome::Pending {
PendingOutcome::Pending {
cell_id: cell_id("1"),
content_items: Vec::new(),
pending_tool_call_ids: vec!["tool-1".to_string(), "tool-2".to_string()],
@@ -321,10 +346,10 @@ await Promise.all([
assert_eq!(
termination,
WaitOutcome::LiveCell(RuntimeResponse::Terminated {
TerminateOutcome::Terminated {
cell_id: cell_id("1"),
content_items: Vec::new(),
})
}
);
}
@@ -332,8 +357,9 @@ await Promise.all([
async fn wait_to_pending_retains_outstanding_calls_when_a_delayed_call_is_added() {
let service = CodeModeService::new();
let initial_response = service
.execute_to_pending(ExecuteRequest {
let initial_response = create_and_observe_to_pending(
&service,
CreateCellRequest {
enabled_tools: vec![echo_tool()],
source: r#"
setTimeout(() => {
@@ -345,15 +371,15 @@ await Promise.all([
]);
"#
.to_string(),
yield_time_ms: Some(60_000),
..execute_request("")
})
.await
.unwrap();
},
)
.await
.unwrap();
assert_eq!(
initial_response,
ExecuteToPendingOutcome::Pending {
PendingOutcome::Pending {
cell_id: cell_id("1"),
content_items: Vec::new(),
pending_tool_call_ids: vec!["tool-1".to_string(), "tool-2".to_string()],
@@ -367,13 +393,13 @@ await Promise.all([
let resumed_response = tokio::time::timeout(Duration::from_secs(5), async {
loop {
let response = service
.wait_to_pending(WaitToPendingRequest {
.observe_to_pending(ObserveToPendingRequest {
cell_id: cell_id("1"),
})
.await?;
if !matches!(
&response,
WaitToPendingOutcome::LiveCell(ExecuteToPendingOutcome::Pending {
ObserveToPendingOutcome::LiveCell(PendingOutcome::Pending {
pending_tool_call_ids,
..
}) if pending_tool_call_ids.is_empty()
@@ -388,7 +414,7 @@ await Promise.all([
assert_eq!(
resumed_response,
WaitToPendingOutcome::LiveCell(ExecuteToPendingOutcome::Pending {
ObserveToPendingOutcome::LiveCell(PendingOutcome::Pending {
cell_id: cell_id("1"),
content_items: Vec::new(),
pending_tool_call_ids: vec![
@@ -403,20 +429,21 @@ await Promise.all([
assert_eq!(
termination,
WaitOutcome::LiveCell(RuntimeResponse::Terminated {
TerminateOutcome::Terminated {
cell_id: cell_id("1"),
content_items: Vec::new(),
})
}
);
}
#[tokio::test]
async fn wait_to_pending_returns_after_resumed_runtime_becomes_quiescent_again() {
async fn observe_to_pending_returns_after_resumed_runtime_becomes_quiescent_again() {
let delegate = Arc::new(ReleasableToolDelegate::default());
let service = CodeModeService::with_delegate(delegate.clone());
let initial_response = service
.execute_to_pending(ExecuteRequest {
let initial_response = create_and_observe_to_pending(
&service,
CreateCellRequest {
enabled_tools: vec![echo_tool()],
source: r#"
await tools.echo({});
@@ -424,15 +451,15 @@ text("after");
await new Promise(() => {});
"#
.to_string(),
yield_time_ms: Some(60_000),
..execute_request("")
})
.await
.unwrap();
},
)
.await
.unwrap();
assert_eq!(
initial_response,
ExecuteToPendingOutcome::Pending {
PendingOutcome::Pending {
cell_id: cell_id("1"),
content_items: Vec::new(),
pending_tool_call_ids: vec!["tool-1".to_string()],
@@ -443,7 +470,7 @@ await new Promise(() => {});
let resumed_response = tokio::time::timeout(
Duration::from_secs(1),
service.wait_to_pending(WaitToPendingRequest {
service.observe_to_pending(ObserveToPendingRequest {
cell_id: cell_id("1"),
}),
)
@@ -453,7 +480,7 @@ await new Promise(() => {});
assert_eq!(
resumed_response,
WaitToPendingOutcome::LiveCell(ExecuteToPendingOutcome::Pending {
ObserveToPendingOutcome::LiveCell(PendingOutcome::Pending {
cell_id: cell_id("1"),
content_items: vec![FunctionCallOutputContentItem::InputText {
text: "after".to_string(),
@@ -466,35 +493,36 @@ await new Promise(() => {});
assert_eq!(
termination,
WaitOutcome::LiveCell(RuntimeResponse::Terminated {
TerminateOutcome::Terminated {
cell_id: cell_id("1"),
content_items: Vec::new(),
})
}
);
}
#[tokio::test]
async fn wait_to_pending_returns_completed_after_resumed_runtime_finishes() {
async fn observe_to_pending_returns_completed_after_resumed_runtime_finishes() {
let delegate = Arc::new(ReleasableToolDelegate::default());
let service = CodeModeService::with_delegate(delegate.clone());
let initial_response = service
.execute_to_pending(ExecuteRequest {
let initial_response = create_and_observe_to_pending(
&service,
CreateCellRequest {
enabled_tools: vec![echo_tool()],
source: r#"
await tools.echo({});
text("done");
"#
.to_string(),
yield_time_ms: Some(60_000),
..execute_request("")
})
.await
.unwrap();
},
)
.await
.unwrap();
assert_eq!(
initial_response,
ExecuteToPendingOutcome::Pending {
PendingOutcome::Pending {
cell_id: cell_id("1"),
content_items: Vec::new(),
pending_tool_call_ids: vec!["tool-1".to_string()],
@@ -505,7 +533,7 @@ text("done");
let resumed_response = tokio::time::timeout(
Duration::from_secs(1),
service.wait_to_pending(WaitToPendingRequest {
service.observe_to_pending(ObserveToPendingRequest {
cell_id: cell_id("1"),
}),
)
@@ -515,15 +543,13 @@ text("done");
assert_eq!(
resumed_response,
WaitToPendingOutcome::LiveCell(ExecuteToPendingOutcome::Completed(
RuntimeResponse::Result {
cell_id: cell_id("1"),
content_items: vec![FunctionCallOutputContentItem::InputText {
text: "done".to_string(),
}],
error_text: None,
}
))
ObserveToPendingOutcome::LiveCell(PendingOutcome::Completed(RuntimeResponse::Result {
cell_id: cell_id("1"),
content_items: vec![FunctionCallOutputContentItem::InputText {
text: "done".to_string(),
}],
error_text: None,
}))
);
}
@@ -533,9 +559,8 @@ async fn v8_console_is_not_exposed_on_global_this() {
let response = execute(
&service,
ExecuteRequest {
CreateCellRequest {
source: r#"text(String(Object.hasOwn(globalThis, "console")));"#.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -559,7 +584,7 @@ async fn date_locale_string_formats_with_icu_data() {
let response = execute(
&service,
ExecuteRequest {
CreateCellRequest {
source: r#"
const value = new Date("2025-01-02T03:04:05Z")
.toLocaleString("fr-FR", {
@@ -575,7 +600,6 @@ const value = new Date("2025-01-02T03:04:05Z")
text(value);
"#
.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -599,7 +623,7 @@ async fn intl_date_time_format_formats_with_icu_data() {
let response = execute(
&service,
ExecuteRequest {
CreateCellRequest {
source: r#"
const formatter = new Intl.DateTimeFormat("fr-FR", {
weekday: "long",
@@ -614,7 +638,6 @@ const formatter = new Intl.DateTimeFormat("fr-FR", {
text(formatter.format(new Date("2025-01-02T03:04:05Z")));
"#
.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -638,7 +661,7 @@ async fn output_helpers_return_undefined() {
let response = execute(
&service,
ExecuteRequest {
CreateCellRequest {
source: r#"
const returnsUndefined = [
text("first"),
@@ -648,7 +671,6 @@ const returnsUndefined = [
text(JSON.stringify(returnsUndefined));
"#
.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -681,7 +703,7 @@ async fn image_helper_accepts_raw_mcp_image_block_with_original_detail() {
let response = execute(
&service,
ExecuteRequest {
CreateCellRequest {
source: r#"
image({
type: "image",
@@ -691,7 +713,6 @@ image({
});
"#
.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -716,7 +737,7 @@ async fn generated_image_helper_appends_image_and_output_hint() {
let response = execute(
&service,
ExecuteRequest {
CreateCellRequest {
source: r#"
generatedImage({
image_url: "data:image/png;base64,AAA",
@@ -724,7 +745,6 @@ generatedImage({
});
"#
.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -754,7 +774,7 @@ async fn image_helper_second_arg_overrides_explicit_object_detail() {
let response = execute(
&service,
ExecuteRequest {
CreateCellRequest {
source: r#"
image(
{
@@ -765,7 +785,6 @@ image(
);
"#
.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -790,7 +809,7 @@ async fn image_helper_second_arg_overrides_raw_mcp_image_detail() {
let response = execute(
&service,
ExecuteRequest {
CreateCellRequest {
source: r#"
image(
{
@@ -803,7 +822,6 @@ image(
);
"#
.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -828,7 +846,7 @@ async fn image_helper_accepts_low_detail() {
let response = execute(
&service,
ExecuteRequest {
CreateCellRequest {
source: r#"
image({
image_url: "data:image/png;base64,AAA",
@@ -836,7 +854,6 @@ image({
});
"#
.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -869,9 +886,8 @@ async fn image_helpers_reject_remote_urls() {
let response = execute(
&service,
ExecuteRequest {
CreateCellRequest {
source,
yield_time_ms: None,
..execute_request("")
},
)
@@ -897,7 +913,7 @@ async fn image_helper_rejects_unsupported_detail() {
let response = execute(
&service,
ExecuteRequest {
CreateCellRequest {
source: r#"
image({
image_url: "data:image/png;base64,AAA",
@@ -905,7 +921,6 @@ image({
});
"#
.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -927,7 +942,7 @@ async fn image_helper_rejects_raw_mcp_result_container() {
let response = execute(
&service,
ExecuteRequest {
CreateCellRequest {
source: r#"
image({
content: [
@@ -942,7 +957,6 @@ image({
});
"#
.to_string(),
yield_time_ms: None,
..execute_request("")
},
)
@@ -961,11 +975,11 @@ image({
}
#[tokio::test]
async fn wait_reports_missing_cell_separately_from_runtime_results() {
async fn observe_reports_missing_cell_separately_from_runtime_results() {
let service = CodeModeService::new();
let response = service
.wait(WaitRequest {
.observe(ObserveRequest {
cell_id: cell_id("missing"),
yield_time_ms: 1,
})
@@ -974,10 +988,8 @@ async fn wait_reports_missing_cell_separately_from_runtime_results() {
assert_eq!(
response,
WaitOutcome::MissingCell(RuntimeResponse::Result {
ObserveOutcome::Missing {
cell_id: cell_id("missing"),
content_items: Vec::new(),
error_text: Some("exec cell missing not found".to_string()),
})
}
);
}
@@ -45,6 +45,7 @@ use crate::cell_actor::CompletionCommit;
use crate::cell_actor::ObserveMode;
type RuntimeEventFuture = Pin<Box<dyn Future<Output = Result<CellEvent, Error>> + Send + 'static>>;
#[allow(dead_code)]
type PausableRuntimeEventFuture =
Pin<Box<dyn Future<Output = Result<PausableCellEvent, Error>> + Send + 'static>>;
@@ -120,6 +121,7 @@ impl<D: SessionRuntimeDelegate> SessionRuntime<D> {
Ok(Cell::new(id))
}
#[allow(dead_code)]
pub(crate) async fn create_pausable_cell(
&self,
request: CreateCellRequest,
@@ -157,6 +159,7 @@ impl<D: SessionRuntimeDelegate> SessionRuntime<D> {
})
}
#[allow(dead_code)]
pub(crate) async fn wait_to_pending(
&self,
cell: &PausableCell,
@@ -169,6 +172,7 @@ impl<D: SessionRuntimeDelegate> SessionRuntime<D> {
.await
}
#[allow(dead_code)]
pub(crate) async fn resume(
&self,
cell: &PausableCell,
@@ -186,6 +190,7 @@ impl<D: SessionRuntimeDelegate> SessionRuntime<D> {
Ok(Cell::new(cell_id.clone()))
}
#[cfg(test)]
pub(crate) async fn pausable_cell(&self, cell_id: &CellId) -> Result<PausableCell, Error> {
self.pausable_handle(cell_id).await?;
Ok(PausableCell::new(cell_id.clone()))
@@ -298,6 +303,7 @@ impl<D: SessionRuntimeDelegate> SessionRuntime<D> {
self.handle_for_kind(cell_id, CellKind::Continuing).await
}
#[allow(dead_code)]
async fn pausable_handle(&self, cell_id: &CellId) -> Result<CellHandle, Error> {
self.handle_for_kind(cell_id, CellKind::Pausable).await
}
@@ -428,6 +434,7 @@ fn map_cell_event(cell_id: CellId, event: CellEventFuture) -> RuntimeEventFuture
})
}
#[allow(dead_code)]
fn map_pausable_event(cell_id: CellId, event: CellEventFuture) -> PausableRuntimeEventFuture {
Box::pin(async move {
match event.await.map_err(|error| actor_error(&cell_id, error))? {
@@ -31,6 +31,7 @@ pub(crate) enum CellExecutionPolicy {
#[default]
ContinueWhenUnblocked,
/// Remain paused at a pending frontier until an explicit resume advances it.
#[allow(dead_code)]
PauseAtPendingFrontier,
}
@@ -52,10 +53,12 @@ impl Cell {
/// A cell that remains paused at each pending frontier until explicitly resumed.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[allow(dead_code)]
pub(crate) struct PausableCell {
id: CellId,
}
#[allow(dead_code)]
impl PausableCell {
pub(super) fn new(id: CellId) -> Self {
Self { id }
@@ -120,6 +123,7 @@ pub(crate) enum CellEvent {
/// An observable lifecycle event for a pausable cell.
#[derive(Clone, Debug, PartialEq)]
#[allow(dead_code)]
pub(crate) enum PausableCellEvent {
Pending(PendingFrontier),
Completed {