Skip to content

fix(read_file): normalize empty pages string to prevent validation loop#114

Open
Gucc111 wants to merge 1 commit into
OpenBMB:mainfrom
Gucc111:fix/issue-108-empty-pages
Open

fix(read_file): normalize empty pages string to prevent validation loop#114
Gucc111 wants to merge 1 commit into
OpenBMB:mainfrom
Gucc111:fix/issue-108-empty-pages

Conversation

@Gucc111
Copy link
Copy Markdown
Collaborator

@Gucc111 Gucc111 commented Jun 2, 2026

Summary

  • Normalize empty/blank pages values ("", " ") to omitted before validation in read_file, preventing invalid_tool_input rejections that lead to agent_tool_error_loop termination.
  • Some models/providers emit pages: "" instead of omitting the optional field for non-PDF files; parsePdfPageRange rejects the empty string, and after 3 consecutive failures the circuit breaker kills the session.

Closes #108

Changes

src/tool/builtin/readFile.ts — added 4 lines in validateInput before the existing pages check:

if (typeof input.pages === "string" && input.pages.trim().length === 0) {
  const { pages: _pages, ...rest } = input;
  input = rest as ReadFileInput;
}

Test plan

  • Verify read_file with pages: "" on a non-PDF file no longer returns invalid_tool_input
  • Verify read_file with pages: "1-5" on a PDF still works correctly
  • Verify tsc --noEmit passes with no type errors

Made with Cursor

When some models/providers emit `pages: ""` instead of omitting the
field, parsePdfPageRange rejects it and triggers invalid_tool_input.
After 3 consecutive failures the agent_tool_error_loop circuit breaker
terminates the session.

Treat blank pages values the same as omitted before validation runs.

Closes OpenBMB#108

Co-authored-by: Cursor <cursoragent@cursor.com>
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_file rejects empty pages string generated for non-PDF files, causing validation loop

1 participant