Skip to content

fix: PDF tool accepts fractional page numbers that select no extracted pages#99582

Closed
Linux2010 wants to merge 1 commit into
openclaw:mainfrom
Linux2010:fix/99393-pdf-fractional-pages
Closed

fix: PDF tool accepts fractional page numbers that select no extracted pages#99582
Linux2010 wants to merge 1 commit into
openclaw:mainfrom
Linux2010:fix/99393-pdf-fractional-pages

Conversation

@Linux2010

Copy link
Copy Markdown
Contributor

Closes #99393

What Problem This Solves

Fixes an issue where users of the pdf tool could pass fractional page numbers (e.g. pages: "1.5") that silently produced empty extraction results. The parser accepted fractional values via Number(part), but the document-extract fallback later filtered them out with Number.isInteger(p), so the request continued with no selected PDF content instead of a clear input error.

Why This Change Was Made

Added a Number.isInteger(num) check to the single-page token path in parsePageRange, so fractional input is rejected at parse time with an Invalid page number error — consistent with how invalid ranges, zero, and negative values are already handled. The dash-range path already uses ^\d+$ regex matching, so it is unaffected.

User Impact

Users who accidentally pass fractional page numbers to the pdf tool now get an immediate, clear error instead of a silently empty result. Integer page numbers and ranges continue to work unchanged.

Evidence

  • New tests: parsePageRange("1.5", 20) and parsePageRange("1,1.5", 20) both throw Invalid page number
  • All 24 tests in src/agents/tools/pdf-tool.helpers.test.ts pass
node scripts/run-vitest.mjs src/agents/tools/pdf-tool.helpers.test.ts
→ 24 tests passed (1 file)

parsePageRange used Number(part) which accepts fractional values like
"1.5". The document-extract fallback later filters non-integer pages
with Number.isInteger, silently dropping them and producing empty
extraction results. Add Number.isInteger check at parse time to reject
fractional input with a clear error.

Closes openclaw#99393
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jul 3, 2026
@clawsweeper

clawsweeper Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close this PR as superseded: it targets a real PDF page parser bug, but an earlier open, mergeable, proof-positive PR already covers the same parser boundary with stronger tool-boundary coverage and real behavior proof.

Canonical path: Land one proof-positive parser-boundary fix, preferably #99399, then close the linked issue and the duplicate open fix candidates.

So I’m closing this here and keeping the remaining discussion on #99399 and #99403.

Review details

Best possible solution:

Land one proof-positive parser-boundary fix, preferably #99399, then close the linked issue and the duplicate open fix candidates.

Do we have a high-confidence way to reproduce the issue?

Yes at source level: current parsePageRange("1.5", 20) follows the single-token Number(part) branch, and fallback extraction filters non-integer pages later. I did not run tests because this review was constrained to read-only inspection.

Is this the best way to solve the issue?

No for this branch as the best landing path: the parser-boundary change is plausible, but #99399 already covers the same fix with stronger real behavior proof and tool-boundary coverage.

Security review:

Security review cleared: The diff tightens PDF parser validation and adds tests; it does not touch dependencies, workflows, secrets, package metadata, or supply-chain execution paths.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • tyler6204: Authored and merged the original PDF analysis tool PR that added parsePageRange, the public pages argument, and the main PDF tool implementation. (role: introduced behavior; confidence: high; commits: d0ac1b019517, 2c257cf97d13, 0b57ca3b5ce3; files: src/agents/tools/pdf-tool.helpers.ts, src/agents/tools/pdf-tool.ts, src/agents/tools/pdf-tool.test.ts)
  • zhangguiping-xydt: Authored the recently merged empty parsed page-range fix in the same parser helper and PDF tool tests. (role: recent adjacent repair author; confidence: high; commits: a5165d6a8486, aadd57c31cc8; files: src/agents/tools/pdf-tool.helpers.ts, src/agents/tools/pdf-tool.helpers.test.ts, src/agents/tools/pdf-tool.test.ts)
  • steipete: Git history shows recent PDF tool helper and test refactors around the affected parser and validation surface. (role: recent area contributor; confidence: medium; commits: 7240830ca42f, 998cc02af40c, 42ae213ba6f4; files: src/agents/tools/pdf-tool.helpers.ts, src/agents/tools/pdf-tool.helpers.test.ts, src/agents/tools/pdf-tool.test.ts)
  • vincentkoc: Merged the adjacent empty-page parser fix and has recent shared PDF test setup work near this surface. (role: recent merger and adjacent contributor; confidence: medium; commits: aadd57c31cc8, b4f5c748c3da; files: src/agents/tools/pdf-tool.helpers.ts, src/agents/tools/pdf-tool.test.ts)

Codex review notes: model internal, reasoning high; reviewed against 5342effebcf7.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 3, 2026
@clawsweeper

clawsweeper Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jul 3, 2026
@Linux2010
Linux2010 deleted the fix/99393-pdf-fractional-pages branch July 17, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: PDF tool accepts fractional page numbers that select no extracted pages

1 participant