Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/TASK_DEFINITION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ types accept it, in what range, what each does with it and what an unset value m
[Run-Limit Parity](agents/HARNESS_PARITY.md#the-context-window-cap-per-harness). An agent
type that cannot apply it rejects it at load.

**`tool_output_token_limit`** (codex only, default `10000`) caps, in tokens, each tool
output Codex shows the model. Override via CLI with `-D agent.tool_output_token_limit=5000`.
See [Codex](agents/CODEX.md#tool-output-cap).

**Permission Modes:**
- `default` — Default permission handling
- `acceptEdits` — Auto-accept file edits (recommended for evaluations)
Expand Down
24 changes: 24 additions & 0 deletions docs/agents/CODEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,30 @@ uses it as the model's context window, capped to the model's catalog maximum, an
auto-compacts at 90% of it. See
[Harness parity](HARNESS_PARITY.md#the-context-window-cap-per-harness).

### Tool Output Cap

`agent.tool_output_token_limit` (Codex only, default `10000`, range 1024-1000000) is passed
as `tool_output_token_limit` in the thread `config`. Codex cuts each tool output it shows the
model to this many tokens, keeping the head and the tail. The default is the cap that Codex
gives the models in its own catalog. Without it, a model that the catalog does not know gets
a fallback cap of 10,000 bytes, about a quarter of the size, so a newer model would see less
of each command output than an older one. The value is recorded in the run's `agent_config`.

Command output has a second cap. The exec tool cuts it to the `max_output_tokens` the model
may pass in each call, 10000 tokens when the model passes none, and no Codex config key
raises that default. Command output is therefore capped at the smaller of the two, so a value
above `10000` widens it only in calls where the model asks for more; it applies in full to MCP
and other tool outputs. Such a value logs a warning when the agent starts.

The value overrides a `tool_output_token_limit` in `$CODEX_HOME/config.toml`. Set it to
`null` to let that host value, or else the Codex default for the model, apply. Override it
per run with `-D agent.tool_output_token_limit=5000`.

Records written before this change reload with `tool_output_token_limit` `10000` (the field
default). Before this change Codex applied its own default (10000 tokens for catalog models,
10,000 bytes for models outside its bundled catalog such as `gpt-6.1-sol`), so compare trend
lines across this commit with that in mind.

### Skills Discovery

The agent sets up SKILL.md files (Agent Skills open standard) in `.agents/skills/` directory:
Expand Down
7 changes: 7 additions & 0 deletions docs/agents/HARNESS_PARITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,13 @@ uncapped under a "capped" label is a wrong measurement.
- Neither harness reports when the model's own window has lowered the cap. A cap
above the model's window runs at the model's window.

`agent.tool_output_token_limit` is a related Codex-only knob and is not shared: it caps,
in tokens, each tool output Codex shows the model (default `10000`, passed in the thread
config). Unlike `context_window`, it is set by default, so a `tool_output_token_limit` in
`$CODEX_HOME/config.toml` is overridden; set it to `null` to let the host value apply.
Claude Code caps Bash output with its own mechanism, so the same number does not mean the
same cap there. See [Codex](CODEX.md#tool-output-cap).

## `agent.plugins[].path` accepts different depths per harness

Not a run limit, but the same promise: one task file, three harnesses, same meaning.
Expand Down
14 changes: 14 additions & 0 deletions src/coder_eval/agents/codex_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
# routes to a custom endpoint.
_CUSTOM_PROVIDER_ID = "custom"

# Codex's exec tool caps each command output at the per-call max_output_tokens the model may
# pass, 10000 tokens when it passes none; no Codex config key raises that default.
_EXEC_OUTPUT_TOKEN_CEILING = 10_000

# apply_patch statuses meaning the patch did not apply. Used ONLY to classify the
# Write telemetry honestly, never to fail or retry the turn: "declined" needs an
# approval reviewer, which no permission mode configures, and "failed" (a diff
Expand Down Expand Up @@ -1791,6 +1795,9 @@ def _build_thread_options(self) -> dict[str, Any]:
# Codex then auto-compacts at 90% of this window.
tool_config["model_context_window"] = self.config.context_window

if self.config.tool_output_token_limit is not None:
tool_config["tool_output_token_limit"] = self.config.tool_output_token_limit

if tool_config:
options["config"] = tool_config

Expand All @@ -1805,6 +1812,13 @@ def _log_config_enforcement(self) -> None:
self._log.debug(f"Disallowed tools: {', '.join(self.config.disallowed_tools)}")

self._log.debug(f"Permission mode: {self.config.permission_mode.value}")
limit = self.config.tool_output_token_limit
if limit is not None and limit > _EXEC_OUTPUT_TOKEN_CEILING:
self._log.warning(
f"tool_output_token_limit {limit} is above {_EXEC_OUTPUT_TOKEN_CEILING}: Codex still caps "
+ f"command output at {_EXEC_OUTPUT_TOKEN_CEILING} tokens unless the model asks for more in "
+ "the call; the value applies in full to MCP and other tool outputs."
)
# Fires for EVERY mode, not just bypassPermissions, so operators are not
# misled that plan/acceptEdits/default confine Codex — none of them do.
self._log.warning(
Expand Down
15 changes: 15 additions & 0 deletions src/coder_eval/models/agent_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,21 @@ class CodexAgentConfig(BaseAgentConfig):
# `yes` that loads as 1.
_context_window_range: ClassVar[tuple[int, int | None] | None] = (32_768, None)

tool_output_token_limit: int | None = Field(
default=10_000,
ge=1_024,
le=1_000_000,
description=(
"Cap, in tokens, on each tool output Codex shows the model, passed as Codex's "
"tool_output_token_limit. The default is the cap Codex gives the models in its own "
"catalog; without it, a model the catalog does not know gets a much smaller fallback "
"cap (10,000 bytes). Command output is also capped by the exec tool's own per-call "
"limit (10000 tokens unless the model asks for more), so a higher value applies in "
"full only to MCP and other tool outputs. None leaves the tool_output_token_limit in the "
"host $CODEX_HOME/config.toml, or else Codex's own per-model default."
),
)

def egress_hosts(self, env: Mapping[str, str]) -> tuple[str, ...]:
"""The ``CODEX_BASE_URL`` host when it is forwarded, else ``api.openai.com``.

Expand Down
133 changes: 133 additions & 0 deletions tests/test_codex_tool_output_cap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"""``agent.tool_output_token_limit``: an explicit Codex tool-output cap, not one from Codex's model catalog.

These tests stop at the thread ``config`` coder_eval builds. The openai_codex SDK passes that dict
through unchecked, and the stub app-server in test_codex_provider_binary.py does not report the
effective config or truncate tool output, so a Codex release that renamed or dropped the key
would go unnoticed here.
"""

from __future__ import annotations

import logging
from typing import Any

import pytest
from pydantic import ValidationError

from coder_eval.models import AgentKind, TaskDefinition, parse_agent_config
from coder_eval.orchestration.config_merge import Layer, resolve_root
from coder_eval.orchestration.overrides import OverrideError, apply_overrides, parse_override


def _agent(**config_kwargs: Any) -> Any:
pytest.importorskip("openai_codex")
from coder_eval.agents.codex_agent import CodexAgent

return CodexAgent(parse_agent_config(type=AgentKind.CODEX, model="example-model", **config_kwargs))


def _thread_config(**config_kwargs: Any) -> dict[str, Any]:
return _agent(**config_kwargs)._build_thread_options().get("config", {})


def _task(agent: dict[str, Any]) -> TaskDefinition:
return TaskDefinition.model_validate(
{"task_id": "cap", "description": "d", "initial_prompt": "p", "agent": agent, "success_criteria": []}
)


class TestThreadOptions:
def test_the_default_cap_reaches_codex(self):
assert _thread_config()["tool_output_token_limit"] == 10_000

def test_an_override_reaches_codex(self):
assert _thread_config(tool_output_token_limit=25_000)["tool_output_token_limit"] == 25_000

def test_none_leaves_the_codex_default(self):
assert "tool_output_token_limit" not in _thread_config(tool_output_token_limit=None)


class TestStartWarning:
def test_a_cap_above_the_exec_ceiling_warns_when_the_agent_starts(self, caplog):
agent = _agent(tool_output_token_limit=50_000)
caplog.clear()
with caplog.at_level(logging.WARNING, logger="coder_eval.agents.codex_agent"):
agent._log_config_enforcement()
assert any("still caps command output at 10000" in r.getMessage() for r in caplog.records)

@pytest.mark.parametrize("limit", [None, 5_000, 10_000])
def test_a_cap_at_or_below_the_exec_ceiling_does_not_warn(self, caplog, limit):
agent = _agent(tool_output_token_limit=limit)
with caplog.at_level(logging.WARNING, logger="coder_eval.agents.codex_agent"):
agent._log_config_enforcement()
assert not any("tool_output_token_limit" in r.getMessage() for r in caplog.records)


class TestConfig:
@pytest.mark.parametrize("limit", [0, -1, 10, 1_023, 1_000_001, True, False])
def test_a_cap_out_of_range_or_a_bool_fails_at_load(self, limit):
with pytest.raises(ValidationError, match="tool_output_token_limit"):
parse_agent_config(type=AgentKind.CODEX, tool_output_token_limit=limit)

@pytest.mark.parametrize("limit", [1_024, 1_000_000])
def test_the_bounds_load(self, limit):
assert (
parse_agent_config(type=AgentKind.CODEX, tool_output_token_limit=limit).model_dump()[
"tool_output_token_limit"
]
== limit
)

def test_loading_a_cap_above_the_exec_ceiling_does_not_warn(self, caplog):
with caplog.at_level(logging.WARNING):
config = parse_agent_config(type=AgentKind.CODEX, tool_output_token_limit=50_000)
parse_agent_config(**config.model_dump())
assert not any("tool_output_token_limit" in r.getMessage() for r in caplog.records)

def test_another_harness_rejects_the_field(self):
with pytest.raises(ValidationError, match="tool_output_token_limit"):
parse_agent_config(type=AgentKind.CLAUDE_CODE, tool_output_token_limit=10_000)

def test_the_run_records_the_default(self):
assert parse_agent_config(type=AgentKind.CODEX).model_dump()["tool_output_token_limit"] == 10_000

def test_yaml_null_survives_the_merge(self):
resolved = resolve_root(
"agent",
[
Layer(source="experiment-defaults", patch={"type": "codex"}),
Layer(source="variant", patch={"tool_output_token_limit": None}),
],
)
assert resolved is not None
assert resolved.model_dump()["tool_output_token_limit"] is None

def test_a_variant_switching_away_from_codex_rejects_a_set_cap(self):
with pytest.raises(ValidationError, match="tool_output_token_limit"):
resolve_root(
"agent",
[
Layer(source="task", patch={"type": "codex", "tool_output_token_limit": 20_000}),
Layer(source="variant", patch={"type": "claude-code"}),
],
)

def test_a_variant_switching_away_from_codex_does_not_inherit_the_default(self):
resolved = resolve_root(
"agent",
[Layer(source="task", patch={"type": "codex"}), Layer(source="variant", patch={"type": "claude-code"})],
)
assert resolved is not None
assert "tool_output_token_limit" not in resolved.model_dump()

@pytest.mark.parametrize(("raw", "expected"), [("5000", 5_000), ("null", None)])
def test_a_cli_override_sets_the_cap(self, raw, expected):
task = _task({"type": "codex"})
apply_overrides(task, dict([parse_override(f"agent.tool_output_token_limit={raw}")]))
assert task.agent is not None
assert task.agent.model_dump()["tool_output_token_limit"] == expected

def test_a_cli_override_out_of_range_reads_as_a_clean_error(self):
task = _task({"type": "codex"})
with pytest.raises(OverrideError, match=r"-D agent\.tool_output_token_limit: .*greater than or equal to 1024"):
apply_overrides(task, dict([parse_override("agent.tool_output_token_limit=10")]))
Loading