Skip to content

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

Description

@qingminglong

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

The PDF tool accepts fractional pages values such as 1.5 as parsed page numbers, but the document extraction fallback later filters them out as non-integer pages, so the request can continue with no selected PDF content instead of a clear input error.

Steps to reproduce

  1. Use the pdf tool with a non-native PDF model path so extraction fallback is used.
  2. Pass a PDF plus pages: "1.5".
  3. Observe that parsePageRange("1.5", 20) currently produces [1.5], while the document extractor only keeps integer page numbers.

Expected behavior

The pages parameter should reject fractional page numbers with an Invalid page number-style error because the documented contract is 1-based page numbers and examples use integer pages/ranges.

Actual behavior

Single-page tokens are parsed with Number(part), so fractional values pass the PDF tool parser. The document-extract plugin then filters pageNumbers with Number.isInteger(p), which drops fractional pages before text/image extraction.

OpenClaw version

Current main at 4e6933c84f186235f467d73c8d73e0bb6f1968a2, source-level repro.

Operating system

Not OS-specific.

Install method

Source checkout / pnpm dev.

Model

Not provider-specific; affects the PDF extraction fallback path.

Provider / routing chain

Not provider-specific; source-level PDF tool runtime path.

Additional provider/model setup details

Not applicable.

Logs, screenshots, and evidence

Relevant source evidence:

  • src/agents/tools/pdf-tool.helpers.ts:49 documents parsePageRange as returning sorted, unique, 1-based page numbers.
  • src/agents/tools/pdf-tool.helpers.ts:68 parses single page tokens with Number(part), which accepts "1.5".
  • src/agents/tools/pdf-tool.ts:489 passes parsed pageNumbers into PDF extraction.
  • extensions/document-extract/document-extractor.ts:68-71 filters request.pageNumbers to Number.isInteger(p) && p >= 1 && p <= pdf.pageCount.
  • docs/tools/pdf.md:72 documents pages as 1-based page numbers.
  • node_modules/clawpdf/CHANGELOG.md:13 describes the dependency API around one-based pages; node_modules/clawpdf/dist/document.js:209-210 rejects non-integer page numbers.

Source-level probe of the current parser behavior:

parsePageRange("1.5", 20) -> [1.5]
parsePageRange("1,1.5", 20) -> [1,1.5]
parsePageRange("20.5", 20) -> No PDF pages matched requested range "20.5" on current main, but not because the token is invalid; it is only empty after max-page filtering.

Duplicate search summary:

  • Open issue search: pdf pages found unrelated issue #77090.
  • Open PR search: pdf pages found unrelated media-path PR #93848.
  • Open issue/PR searches for PDF page range, PDF page number, parsePageRange, pdf-tool.helpers, and pdfMaxPages found no open blockers.
  • Closed related PR #97698 fixed empty out-of-range page selections before native PDF analysis, but does not cover fractional page numbers.

Focused regression test idea:

  • src/agents/tools/pdf-tool.helpers.test.ts: assert parsePageRange("1.5", 20) throws Invalid page number.
  • Optionally src/agents/tools/pdf-tool.test.ts: assert a fallback PDF tool request with pages: "1.5" rejects before model completion.

Impact and severity

Affected: users of the pdf tool who pass fractional pages values, especially in extraction fallback mode.
Severity: Medium; this is an edge-case input bug, but it can produce an answer without the requested PDF page content instead of an actionable input error.
Frequency: Always for fractional single-page tokens accepted by Number(part).
Consequence: The user may receive a model answer based on no selected PDF page content, making PDF analysis misleading.

Additional information

Related merged PR: #97698 fixed a neighboring empty-selection bug for out-of-range pages. This report is narrower: fractional page tokens still pass the parser and are only dropped later by the document extractor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.no-staleExclude from stale automation

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions