Skip to content

Mirror: fix: treat maxReadFileLine=0 as unlimited (#5575)#36

Closed
jeremylongshore wants to merge 1 commit intomainfrom
mirror/PR-5575
Closed

Mirror: fix: treat maxReadFileLine=0 as unlimited (#5575)#36
jeremylongshore wants to merge 1 commit intomainfrom
mirror/PR-5575

Conversation

@jeremylongshore
Copy link
Copy Markdown
Owner

Mirror of Kilo-Org#5575

Field Value
Upstream PR #5575
Author @Patel230
Category fix
Tier 2
Size 22 lines, 2 files

This PR mirrors the upstream change for multi-AI review analysis.

Bot Review Tracker

  • CodeRabbit
  • Gemini Code Assist
  • Greptile
  • CodeQL
  • Qodo PR-Agent

Links

Users setting maxReadFileLine to 0 expect it to mean 'no limit',
similar to -1. This fix ensures 0 is treated as unlimited,
preventing errors when using @file mentions with this setting.

Fixes Kilo-Org#5535
@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 15, 2026

Warning

Rate limit exceeded

@jeremylongshore has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 22 minutes and 41 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mirror/PR-5575

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Treat maxReadFileLine=0 as unlimited for backward compatibility

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Treat maxReadFileLine=0 as unlimited, same as -1
• Update validation logic to accept 0 as valid unlimited value
• Modify test to verify 0 reads all file content
• Update error message to reflect new behavior
Diagram
flowchart LR
  A["maxReadFileLine parameter"] --> B{"Value check"}
  B -->|"0 or -1"| C["Treat as unlimited"]
  B -->|"positive integer"| D["Apply line limit"]
  B -->|"invalid"| E["Throw error"]
  C --> F["Read entire file"]
  D --> G["Read up to limit"]
Loading

Grey Divider

File Changes

1. src/integrations/misc/extract-text.ts 🐞 Bug fix +5/-3

Accept 0 as unlimited in validation logic

• Modified validation logic to accept maxReadFileLine=0 as unlimited
• Added check for maxReadFileLine !== 0 alongside existing -1 check
• Updated error message to include 0 as valid unlimited option
• Added inline comments explaining backward compatibility behavior

src/integrations/misc/extract-text.ts


2. src/integrations/misc/__tests__/extract-text-large-files.spec.ts 🧪 Tests +9/-5

Update test to verify 0 as unlimited

• Changed test case from expecting error to expecting unlimited behavior
• Updated test to verify all file content is read when maxReadFileLine=0
• Added assertions to confirm no truncation message appears
• Updated test description to reflect new expected behavior

src/integrations/misc/tests/extract-text-large-files.spec.ts


Grey Divider

Qodo Logo

@github-actions
Copy link
Copy Markdown

Failed to generate code suggestions for PR

@qodo-code-review
Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (1) 📎 Requirement gaps (0)

Grey Divider


Action required

1. No changeset for extractTextFromFile 📘 Rule violation ⛯ Reliability
Description
This PR makes a functional behavior change (treating maxReadFileLine=0 as unlimited) but does not
include an accompanying .changeset/*.md entry. Without a changeset, the user-facing fix may be
missing from release notes/versioning.
Code

src/integrations/misc/extract-text.ts[R66-70]

+	// 0 is treated as unlimited (same as -1) for backward compatibility
+	if (maxReadFileLine !== undefined && maxReadFileLine !== -1 && maxReadFileLine !== 0) {
		if (!Number.isInteger(maxReadFileLine) || maxReadFileLine < 1) {
			throw new Error(
-				`Invalid maxReadFileLine: ${maxReadFileLine}. Must be a positive integer or -1 for unlimited.`,
+				`Invalid maxReadFileLine: ${maxReadFileLine}. Must be a positive integer, 0, or -1 for unlimited.`,
Evidence
PR Compliance ID 7 requires a changeset for non-documentation product/code changes. The diff shows
product code behavior was changed in extractTextFromFile, while the PR metadata indicates only two
files were modified (no .changeset/ addition).

AGENTS.md
src/integrations/misc/extract-text.ts[66-71]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
This PR introduces a functional behavior change but does not include a required Changesets entry under `.changeset/`.

## Issue Context
Per repo compliance, non-documentation/non-internal-tooling changes must include a changeset so the fix is included in release notes and versioning.

## Fix Focus Areas
- .changeset/[new-file].md[1-6]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. 0 semantics inconsistent 🐞 Bug ✓ Correctness
Description
This PR makes extractTextFromFile treat maxReadFileLine=0 as unlimited, but other subsystems treat 0
as “definitions-only/0 lines”, so the same setting can produce contradictory behavior and
unexpectedly inject full file contents into mentions (risking context exhaustion). Aligning
semantics across mentions, read_file, and prompt/tool gating is required.
Code

src/integrations/misc/extract-text.ts[R94-98]

+		// 0 is treated as unlimited (same as -1) for backward compatibility
+		if (maxReadFileLine !== undefined && maxReadFileLine !== -1 && maxReadFileLine !== 0) {
			const totalLines = await countFileLines(filePath)
			if (totalLines > maxReadFileLine) {
				// Read only up to maxReadFileLine (endLine is 0-based and inclusive)
Evidence
extractTextFromFile now explicitly exempts 0 from validation and from the truncation/partial-read
path, effectively making it behave like unlimited. However, the read_file tool and its helper/test
suite document and enforce maxReadFileLine=0 as a special “definitions only” mode (no file content).
File mentions forward the (global) maxReadFileLine setting into extractTextFromFile, so a user
setting of 0 will now cause mentions to read the entire file, contradicting the established
“definitions-only” meaning. Additionally, system prompt/tool building uses maxReadFileLine !== -1 to
decide whether partial reads are enabled; if 0 is now “unlimited”, those gates are also
inconsistent.

src/integrations/misc/extract-text.ts[64-72]
src/integrations/misc/extract-text.ts[92-109]
src/core/tools/ReadFileTool.ts[482-505]
src/core/tools/helpers/tests/truncateDefinitions.spec.ts[15-23]
src/core/mentions/index.ts[193-207]
src/core/mentions/index.ts[287-307]
src/core/task/build-tools.ts[161-172]
src/core/task/Task.ts[4253-4257]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`maxReadFileLine` is a shared setting used by multiple features (mentions, read_file tool, system prompt/tool building). In this repo, `maxReadFileLine === 0` is already established as a **definitions-only / 0 lines** mode in the read_file tool, but this PR changes `extractTextFromFile` to treat `0` as **unlimited**, which can cause full file contents to be included in file mentions when the global setting is `0`.

## Issue Context
- `extractTextFromFile` is used by the mentions system with the global `maxReadFileLine` value.
- `ReadFileTool` and helper tests explicitly treat `0` as &quot;definitions only mode&quot;.
- Tool/prompt gating treats `maxReadFileLine !== -1` as &quot;partial reads enabled&quot;, which may also need updating if `0` is redefined.

## Fix Focus Areas
Decide on one consistent meaning and implement it across all call sites and docs.

- src/integrations/misc/extract-text.ts[64-109]
- src/core/mentions/index.ts[193-207]
- src/core/mentions/index.ts[287-307]
- src/core/tools/ReadFileTool.ts[482-505]
- src/core/task/build-tools.ts[161-172]
- src/core/task/Task.ts[4253-4257]
- src/core/tools/helpers/__tests__/truncateDefinitions.spec.ts[15-23]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. JSDoc contradicts behavior 🐞 Bug ✓ Correctness
Description
The extractTextFromFile JSDoc still documents only positive integers or -1/undefined for unlimited,
but the implementation now allows 0 as well. This mismatch can mislead callers and maintainers.
Code

src/integrations/misc/extract-text.ts[R66-71]

+	// 0 is treated as unlimited (same as -1) for backward compatibility
+	if (maxReadFileLine !== undefined && maxReadFileLine !== -1 && maxReadFileLine !== 0) {
		if (!Number.isInteger(maxReadFileLine) || maxReadFileLine < 1) {
			throw new Error(
-				`Invalid maxReadFileLine: ${maxReadFileLine}. Must be a positive integer or -1 for unlimited.`,
+				`Invalid maxReadFileLine: ${maxReadFileLine}. Must be a positive integer, 0, or -1 for unlimited.`,
			)
Evidence
The function’s parameter docs say maxReadFileLine must be a positive integer or -1/undefined for
unlimited, but the PR changes runtime validation and error messaging to accept 0. Documentation
should be updated to match whichever unified semantics you choose for 0.

src/integrations/misc/extract-text.ts[57-62]
src/integrations/misc/extract-text.ts[64-72]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`extractTextFromFile` documentation for `maxReadFileLine` no longer matches implementation: code/error messaging now accepts `0` but JSDoc does not.

## Issue Context
This is especially important because `maxReadFileLine` is used as a shared setting across the codebase.

## Fix Focus Areas
- src/integrations/misc/extract-text.ts[53-62]
- src/integrations/misc/extract-text.ts[64-72]
- packages/types/src/global-settings.ts[429-431]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Comment on lines +66 to +70
// 0 is treated as unlimited (same as -1) for backward compatibility
if (maxReadFileLine !== undefined && maxReadFileLine !== -1 && maxReadFileLine !== 0) {
if (!Number.isInteger(maxReadFileLine) || maxReadFileLine < 1) {
throw new Error(
`Invalid maxReadFileLine: ${maxReadFileLine}. Must be a positive integer or -1 for unlimited.`,
`Invalid maxReadFileLine: ${maxReadFileLine}. Must be a positive integer, 0, or -1 for unlimited.`,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. No changeset for extracttextfromfile 📘 Rule violation ⛯ Reliability

This PR makes a functional behavior change (treating maxReadFileLine=0 as unlimited) but does not
include an accompanying .changeset/*.md entry. Without a changeset, the user-facing fix may be
missing from release notes/versioning.
Agent Prompt
## Issue description
This PR introduces a functional behavior change but does not include a required Changesets entry under `.changeset/`.

## Issue Context
Per repo compliance, non-documentation/non-internal-tooling changes must include a changeset so the fix is included in release notes and versioning.

## Fix Focus Areas
- .changeset/[new-file].md[1-6]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +94 to 98
// 0 is treated as unlimited (same as -1) for backward compatibility
if (maxReadFileLine !== undefined && maxReadFileLine !== -1 && maxReadFileLine !== 0) {
const totalLines = await countFileLines(filePath)
if (totalLines > maxReadFileLine) {
// Read only up to maxReadFileLine (endLine is 0-based and inclusive)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

2. 0 semantics inconsistent 🐞 Bug ✓ Correctness

This PR makes extractTextFromFile treat maxReadFileLine=0 as unlimited, but other subsystems treat 0
as “definitions-only/0 lines”, so the same setting can produce contradictory behavior and
unexpectedly inject full file contents into mentions (risking context exhaustion). Aligning
semantics across mentions, read_file, and prompt/tool gating is required.
Agent Prompt
## Issue description
`maxReadFileLine` is a shared setting used by multiple features (mentions, read_file tool, system prompt/tool building). In this repo, `maxReadFileLine === 0` is already established as a **definitions-only / 0 lines** mode in the read_file tool, but this PR changes `extractTextFromFile` to treat `0` as **unlimited**, which can cause full file contents to be included in file mentions when the global setting is `0`.

## Issue Context
- `extractTextFromFile` is used by the mentions system with the global `maxReadFileLine` value.
- `ReadFileTool` and helper tests explicitly treat `0` as "definitions only mode".
- Tool/prompt gating treats `maxReadFileLine !== -1` as "partial reads enabled", which may also need updating if `0` is redefined.

## Fix Focus Areas
Decide on one consistent meaning and implement it across all call sites and docs.

- src/integrations/misc/extract-text.ts[64-109]
- src/core/mentions/index.ts[193-207]
- src/core/mentions/index.ts[287-307]
- src/core/tools/ReadFileTool.ts[482-505]
- src/core/task/build-tools.ts[161-172]
- src/core/task/Task.ts[4253-4257]
- src/core/tools/helpers/__tests__/truncateDefinitions.spec.ts[15-23]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@jeremylongshore
Copy link
Copy Markdown
Owner Author

@greptileai review

@jeremylongshore
Copy link
Copy Markdown
Owner Author

@greptileai

@jeremylongshore
Copy link
Copy Markdown
Owner Author

Merged into batch-6-combined-20-mirrors branch for combined testing. Bot reviews collected. Review artifacts preserved in .reviews/.

@jeremylongshore jeremylongshore deleted the mirror/PR-5575 branch February 16, 2026 00:43
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.

2 participants