Skip to content

Workers should auto-truncate large tool outputs to prevent context overflow #504

@vsumner-spacebot

Description

@vsumner-spacebot

Feature Request / Improvement

Workers that run shell commands with large outputs (e.g., journalctl, cat, find) can easily fill the model's context window. There is no automatic truncation of tool results before they are sent to the LLM, causing model_context_window_exceeded errors (see related issue about non-retriable context overflow).

Current Behavior

  • Shell tool returns full stdout/stderr to the worker's context
  • A single journalctl --no-pager -n 500 can produce 100KB+ of text
  • Multiple large tool results accumulate and exceed the context window
  • Worker fails with context overflow (related: retries are wasted on non-retriable error)

Proposed Behavior

  • Implement automatic truncation of large tool outputs (e.g., max 4000-8000 characters per tool result)
  • When truncation occurs, append a note: [Output truncated: N characters omitted. Use pagination or filtering to see more.]
  • Allow per-tool configuration of max output size (e.g., shell tool might have a higher limit than file_read)
  • Consider adding a context usage check before API calls — if approaching the limit, proactively summarize oldest tool results

Impact

  • Prevents context overflow from killing workers mid-task
  • Reduces token usage and API costs
  • Makes workers more reliable for log analysis and system administration tasks
  • Complements the non-retriable context overflow fix

Examples Where This Would Help

  • journalctl -u spacebot --no-pager --since "2026-03-21" — easily 50-100KB
  • find / -name "*.log" — can produce thousands of lines
  • cat /var/log/some-service.log — unbounded file size
  • Multiple parallel curl responses with large JSON bodies

Environment

  • Spacebot version: 0.3.3
  • Model: zai_anthropic/glm-5-turbo (128k context but fills fast with raw logs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions