Skip to content

feat(tracing): surface nested exec command exit codes as child tool spans - #123

Closed
MaelRB wants to merge 1 commit into
langfuse:mainfrom
MaelRB:feat/nested-exec-exit-codes
Closed

MaelRB wants to merge 1 commit into
langfuse:mainfrom
MaelRB:feat/nested-exec-exit-codes

Conversation

@MaelRB

@MaelRB MaelRB commented Oct 23, 2026

Copy link
Copy Markdown

Problem

In Codex code mode, one exec tool call can run several commands. The output has one JSON part per command, with that command's exit_code:

{"chunk_id":"a4b7b0","wall_time_seconds":0.0,"exit_code":2,"output":"rg: path: No such file or directory ..."}

The exec span is DEFAULT because the script itself finished. A failing command inside it is only visible in the output text. Filtering or alerting on level misses it.

Change

  • Parsing: extractNestedResults (in parse.ts) reads text parts of function_call_output / custom_tool_call_output that are JSON objects with a numeric exit_code. It skips non-JSON or malformed parts without throwing.
  • Child spans: emitToolCall adds one exec_command child tool span per nested result, with codex.exit_code (and codex.chunk_id when present) as metadata and the nested output.
    • exit_code >= 2: ERROR, with a status message.
    • exit_code 0 or 1: DEFAULT. rg and grep use 1 for "no match".
  • Parent span: level and status message are unchanged. It gets codex.nested_failed_count, but only when that count is above zero.

Tests

  • parse.test.ts: the extraction cases, including malformed parts.
  • trace.test.ts:
    • an exit-2 child is ERROR with its chunk id and output;
    • an exit-1 child is not ERROR;
    • the parent level and status are unchanged;
    • nothing is emitted when no part can be parsed.

pnpm run lint and pnpm test pass (125/125). I also ran the parser on a real Codex rollout: the failing nested rg came out as exit code 2.

🤖 Generated with Claude Code

…pans

Codex code-mode `exec` outputs carry one JSON part per nested command with
its `exit_code`. The parent tool span stays DEFAULT because the script itself
completed, so a nested failure (for example `rg` on a missing path, exit 2) is
invisible to level-based monitoring.

Emit an `exec_command` child tool span per nested result with
`codex.exit_code` (and `codex.chunk_id`). Exit codes >= 2 are ERROR; exit 1
stays DEFAULT because rg/grep use it for "no match". The parent keeps its own
level and status and gets `codex.nested_failed_count` when it is non-zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@MaelRB MaelRB closed this Oct 23, 2026
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.

1 participant