Skip to content

[BUG] Bound native read_file output by the active context budget #1252

Description

@zoomote

Problem

Native read_file output is limited by line count and per-line characters, but not by the active model's available input budget. The default path can return roughly 4 MB (2,000 lines x 2,000 characters), and an explicit limit can request even more. The complete result is then added to API conversation history, where it can exceed the model context window before recovery can run.

This was reproduced from #648 using the real read_file formatter.

Scope

Bound native textual read_file results before they are added to model-facing history.

  • Derive the available read budget from the active profile's input capacity after accounting for current context, reserved output, and a safety margin.
  • Apply an absolute ceiling so incorrect model metadata cannot permit an unbounded result.
  • Clamp or reject explicit limit values that would bypass the model-facing budget.
  • Preserve useful line-range semantics and include a clear truncation marker with the returned range, original size, and continuation guidance.
  • Cover ordinary text reads and native text extraction paths such as PDF/DOCX.

Acceptance criteria

  • A default read of 2,000 long lines cannot add a multi-megabyte result beyond the calculated budget.
  • An oversized explicit limit cannot bypass the budget.
  • Truncated output tells the model what was omitted and how to request the next range.
  • Existing small-file and partial-read behavior remains unchanged.
  • Focused tests cover long lines, many lines, explicit limits, and extracted text.

Out of scope

  • MCP output limiting
  • Condensation-input sanitization
  • Sliding-window recovery behavior
  • Full-output spill files or resource references
  • Aggregate budgeting across parallel tool calls

Estimate

1 story point. Independently mergeable and non-stacked.

Parent tracking issue: #648

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions