[code-mode] outer `exec` truncates aggregated results despite higher nested budgets, causing token waste and retry churn

Open
#33,402 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
javascript, rust

Research direction

Start by reproducing the code-mode programmatic exec flow with parallel nested exec_command calls, comparing aggregated output with and without the // @exec max_output_tokens pragma. Trace the outer budget and result serialization through the generated tool call and rollout JSONL; done means requested nested output is not unexpectedly discarded, or the truncation warning clearly identifies the outer limit and how to raise it.

Written by the indexing model from the issue text.

Description

app-server bug CLI rate-limits tool-calls
What version of Codex CLI is running?

0.144.3

What subscription do you have?

Pro

Which model were you using?

gpt-5.6-sol

What platform is your computer?

Linux 5.15.167.4-microsoft-standard-WSL2 x86_64 x86_64

What terminal emulator and version are you using (if applicable)?

WSL

What issue are you seeing?

When Codex uses the new code-mode/programmatic exec tool to compose multiple nested exec_command calls, each nested command can specify a large max_output_tokens value, but the combined result is still truncated by a separate 10,000-token outer exec limit.

In my session, Codex generated four parallel exec_command calls with limits between 12,000 and 30,000 tokens, then emitted their results using:

for (const x of r) text(x);

The combined output contained 13,343 tokens, but the resulting custom_tool_call_output reported:

Warning: truncated output (original token count: 13343)

The nested limits do not propagate to the surrounding programmatic exec. Avoiding the truncation requires a separate first-line pragma:

// @exec: {"max_output_tokens": 20000}

Codex generated the tool call itself but omitted this pragma, despite deliberately assigning higher budgets to the nested commands. It also serialized complete result objects with text(x) instead of emitting only text(x.output), increasing the aggregate token count.

This can discard repository documentation, search results, or command output that Codex explicitly requested and may cause it to reason from incomplete information. The user may not notice beyond the truncation warning in the tool result, and there is currently no apparent configuration setting for changing the outer code-mode default.

What steps can reproduce the bug?
  1. Start a Codex app-server session using code mode/programmatic tool calling.
  2. Ask Codex to inspect multiple files or run multiple searches in parallel, where the combined output exceeds 10,000 tokens.
  3. Observe a generated tool call similar to:
const results = await Promise.all([
  tools.exec_command({
    cmd: "seq 1 7000",
    max_output_tokens: 20000
  }),
  tools.exec_command({
    cmd: "seq 7001 14000",
    max_output_tokens: 20000
  })
]);

for (const result of results) text(result);
  1. Do not add an outer // @exec pragma.
  2. Inspect the resulting custom_tool_call_output in the rollout JSONL.
  3. The nested commands allow more than 10,000 tokens, but their combined result is truncated to the outer default and contains a warning such as:
Warning: truncated output (original token count: ...)
  1. Repeat with this first line:
// @exec: {"max_output_tokens": 30000}

The outer result is no longer truncated at 10,000 tokens, assuming it remains below the requested budget.

Observed with:

codex-cli 0.144.3
model: gpt-5.6-sol
interface: app-server
What is the expected behavior?

Codex should not unexpectedly discard aggregated output when it generated nested calls with explicit output budgets larger than the outer default.

Any of the following would address the problem:

  • Codex reliably adds an outer max_output_tokens pragma when aggregating potentially large nested results.
  • The outer budget is derived from the actual or requested nested output budgets, subject to a documented safety cap.
  • The default outer code-mode limit is configurable.
  • max_output_tokens is exposed as a normal structured parameter instead of only through a source-code pragma.
  • Generated aggregation emits only necessary fields such as result.output, avoiding unnecessary JSON serialization.
  • If truncation still occurs, the warning explicitly identifies the outer code-mode aggregate limit and explains how to raise it.

At minimum, the model-generated call and the tool contract should be aligned so that Codex does not request large nested outputs and then unintentionally truncate them at a separate outer layer.

Additional information

No response

Dominant language
Rust
Stars
125k
Forks
19.5k
Avg merge
1m
Merged PRs (30d)
1k

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openai/codex

All issues in openai/codex

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.