Skip to content

@openai/codex-sdk: TS item types drifted from exec JSONL wire format #53017

Open

Description

@nosmile99

The hand-maintained sdk/typescript/src/items.ts (header: "based on item types from codex-rs/exec/src/exec_events.rs") has drifted from what codex exec --experimental-json actually emits. All four gaps below were verified against current main Rust sources and with tsc — the SDK rejects each shape.

  1. collab_tool_call missing from ThreadItem — the wire format emits it for subagent activity (ThreadItemDetails::CollabToolCall in exec_events.rs, mapped in event_processor_with_jsonl_output.rs), but TS consumers must cast to any to handle official SDK events. Same root cause as @openai/codex-sdk: ThreadItem type missing collab_tool_call #28318 (no fixing PR exists).
  2. CommandExecutionStatus missing "declined" — event_processor_with_jsonl_output.rs maps CommandExecutionStatus::Declined into the JSONL output.
  3. PatchApplyStatus missing "in_progress" — event_processor_with_jsonl_output.rs maps PatchApplyStatus::InProgress into the JSONL output.
  4. WebSearchItem missing action and results — added to the wire format by Preserve web search actions and results in exec JSON output #46319 (WebSearchAction + results: Option<Vec<JsonValue>> in exec_events.rs); the SDK was never synced.

