Skip to content

Conversation

@Skyline-23
Copy link

@Skyline-23 Skyline-23 commented Jan 20, 2026

Summary

  • switch global tool output truncation from byte limits to token budgets
  • update Read tool truncation messaging to token-based limits
  • align bash tool help text and truncation tests with token limits

Testing

  • bun test test/tool/truncation.test.ts
  • bun test test/tool/bash.test.ts

References

Copilot AI review requested due to automatic review settings January 20, 2026 16:13
@github-actions
Copy link
Contributor

Hey! Your PR title Switch tool truncation to token-based limits doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search results, I found some related PRs that deal with output limits and truncation, but none appear to be direct duplicates of PR #9648. Here are the potentially related PRs:

Related PRs (not duplicates):

  1. PR feat(opencode): add context overflow prevention with configurable thresholds #8810 - feat(opencode): add context overflow prevention with configurable thresholds

    • Related to managing tool output and context limits, but appears to be about overflow prevention rather than token-based truncation
  2. PR fix(grep): stream ripgrep output to prevent memory exhaustion #5432 - fix(grep): stream ripgrep output to prevent memory exhaustion

    • Related to managing tool output size, but focused on grep/ripgrep specifically
  3. PR feat: add file persistence for large tool outputs #6234 - feat: add file persistence for large tool outputs

    • Related to handling large tool outputs, but uses file persistence approach rather than token-based limits

These PRs address related concerns about tool output management, but none appear to be duplicate work on the same token-based truncation feature that PR #9648 implements.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request switches the tool output truncation system from byte-based limits to token-based limits for more accurate context management. The token estimation uses a simple 4 characters per token approximation.

Changes:

  • Replaced MAX_BYTES (50KB) with MAX_TOKENS (10,000) as the default truncation limit
  • Updated truncation logic to use Token.estimate() instead of Buffer.byteLength()
  • Updated user-facing messages in Read and Bash tools to reference tokens instead of bytes

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/opencode/src/tool/truncation.ts Core implementation: renamed constants, options, and variables from byte-based to token-based; replaced byte counting with token estimation
packages/opencode/src/tool/read.ts Updated Read tool to use token-based truncation and updated user-facing messages to reference tokens
packages/opencode/src/tool/bash.ts Updated template variable replacement from maxBytes to maxTokens
packages/opencode/src/tool/bash.txt Updated help text to reference token limits instead of byte limits
packages/opencode/test/tool/truncation.test.ts Updated test descriptions and assertions to use token-based expectations; added Token import
packages/opencode/test/tool/bash.test.ts Updated truncation test to generate token-based test data

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Skyline-23 Skyline-23 changed the title Switch tool truncation to token-based limits feat(opencode): switch tool truncation to token-based limits Jan 20, 2026
@Skyline-23
Copy link
Author

Updated the PR title to conventional format and added Fixes #9045 in the description.

@Skyline-23 Skyline-23 force-pushed the perf/token-truncation branch from d11838e to 6dd40a4 Compare January 21, 2026 03:05
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.

Codex model response latency increases significantly as conversation grows

1 participant