Skip to content

fix(read): report MAX_BYTES cap independently when both MAX_LINES and MAX_BYTES are hit#216

Open
LifeJiggy wants to merge 2 commits into
MoonshotAI:mainfrom
LifeJiggy:fix/read-tool-dual-cap-message
Open

fix(read): report MAX_BYTES cap independently when both MAX_LINES and MAX_BYTES are hit#216
LifeJiggy wants to merge 2 commits into
MoonshotAI:mainfrom
LifeJiggy:fix/read-tool-dual-cap-message

Conversation

@LifeJiggy
Copy link
Copy Markdown

What does this PR do?

  1. Read tool status now reports both caps when both are hit. The finishMessage() method used else if for the maxLinesReached, maxBytesReached, and end-of-file conditions. When a file exceeded both MAX_LINES (1000) and MAX_BYTES (100 KiB) simultaneously — e.g. a file with many long lines — only the line cap was reported, silently hiding the byte cap from the model. Changed to independent if statements so both limits are reported when both are triggered. The EOF message only appears when neither limit was reached.

Related Issue

Fixes #94

Changes Made

  • packages/agent-core/src/tools/builtin/file/read.ts — Changed else if (input.maxBytesReached) to independent if (input.maxBytesReached). Changed EOF condition to guard on !input.maxLinesReached && !input.maxBytesReached.
  • packages/agent-core/test/tools/read.test.ts — Added test reports both MAX_LINES and MAX_BYTES when both caps are hit that creates a file exceeding both limits and asserts both cap messages appear.

How to Test

  1. Run the full read tool test suite: pnpm --filter @moonshot-ai/agent-core exec vitest run test/tools/read.test.ts

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

🦋 Changeset detected

Latest commit: abc3b53

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/agent-core Patch
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@LifeJiggy LifeJiggy force-pushed the fix/read-tool-dual-cap-message branch from 863a223 to 1d094d6 Compare May 29, 2026 11:53
LifeJiggy added 2 commits May 29, 2026 12:54
… MAX_BYTES are hit

The finishMessage method used else-if chaining for the maxLinesReached,
maxBytesReached, and end-of-file conditions. When a file exceeded both
MAX_LINES and MAX_BYTES simultaneously, only the line cap was reported,
silently hiding the byte cap from the model.

Changed the conditions to independent if statements so both limits are
reported when both are triggered. The EOF message now only appears when
neither limit was reached.

Fixes MoonshotAI#94
@LifeJiggy LifeJiggy force-pushed the fix/read-tool-dual-cap-message branch from 1d094d6 to abc3b53 Compare May 29, 2026 11:54
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.

Read tool status message omits MAX_BYTES cap when MAX_LINES is also hit

1 participant