Skip to content

fix(codex): keep code-mode exec results and wrap freeform inputs for opencode - #109

Merged
NishantJoshi00 merged 3 commits into
mainfrom
fix/104-followups
Nov 18, 2026
Merged

NishantJoshi00 merged 3 commits into
mainfrom
fix/104-followups

Conversation

@NishantJoshi00

Copy link
Copy Markdown
Collaborator

Fixes #104

Problem

  1. Code-mode results dropped. Codex code mode writes custom_tool_call_output.output as an array of input_text content items. The reader only accepted strings, so every code-mode exec result was lost on export and on conversion to every target.
  2. OpenCode import rejected freeform inputs. The OpenCode writer put a non-object tool input (the raw JS of a code-mode exec call) straight into state.input, which opencode import rejects.

Fix

  • Array outputs in custom_tool_call_output and function_call_output that are all text collapse to text; other lists are kept as JSON.
  • Failed code-mode scripts are flagged as errors. Codex never writes a success flag, so the only on-disk signal is the status header it inserts as the first item (Script failed\nWall time … seconds\nOutput:\n); it is matched whole, so output that merely starts with those words isn't misread.
  • The OpenCode writer wraps a non-object input as {"input": <value>} (matching the Claude Code export) and marks the wrap in state.metadata (txcriptWrappedInput: true). The reader unwraps only flagged parts that are still exactly that one-key object, so Codex → OpenCode → back restores the original input, while a genuine {"input": …} tool input is left alone.

Tests

  • New tests/regression/codex_code_mode.rs covers results, failure flagging, and the OpenCode wrap/unwrap round trip; it fails on main and passes here.
  • cargo fmt --check, cargo clippy --workspace --all-targets --all-features -D warnings, and cargo test --workspace --all-features pass.
  • End-to-end against the real Codex 0.169.0, Claude Code 2.1.326 and OpenCode CLIs: the code-mode export, convert and resume checks into Claude Code, pi and OpenCode now pass.

Try it

Run a Codex session that uses code mode, then txcript export <id> --from codex or txcript continue <id> --from codex --with opencode; the exec results are present and the import succeeds.

…opencode

Codex code mode writes custom_tool_call_output.output as an array of
input_text content items; the reader only accepted strings, so the result
was dropped for every target. Collapse all-text item lists to text (keep
other lists as JSON) for both custom_tool_call_output and
function_call_output.

The OpenCode writer passed a non-object tool input (the raw JS of an exec
call) into state.input, which opencode import rejects. Wrap it as
{"input": ...}, matching the Claude Code export.

Fixes #104
…from opencode

Follow-ups to #104.

Codex never writes a call's `success` flag to the rollout; a content-item
list serializes as the bare array. For code mode the only on-disk failure
signal is the status header Codex inserts as the first item
("Script failed\nWall time ... seconds\nOutput:\n"). Array results in
custom_tool_call_output and function_call_output now set is_error from
that header (matched whole, so script output that merely starts with the
words is not mistaken for it); lists without it stay non-errors.

The OpenCode writer wraps a non-object tool input as {"input": <value>}
because `opencode import` requires an object. It now flags that wrap in
state.metadata (txcriptWrappedInput: true), and the reader unwraps only
flagged parts whose input is still exactly that one-key object, so
Codex -> OpenCode -> common restores the original freeform input while a
genuine {"input": ...} tool input is left untouched.
@NishantJoshi00
NishantJoshi00 merged commit d43ab8b into main Nov 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex code-mode tool calls (custom_tool_call with a string input) break conversion to opencode and lose the result for claude_code

1 participant