Skip to content

No global cap on tool result size #769

Closed

Description

@will-lamerton

Problem

There is no global ceiling on how large a tool result can be. Only two tools truncate at all:

  • source/tools/execute-bash.tsx:50-54 (head-only, 2000 chars)
  • source/custom-tools/handler.ts:100-101 (head-only, same constant)

Everything else is unbounded, including:

  • read_file with an explicit range covering a huge file
  • string_replace and write_file, which return the whole post-edit file
  • git_diff (source/tools/git/git-diff.tsx:71), which returns full diff content plus a [Total: N lines] footer
  • list_directory recursive listings
  • MCP tool results, which we do not control at all

A single large diff or a recursive listing of a big tree can dominate the context window, and because tool results persist in the conversation, the cost is re-sent on every subsequent step.

Proposal

Add one choke point that caps any tool result before it enters the conversation, with head-plus-tail elision and a clear marker telling the model what was dropped and how to get it.

Making it structural rather than per-tool means unbounded output becomes impossible by construction, and it covers MCP and custom tools that we do not own.

Design questions worth settling on the issue:

  • Where the choke point lives. ToolManager is the natural place since it already wraps every tool including MCP and custom ones.
  • Whether the cap should be a fixed character count or a share of the model's context window. The latter is better but needs the context size plumbed through.
  • Whether some tools should be exempt or get a higher ceiling.
  • Whether the elided content should be recoverable, for example written to a temp file the model can read a range from.

Related

Several individual uncapped tools have their own issues. This one is the structural fix that would make those individually less critical, but it is more invasive, so the per-tool fixes are probably worth landing first.

Activity

  1. added
    enhancement
    architecture
    on Aug 3, 2026
  2. will-lamerton commented on Aug 3, 2026

    @will-lamerton
    MemberAuthor

    Part of #772.

  3. RealBhupesh commented on Aug 4, 2026

    @RealBhupesh
    Contributor

    I'd like to take this issue.

    Plan:

    • add a shared head-and-tail truncation helper with a bounded character budget and an actionable elision marker;
    • apply it at the central tool execution boundary so built-in, MCP, and file-based custom tools are covered;
    • cover the interactive message-builder path as well, since streaming Bash and subagent results can bypass the normal handler;
    • add focused regression tests and a patch changeset;
    • run the focused tests plus the repository validation checks before opening a ready-for-review PR.

    I'll keep structured tool payloads intact and cap only the LLM-facing text content.

  4. RealBhupesh commented on Aug 4, 2026

    @RealBhupesh
    Contributor

    Implemented and submitted as ready-for-review PR #786: #786

    What changed:

    • Added a shared 20,000-character cap that preserves both the beginning and actionable tail of oversized tool output.
    • Applied it to normal tool handlers, optimized interactive MessageBuilder flows, and direct subagent execution.
    • Kept structured tool payloads intact while bounding only the LLM-facing text.
    • Added focused regression tests and a patch changeset.

    Validation:

    • Focused regression suite: 66 passed
    • Types, formatting, lint, unused-dependency, audit, and diff checks: passed
    • The full suite has one unrelated existing failure at source/app/components/settings-tabs.spec.tsx:109 because the baseline test expects the Display tab.

    The PR is open and ready for maintainer review; GitHub Actions checks are currently queued.

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

    architectureenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions