Skip to content

[BUG] Tool results sent to the LLM are right-padded to the widest line #1590

Closed

Description

@edenreich

Summary

Every tool result sent to the LLM is right-padded with spaces to the widest line of the result. FormatToolResultForLLM renders the result through the lipgloss tree in renderExpandedTree (internal/tools/formatter.go), and lipgloss.JoinHorizontal pads every line of a block to the block's widest line. A Read of a file with one long line turns every other line of that file into a line of that length. Split out of #1586, where this accounts for most of the gap between the compaction estimate and the provider's prompt_tokens.

Steps to Reproduce

  1. Build a ToolExecutionResult for Bash with an output of "short\n" + 120 x "x" + "\nalso short\n".
  2. Render it with tools.BaseFormatter{}.FormatExpanded(result, body) (what FormatForLLM calls).
  3. Measure the rune length of each line of the Result: block.

Expected Behavior

Lines keep their own length. short is 4 + 5 runes with the tree indent.

Actual Behavior

Every line of the block is 124 runes:

124 "╰── Result:                         …"
124 "    Exit Code: 0                    …"
124 "    short                           …"
124 "    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx…"

On the run in #1586, 58 tool results with 296k chars of content became 1.33M chars once padded. The padding is sent to the provider on every request, and the chars/4 estimate counts it at full weight, which is why estimateTriggerTokens crossed 500k while the provider reported 231k.

Activity

  1. added
    bug
    on Oct 20, 2026
  2. added theissue type on Oct 20, 2026
  3. moved this from Todo to QA in 2026on Oct 20, 2026
  4. moved this from QA to Done in 2026on Oct 20, 2026
  5. inference-gateway-releaser commented on Oct 20, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.234.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

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

    bugreleased

    Type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions