Skip to content

fix: reject fractional PDF page numbers#100596

Closed
qingminlong wants to merge 1 commit into
openclaw:mainfrom
qingminlong:codex/99393-pdf-fractional-pages-pr
Closed

fix: reject fractional PDF page numbers#100596
qingminlong wants to merge 1 commit into
openclaw:mainfrom
qingminlong:codex/99393-pdf-fractional-pages-pr

Conversation

@qingminlong

Copy link
Copy Markdown
Contributor

Closes #99393

What Problem This Solves

Fixes an issue where the PDF tool accepted fractional pages values such as 1.5, allowing invalid page selections to reach later extraction paths where non-integer pages could be dropped.

Why This Change Was Made

The PDF page parser now rejects non-integer single-page tokens at the public pages parsing boundary using the existing invalid page-number error path. The fix preserves existing integer page, range, clamp, sort, and dedupe behavior.

User Impact

Users who pass fractional PDF page numbers now receive a clear input error instead of a misleading PDF analysis path that may omit the requested content.

Evidence

  • Head SHA: c18f5e2d6d8d7c6d1dc18fc65f3dd825e37eb8c9
  • Claim proved: fractional PDF page tokens are rejected by the parser and by the tool before native PDF analysis starts.
  • Commands / artifacts:
    • git diff --check passed.
    • git diff upstream/main...HEAD --check passed.
    • node scripts/run-vitest.mjs src/agents/tools/pdf-tool.helpers.test.ts passed: 23 tests.
    • node scripts/run-vitest.mjs src/agents/tools/pdf-tool.test.ts passed: 27 tests.
  • Observed result: parsePageRange("1.5", 20) now throws Invalid page number: "1.5", and the PDF tool rejects pages: "1.5" before native provider analysis.
  • Not tested / proof gaps: no broad typecheck/lint was run by request.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jul 6, 2026
@clawsweeper

clawsweeper Bot commented Jul 6, 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 as duplicate/superseded: the same fractional PDF page-token fix is already covered by #99399, which is cleanly mergeable, proof-sufficient, and has broader tool-boundary coverage; this branch does not add a unique fix.

Canonical path: #99403 is another open, cleanly mergeable, proof-sufficient candidate for the same issue, confirming this is a duplicate fix cluster rather than a unique branch.

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

Review details

Best possible solution:

Review and land exactly one proof-positive parser-boundary fix, preferably #99399, then close the linked issue and remaining duplicate PRs.

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

Yes. Current main clearly parses "1.5" through the single-token Number(part) branch, and fallback extraction filters non-integer page numbers later.

Is this the best way to solve the issue?

Yes for the fix layer, but this branch is not the best landing vehicle. The parser-boundary integer check is correct, while #99399 is the stronger canonical PR to review and land.

Security review:

Security review cleared: The diff only 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:

  • Current parser accepts fractional single-page tokens: On current main, parsePageRange converts single tokens with Number(part) and only rejects non-finite or values below 1, so "1.5" can still enter the page-number contract. (src/agents/tools/pdf-tool.helpers.ts:68, f296dc4e68e4)
  • PDF tool uses the parser as the shared boundary: createPdfTool computes pageNumbers once from parsePageRange and passes it to both extraction and model routing, so the parser is the right fix layer. (src/agents/tools/pdf-tool.ts:498, f296dc4e68e4)
  • Fallback extraction filters non-integer pages: The document-extract plugin filters requested pages with Number.isInteger, so a fractional parser output can be dropped downstream instead of reported as invalid input. (extensions/document-extract/document-extractor.ts:68, f296dc4e68e4)
  • Dependency contract also expects integer pages: The pinned [email protected] package validates loaded page numbers with Number.isInteger and documents one-based page APIs, matching integer-only OpenClaw parsing.
  • Canonical open PR is viable: fix(pdf): reject fractional page selections #99399 is open, cleanly mergeable, has proof: sufficient, and covers both direct fractional tokens and mixed comma-separated fractional input before fallback extraction. (451ef0407653)
  • Current branch duplicates the same parser fix: This PR changes the same helper and adds narrower parser/native-path tests for the same linked issue, without a unique implementation or validation advantage over the canonical candidate. (src/agents/tools/pdf-tool.helpers.ts:66, c18f5e2d6d8d)

Likely related people:

  • tyler6204: Remote history shows the original merged PDF analysis tool PR added parsePageRange, the public pages argument, and the main PDF tool implementation. (role: introduced behavior; confidence: high; commits: d0ac1b019517; 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 neighboring fix for empty parsed PDF page selections in the same parser helper and 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: Recent remote history includes multiple PDF tool/helper and test refactors around the affected parser and tool surface. (role: recent area contributor; confidence: medium; commits: 7240830ca42f, 998cc02af40c, 1ce11fbf423b; files: src/agents/tools/pdf-tool.helpers.ts, src/agents/tools/pdf-tool.ts, src/agents/tools/pdf-tool.helpers.test.ts)
  • vincentkoc: Merged the adjacent empty-page parser fix and appears in recent PDF/document-extract history around this surface. (role: recent merger and adjacent contributor; confidence: medium; commits: aadd57c31cc8, 3881cb34260a; files: src/agents/tools/pdf-tool.helpers.ts, src/agents/tools/pdf-tool.ts, extensions/document-extract/document-extractor.ts)

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

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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 6, 2026
@clawsweeper

clawsweeper Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

  • Action: closed this PR.
  • Close reason: duplicate or superseded.
  • Evidence: durable ClawSweeper review.
  • Coverage proof: PR B clearly carries PR A's core bug fix and review concerns, is identified as the stronger/current canonical landing path, and any remaining PR A details are incidental or can be handled while reviewing PR B. Covering PR: fix(pdf): reject fractional page selections #99399.

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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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