Skip to content

fix: configurable terminal output truncation to prevent context window blowup#1695

Open
darksider4all wants to merge 1 commit into
agent0ai:mainfrom
darksider4all:fix/configurable-output-truncation
Open

fix: configurable terminal output truncation to prevent context window blowup#1695
darksider4all wants to merge 1 commit into
agent0ai:mainfrom
darksider4all:fix/configurable-output-truncation

Conversation

@darksider4all

Copy link
Copy Markdown

Problem

fix_full_output() in code_execution_tool.py had a hardcoded truncation threshold of 1,000,000 characters (~1MB / ~250K tokens). A single large command output (e.g., recursive grep through minified JS) could fill the entire LLM context window, crashing the session.

Root Cause

File: plugins/_code_execution/tools/code_execution_tool.py, line 475:
python
output = truncate_text_agent(agent=self.agent, output=output, threshold=1000000)

Fix

Made the threshold configurable via plugin settings with a sensible default of 30,000 characters (~7.5K tokens):

Changes

  1. default_config.yaml — Added config option:
    yaml
    max_output_chars: 30000

  2. code_execution_tool.pyfix_full_output() reads from config:
    python
    cfg = _get_config(self.agent)
    max_chars = cfg.get("max_output_chars", 30000)
    output = truncate_text_agent(agent=self.agent, output=output, threshold=max_chars)

  3. _get_config() — Added key:
    python
    "max_output_chars": int(cfg.get("max_output_chars", 30000)),

Impact

Metric Before After
Max output 1,000,000 chars (1MB) 30,000 chars (~30KB)
≈ Token cost ~250K tokens ~7.5K tokens
Configurable No (hardcoded) Yes (per-agent, per-project)
Risk of context blowup High Eliminated

Backwards Compatibility

Fully backwards compatible — agents/projects that need more output can set max_output_chars to a higher value in their plugin config.

Root cause: fix_full_output() had hardcoded 1M char threshold (~250K tokens).
A grep through minified JS produced 1MB output, exceeding LLM context limits.

Changes:
- Add max_output_chars config (default: 30000 chars ~ 7.5K tokens)
- Patch fix_full_output() to read from plugin config
- Add max_output_chars to _get_config()

Also patched usr/plugins/tree_sitter (local, gitignored) with
.gitignore awareness + default ignore dirs for build_index.
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