Skip to content

agent: tell the model when bash output was truncated - #680

Open
JonasColmsjo wants to merge 1 commit into
antirez:mainfrom
JonasColmsjo:announce-truncated-bash-output
Open

agent: tell the model when bash output was truncated#680
JonasColmsjo wants to merge 1 commit into
antirez:mainfrom
JonasColmsjo:announce-truncated-bash-output

Conversation

@JonasColmsjo

Copy link
Copy Markdown

Problem

agent_bash_observation() clips long bash output to a <head -N file> or
<tail -N file> block and prints output_path=..., but it never states that
anything was dropped. The model has to infer truncation from the tag name alone.

Larger models usually make that inference. Smaller/quantized ones do not — they
read the fragment as the complete output and answer confidently from a partial
result. I hit this with a command whose answer depended on its last line: the
model saw the first 100 of 5000 lines and never realised the rest existed.

The full output is already on disk and the read tool can open it. Nothing told
the model it needed to.

Change

After the head/tail block, emit one line stating how many of how many lines were
shown and naming the file to read, and document the convention in the tools
system prompt so the model knows head/tail blocks are never the whole output.

Warn only on real truncation. The head branch is also taken while a job is still
running, and at that point nothing has been dropped — warning there would claim
"the first 5 of 5 lines" and teach the model to distrust output that is intact.

The warning goes into the model-visible observation. The terminal echo path
(agent_bash_publish_observation()) still publishes only the head/tail body, so
interactive output is unchanged.

Verification

Built with make cuda-spark (GB10 / sm_121), no new warnings, and exercised
against DeepSeek-V4-Flash on a DGX Spark:

  • seq 1 5000 — model quotes back:
    WARNING: output truncated. Only the first 100 of 5000 lines are shown above; the rest was NOT shown. Read /tmp/ds4_agent_output_SBvTZt before drawing conclusions that depend on the full output.
  • seq 1 5 — model reports NO-WARNING (no false positive on short output)

In agent runs the model then reads output_path instead of guessing.

agent_bash_observation() clips long output to a <head -N file> or
<tail -N file> block and prints output_path, but never states that
anything was dropped. The model is left to infer truncation from the
tag name alone, and smaller models do not make that inference: they
read the fragment as the complete output and answer confidently from
a partial result. Observed with a 5000-line command whose last line
decided the answer.

The full output is already on disk and the read tool can open it, so
the fix is only to say so. After the head/tail block, emit a line
stating how many of how many lines were shown and naming the file to
read, and document the convention in the tools system prompt.

Warn only on real truncation. The head branch is also taken while a
job is still running, and at that point nothing has been dropped --
warning there would claim "the first 5 of 5 lines" and teach the
model to distrust output that is intact.

The warning goes into the model-visible observation. The terminal
echo path (agent_bash_publish_observation) still publishes only the
head/tail body, so interactive output is unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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