I have a ready fix on branch codex-sdk-wire-type-sync in nosmile99/codex (commit c2ce059; compares cleanly against main, no conflicts) that:

  • adds exported CollabToolCallItem, CollabToolCallStatus, CollabTool, CollabAgentStatus, CollabAgentState and puts CollabToolCallItem in the ThreadItem union;
  • adds "declined" to CommandExecutionStatus and "in_progress" to PatchApplyStatus;
  • adds action: WebSearchAction and results?: unknown[] to WebSearchItem, with WebSearchAction mirroring the Rust serde shape (search / open_page / find_in_page / other, snake_case tag);
  • adds tests/wireTypeSync.test.ts: wire-shaped fixtures (including the runtime example from @openai/codex-sdk: ThreadItem type missing collab_tool_call #28318) that fail to compile via ts-jest diagnostics if the types drift again.

Verified: new suite 5/5 green, pre-existing tests/exec.test.ts 14/14 green, eslint + prettier clean; the new suite fails against the pre-fix types (negative control). I could not open a PR because this repo restricts PR creation to collaborators — happy for a maintainer to pull the branch, or I can re-submit it as a PR if the restriction is lifted.

Activity

  1. added
    bug
    CLI
    exec
    subagent
    on Oct 11, 2026
  2. argszero commented on Oct 11, 2026

    @argszero

    Verified all four against main @ cc7ba33601, and swept the rest of the mirror for the same class of gap. All four are real, and the fix scope is exactly these two files.

    Claim-by-claim

    1. collab_tool_call — ThreadItemDetails has 9 variants (exec_events.rs:107-133), the TS union has 8 (items.ts:120-128). Emission site: event_processor_with_jsonl_output.rs:246. Confirmed.
    2. declined — CommandExecutionStatus is 4 variants (exec_events.rs:151-157), items.ts:6 lists 3. Confirmed.
    3. in_progress — PatchApplyStatus is 3 (exec_events.rs:178-182), items.ts:32 lists 2. Confirmed.
    4. action / results — WebSearchItem is {id, query, action, results} (exec_events.rs:298-306), items.ts:90-94 has neither. Confirmed, and your proposed shape is right on the subtle part: action: WebSearchAction is required (not an Option, no skip_serializing_if, so always emitted) while results carries skip_serializing_if/#[ts(optional)] and is the only genuinely optional field. Your WebSearchAction also matches the source: models.rs:2066-2092 is #[serde(tag = "type", rename_all = "snake_case")] with Search { query?, queries? } / OpenPage { url? } / FindInPage { url?, pattern? } / Other (#[serde(other)]) — note search carries both query and queries.

    What else I checked (the four are complete — nothing else in items.ts drifted)

    Field-by-field against the Rust structs: PatchChangeKind, McpToolCallStatus, CollabTool/CollabToolCallStatus/CollabAgentStatus/CollabAgentState, McpToolCallItem's fields, TodoItem/TodoListItem, ErrorItem, AgentMessageItem, ReasoningItem — all in sync. And events.ts is fully in sync: all 8 ThreadEvent arms and all 5 Usage fields including cache_write_input_tokens (exec_events.rs:61-73). So the surface to fix is items.ts only, which should keep the patch small.

    One divergence the four don't cover, and the proposed patch keeps

    exit_code is null, not absent. exec_events.rs:164 declares pub exit_code: Option<i32> with no skip_serializing_if and no #[ts(optional)], and the emit path is plain serde_json::to_string(&event) (event_processor_with_jsonl_output.rs:108) — so while a command is running the wire carries "exit_code": null, an always-present key. items.ts:17 types it exit_code?: number with the doc "omitted while still running", so item.exit_code !== undefined is wrong against the wire while item.exit_code != null is right. Same asymmetry for McpToolCallItem.result and .error (exec_events.rs:291-292 vs items.ts:61,67: both serialize as null, both typed ?). Fixture-based type tests won't catch this class, because the undefined check still compiles.

    The structural point

    exec_events.rs derives ts_rs::TS on every type in the file, and codex-rs/exec/Cargo.toml:61 depends on ts-rs v11 — ts-rs renders that field as exit_code: number | null, so the hand-written mirror already disagrees with a generator wired to the source. exec just never got an export step, which is why items.ts carries the hand-copy header.

    The repo does have a complete pattern for this, in app-server-protocol:

    • export.rs:123 generate_ts_with_options / :132-140 export_all_to, with #[ts(export_to = "v2/")] markers on the types;
    • precomputed_exports.rs — a precomputed snapshot (GENERATED_TS_HEADER = "// GENERATED CODE! DO NOT MODIFY BY HAND!", served from schema/precomputed/*.json.zst) so the check needs no Rust run;
    • schema_fixtures_tests.rs:19-37 typescript_schema_fixtures_match_generated — a drift guard that reads the committed fixture tree and diffs it against freshly generated output (assert_schema_trees_match), wired into nextest at codex-rs/.config/nextest.toml:67.

    That is the shape that would end this class of bug for exec, rather than a third hand-sync. Flagging it as the follow-up rather than something to bundle here.

    History of this exact surface

    Nuance worth putting in the type once you add it

    The collab mapping is conditional in a way the type can't express: CollabAgentTool::SendMessage, FollowupTask, InterruptAgent, ListAgents and status Interrupted all return None, i.e. no item is emitted at all (event_processor_with_jsonl_output.rs:248-251, :299), and CollabAgentTool::ResumeAgent is folded into CollabTool::Wait (:254) — so the wire only ever carries spawn_agent/send_input/wait/close_agent with in_progress/completed/failed, matching your proposed enum. A short comment there is worth it, since wait is two source tools and the absent cases are invisible from the types alone.

    I hit the same wall on PR creation, so I can't submit this either. If it helps, I can re-run this comparison against a newer main once the branch is rebased, or check whether the export/snapshot shape from app-server-protocol transfers cleanly to exec.

  3. nosmile99 commented on Oct 11, 2026

    @nosmile99
    Author

    Thanks for the thorough verification — your claims-by-claim check is even deeper than the issue.

    I folded the extra divergence you found into the fix branch:

    • exit_code: number | null — always present on the wire, null while running (never omitted); same for McpToolCallItem.result / .error (always present, null until settled). The type doc now says to check == null, not === undefined.
    • Collab mapping comment added, noting the conditional emission (SendMessage/FollowupTask/InterruptAgent/ListAgents/Interrupted never emitted; ResumeAgent folded into wait).
    • wireTypeSync fixtures extended: declined/running command item with exit_code: null, plus a dedicated always-present-null test. 6/6 green, lint clean.

    On the structural point I agree: the app-server-protocol export/snapshot + drift-guard shape is the right end-state for exec, and that belongs as a follow-up rather than bundled here.

    The branch is updated at nosmile99/codex@codex-sdk-wire-type-sync (now 56421a3) if you want to pull it — happy to rebase it or run the comparison against a newer main whenever that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIbugexecsubagent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions