openai/codex · error

tool runtime start would create a second terminal operation…

Error message

tool runtime start would create a second terminal operation for {tool_call_id}

What it means

The tool call already has a terminal_operation_id, and this runtime start would attach a second terminal operation, which the model forbids for one tool call.

Solutions

  1. Ensure only one runtime begin creates the terminal operation per tool call
  2. Reuse the existing terminal operation instead of creating a new one
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at codex-rs/rollout-trace/src/reducer/tool.rs:261 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/42466e7960cb3df4. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/rollout-trace/src/reducer/tool.rs:261

        let (thread_id, _requester, kind, existing_terminal_operation_id) = {
            let Some(tool_call) = self.rollout.tool_calls.get_mut(&tool_call_id) else {
                bail!("tool runtime start referenced unknown call {tool_call_id}");
            };
            push_unique(
                &mut tool_call.raw_runtime_payload_ids,
                &runtime_payload.raw_payload_id,
            );
            (
                tool_call.thread_id.clone(),
                tool_call.requester.clone(),
                tool_call.kind.clone(),
                tool_call.terminal_operation_id.clone(),
            )
        };
        if existing_terminal_operation_id.is_some()
            && matches!(kind, ToolCallKind::ExecCommand | ToolCallKind::WriteStdin)
        {
            bail!("tool runtime start would create a second terminal operation for {tool_call_id}");
        }

        // Protocol begin events carry runtime facts such as process ids and
        // cwd. These facts should create terminal rows, but they must not
        // replace the canonical invocation payload captured at dispatch.
        let terminal_operation_id = self.start_terminal_operation_from_runtime(
            seq,
            wall_time_unix_ms,
            &thread_id,
            &tool_call_id,
            &kind,
            &runtime_payload,
        )?;

        if let Some(operation_id) = &terminal_operation_id {
            let Some(tool_call) = self.rollout.tool_calls.get_mut(&tool_call_id) else {
                bail!("tool call {tool_call_id} disappeared during runtime start reduction");
            };

View on GitHub (pinned to 339751715c)