diff --git a/codex-rs/core/src/tools/code_mode/mod.rs b/codex-rs/core/src/tools/code_mode/mod.rs index 17d51f101f..d036a3224e 100644 --- a/codex-rs/core/src/tools/code_mode/mod.rs +++ b/codex-rs/core/src/tools/code_mode/mod.rs @@ -86,14 +86,24 @@ impl CodeModeService { &self, request: codex_code_mode::WaitRequest, ) -> Result { - self.session().await?.wait(request).await + match self.session.get() { + Some(session) => session.wait(request).await, + None => Ok(codex_code_mode::WaitOutcome::MissingCell( + missing_cell_response(request.cell_id), + )), + } } pub(crate) async fn terminate( &self, cell_id: CellId, ) -> Result { - self.session().await?.terminate(cell_id).await + match self.session.get() { + Some(session) => session.terminate(cell_id).await, + None => Ok(codex_code_mode::WaitOutcome::MissingCell( + missing_cell_response(cell_id), + )), + } } pub(crate) async fn shutdown(&self) -> Result<(), String> { @@ -142,6 +152,14 @@ impl CodeModeService { } } +fn missing_cell_response(cell_id: CellId) -> RuntimeResponse { + RuntimeResponse::Result { + error_text: Some(format!("exec cell {cell_id} not found")), + cell_id, + content_items: Vec::new(), + } +} + pub(super) async fn handle_runtime_response( exec: &ExecContext, response: RuntimeResponse,