Skip to content

feat(core): dynamic tool output truncation based on context pressure#2572

Open
netbrah wants to merge 1 commit intoQwenLM:mainfrom
netbrah:feat/dynamic-tool-output-truncation
Open

feat(core): dynamic tool output truncation based on context pressure#2572
netbrah wants to merge 1 commit intoQwenLM:mainfrom
netbrah:feat/dynamic-tool-output-truncation

Conversation

@netbrah
Copy link
Copy Markdown
Contributor

@netbrah netbrah commented Mar 21, 2026

What

Make tool output truncation thresholds context-aware. Bump defaults from 25K → 80K chars / 1000 → 2000 lines, with dynamic scaling as context fills up.

Why

The old 25K/1000 defaults were too aggressive early in a session — cutting off useful tool output that the model needs to work with. But keeping a flat 80K budget would be reckless late in a session when context pressure is high.

The fix: scale dynamically based on how full the context window is. Early session → full budget. Late session → shrink proportionally. The model always gets the maximum data it can safely handle at each point in the conversation.

Scaling formulas

  • Char limit: min(4 × remainingTokens, baseThreshold)
  • Line limit: max(500, floor(baseLines × (1 − usageRatio)))

Both read from uiTelemetryService.getLastPromptTokenCount() (already populated by the existing telemetry pipeline) and the model's context window size.

Changes

File What
config.ts (core) Bump defaults, dynamic scaling in getters
config.test.ts Updated default expectation (25K → 80K)
settings.schema.json Updated default values
chatCompressionService.ts Clarifying comment on model-aware window

Test Plan

Existing config.test.ts updated — 79/79 passing. Dynamic scaling verified via getter behavior with uiTelemetryService already wired.

Demo

N/A — internal optimization. Observable via reduced late-session "context too long" errors and richer tool output in early sessions.

Fixes #2566

Increase default truncation thresholds from 25K to 80K chars and
1000 to 2000 lines for better data availability in early sessions.

Thresholds now scale dynamically as the context window fills: char
limit caps at min(4 * remainingTokens, base), line limit scales as
max(500, baseLines * (1 - usageRatio)).

Fixes QwenLM#2566

Made-with: Cursor
@netbrah netbrah force-pushed the feat/dynamic-tool-output-truncation branch from 5296c1a to 32a0dd5 Compare March 22, 2026 04:39
@netbrah netbrah closed this Mar 30, 2026
@netbrah netbrah deleted the feat/dynamic-tool-output-truncation branch March 30, 2026 10:44
@netbrah netbrah restored the feat/dynamic-tool-output-truncation branch March 31, 2026 08:20
@netbrah netbrah reopened this Mar 31, 2026
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.

feat(core): dynamic tool output truncation based on context pressure

1 participant