code-mode: make create and observe retry-safe

This commit is contained in:
Channing Conger
2026-06-22 08:48:46 +00:00
parent 96581e99cf
commit 098e9f0a1e
10 changed files with 191 additions and 38 deletions
@@ -40,11 +40,13 @@ impl CodeModeExecuteHandler {
let enabled_tools =
codex_tools::collect_code_mode_tool_definitions(&self.nested_tool_specs);
let started_at = std::time::Instant::now();
let idempotency_key = format!("{}:{call_id}", exec.session.thread_id());
let cell_id = exec
.session
.services
.code_mode_service
.create_cell(codex_code_mode::CreateCellRequest {
idempotency_key: idempotency_key.clone(),
tool_call_id: call_id.clone(),
enabled_tools,
source: args.code.clone(),
@@ -77,6 +79,7 @@ impl CodeModeExecuteHandler {
.services
.code_mode_service
.observe(codex_code_mode::ObserveRequest {
idempotency_key,
cell_id: cell_id.clone(),
yield_time_ms: args
.yield_time_ms
@@ -66,6 +66,7 @@ impl CodeModeWaitHandler {
let ToolInvocation {
session,
turn,
call_id,
tool_name,
payload,
..
@@ -76,6 +77,7 @@ impl CodeModeWaitHandler {
if tool_name.namespace.is_none() && tool_name.name.as_str() == WAIT_TOOL_NAME =>
{
let args: ExecWaitArgs = parse_arguments(&arguments)?;
let idempotency_key = format!("{}:{call_id}", session.thread_id());
let exec = ExecContext { session, turn };
let started_at = std::time::Instant::now();
let cell_id = codex_code_mode::CellId::new(args.cell_id);
@@ -99,6 +101,7 @@ impl CodeModeWaitHandler {
.services
.code_mode_service
.observe(codex_code_mode::ObserveRequest {
idempotency_key,
cell_id,
yield_time_ms: args.yield_time_ms,
})