fix(pdf): provide standardFontDataUrl for Node fallback rendering#51465
fix(pdf): provide standardFontDataUrl for Node fallback rendering#51465anyech wants to merge 1238 commits into
Conversation
Greptile SummaryThis PR addresses the
Confidence Score: 2/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/media/pdf-extract.ts
Line: 52-53
Comment:
**Wrong depth in relative path — fonts won't be found at runtime**
The relative path `"../node_modules/pdfjs-dist/standard_fonts/"` is one level too shallow.
The compiled file lives at `dist/media/pdf-extract.js`, so `import.meta.url` at runtime resolves to `file:///…/dist/media/pdf-extract.js`. Resolving `../` from `dist/media/` gives `dist/`, not the repo root. The full resolved path would be:
```
/path/to/openclaw/dist/node_modules/pdfjs-dist/standard_fonts/
```
…which does not exist. The actual package is installed at `/path/to/openclaw/node_modules/pdfjs-dist/standard_fonts/`.
Reaching the repo root from `dist/media/` requires two levels up:
```suggestion
const standardFontDataUrl = new URL("../../node_modules/pdfjs-dist/standard_fonts/", import.meta.url)
.pathname;
```
This silently causes PDF.js to fail to load standard fonts even though the parameter is now wired in. The specific `"standardFontDataUrl API parameter is provided"` warning disappears (because the param is now truthy), but font fetches will 404 and PDF rendering quality may still be degraded. The test does not catch this because `getDocument` is fully mocked and the path's existence is never verified.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/media/pdf-extract.test.ts
Line: 55-58
Comment:
**Test does not verify the resolved path exists on disk**
The assertions check that `standardFontDataUrl` is a non-empty string containing `"standard_fonts"`, but they never verify the path actually points to an existing directory. This means the test passes even when the path resolves to a non-existent location (e.g., `dist/node_modules/pdfjs-dist/standard_fonts/`).
Consider adding a `fs.existsSync` guard to catch path regressions:
```ts
import { existsSync } from "node:fs";
// …
expect(existsSync(params.standardFontDataUrl)).toBe(true);
```
This would have caught the depth-mismatch in the relative path before the PR landed.
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: "Fix PDF fallback sta..." |
| const standardFontDataUrl = new URL("../node_modules/pdfjs-dist/standard_fonts/", import.meta.url) | ||
| .pathname; |
There was a problem hiding this comment.
Wrong depth in relative path — fonts won't be found at runtime
The relative path "../node_modules/pdfjs-dist/standard_fonts/" is one level too shallow.
The compiled file lives at dist/media/pdf-extract.js, so import.meta.url at runtime resolves to file:///…/dist/media/pdf-extract.js. Resolving ../ from dist/media/ gives dist/, not the repo root. The full resolved path would be:
/path/to/openclaw/dist/node_modules/pdfjs-dist/standard_fonts/
…which does not exist. The actual package is installed at /path/to/openclaw/node_modules/pdfjs-dist/standard_fonts/.
Reaching the repo root from dist/media/ requires two levels up:
| const standardFontDataUrl = new URL("../node_modules/pdfjs-dist/standard_fonts/", import.meta.url) | |
| .pathname; | |
| const standardFontDataUrl = new URL("../../node_modules/pdfjs-dist/standard_fonts/", import.meta.url) | |
| .pathname; |
This silently causes PDF.js to fail to load standard fonts even though the parameter is now wired in. The specific "standardFontDataUrl API parameter is provided" warning disappears (because the param is now truthy), but font fetches will 404 and PDF rendering quality may still be degraded. The test does not catch this because getDocument is fully mocked and the path's existence is never verified.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/media/pdf-extract.ts
Line: 52-53
Comment:
**Wrong depth in relative path — fonts won't be found at runtime**
The relative path `"../node_modules/pdfjs-dist/standard_fonts/"` is one level too shallow.
The compiled file lives at `dist/media/pdf-extract.js`, so `import.meta.url` at runtime resolves to `file:///…/dist/media/pdf-extract.js`. Resolving `../` from `dist/media/` gives `dist/`, not the repo root. The full resolved path would be:
```
/path/to/openclaw/dist/node_modules/pdfjs-dist/standard_fonts/
```
…which does not exist. The actual package is installed at `/path/to/openclaw/node_modules/pdfjs-dist/standard_fonts/`.
Reaching the repo root from `dist/media/` requires two levels up:
```suggestion
const standardFontDataUrl = new URL("../../node_modules/pdfjs-dist/standard_fonts/", import.meta.url)
.pathname;
```
This silently causes PDF.js to fail to load standard fonts even though the parameter is now wired in. The specific `"standardFontDataUrl API parameter is provided"` warning disappears (because the param is now truthy), but font fetches will 404 and PDF rendering quality may still be degraded. The test does not catch this because `getDocument` is fully mocked and the path's existence is never verified.
How can I resolve this? If you propose a fix, please make it concise.| }); | ||
| expect(typeof params.standardFontDataUrl).toBe("string"); | ||
| expect(params.standardFontDataUrl).toContain("standard_fonts"); | ||
| expect(params.standardFontDataUrl.endsWith("/standard_fonts/")).toBe(true); |
There was a problem hiding this comment.
Test does not verify the resolved path exists on disk
The assertions check that standardFontDataUrl is a non-empty string containing "standard_fonts", but they never verify the path actually points to an existing directory. This means the test passes even when the path resolves to a non-existent location (e.g., dist/node_modules/pdfjs-dist/standard_fonts/).
Consider adding a fs.existsSync guard to catch path regressions:
import { existsSync } from "node:fs";
// …
expect(existsSync(params.standardFontDataUrl)).toBe(true);This would have caught the depth-mismatch in the relative path before the PR landed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/media/pdf-extract.test.ts
Line: 55-58
Comment:
**Test does not verify the resolved path exists on disk**
The assertions check that `standardFontDataUrl` is a non-empty string containing `"standard_fonts"`, but they never verify the path actually points to an existing directory. This means the test passes even when the path resolves to a non-existent location (e.g., `dist/node_modules/pdfjs-dist/standard_fonts/`).
Consider adding a `fs.existsSync` guard to catch path regressions:
```ts
import { existsSync } from "node:fs";
// …
expect(existsSync(params.standardFontDataUrl)).toBe(true);
```
This would have caught the depth-mismatch in the relative path before the PR landed.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d8e89c656d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const standardFontDataUrl = new URL("../node_modules/pdfjs-dist/standard_fonts/", import.meta.url) | ||
| .pathname; |
There was a problem hiding this comment.
Resolve standardFontDataUrl from both source and dist layouts
When this code runs from source rather than a built install, import.meta.url is .../src/media/pdf-extract.ts, so ../node_modules/pdfjs-dist/standard_fonts/ resolves to src/node_modules/... instead of the repo root. The main dev entrypoints (pnpm openclaw / pnpm dev via scripts/run-node.mjs) still execute source files, so scanned/image-only PDFs in those workflows will keep failing once pdf.js tries to load fallback fonts. The added test only asserts that some standard_fonts string is passed, so it won't catch this broken path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4174400354
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }); | ||
| expect(typeof params.standardFontDataUrl).toBe("string"); | ||
| expect(params.standardFontDataUrl).toContain("standard_fonts"); | ||
| expect(params.standardFontDataUrl.endsWith("standard_fonts/")).toBe(true); |
There was a problem hiding this comment.
Make path assertion separator-agnostic
fileURLToPath(...) returns Windows-style paths (ending in \standard_fonts\), so this hardcoded "standard_fonts/" suffix check fails on Windows even when standardFontDataUrl is correct. Because this PR touches src/**, the Windows shard in .github/workflows/ci.yml runs pnpm test, so this assertion can block CI for a non-bug in runtime behavior; please make the suffix check accept both separators (or assert via path.basename/dirname).
Useful? React with 👍 / 👎.
4174400 to
c76b9e5
Compare
|
Thanks — I checked the current failing CI lane by looking at the check-run annotations first rather than starting with the full workflow logs. The concrete failing annotation on the current head points to:
I then rechecked that seam in a disposable checkout of this PR branch and ran the narrowest local verification I could exercise: corepack pnpm exec vitest run --config vitest.config.ts src/cli/cron-cli/shared.test.tsThat targeted test passes locally in the disposable checkout. I also diffed this PR branch against the current mainline. The branch only touches:
It does not touch Caveat: this is not a clean latest-version stage repro of the Windows failure path. It is a narrower annotation-first read plus isolated disposable-checkout verification. Given that, I would prefer not to widen this PR to fix an apparently unrelated cron-cli test failure. If helpful, I can rerun the Windows lane or handle that as a separate follow-up, but I would rather keep this PR scoped to the PDF fix. |
|
Thanks — I checked the current failing CI lane by looking at the check-run annotations first rather than starting with the full workflow logs. The concrete failing annotation on the current head points to:
I then rechecked that seam in a disposable checkout of this PR branch and ran the narrowest local verification I could exercise: corepack pnpm exec vitest run --config vitest.config.ts src/cli/cron-cli/shared.test.tsThat targeted test passes locally in the disposable checkout. I also diffed this PR branch against the current mainline. The branch only touches:
It does not touch Caveat: this is not a clean latest-version stage repro of the Windows failure path. It is a narrower annotation-first read plus isolated disposable-checkout verification. Given that, I would keep this PR scoped to the PDF fix unless stronger evidence ties the cron-cli failure to this change. If helpful, I can rerun the Windows lane or handle that as a separate follow-up. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e6534e5c9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const pdf = await getDocument({ data: new Uint8Array(buffer), disableWorker: true }).promise; | ||
| const pdfJsModule = await loadPdfJsModule(); | ||
| const standardFontDataUrl = fileURLToPath( | ||
| new URL("../../node_modules/pdfjs-dist/standard_fonts/", import.meta.url), |
There was a problem hiding this comment.
Resolve standard-font path from package location
standardFontDataUrl is computed with new URL("../../node_modules/...", import.meta.url), which only works when the emitted file stays two directories below the package root. This repo’s build uses tsdown without unbundle: true (tsdown.config.ts), so bundled output can place this code in root-level entry/chunk files; in that layout ../../node_modules resolves outside the OpenClaw package and the font directory is missing, so Node fallback rendering still emits the same PDF.js standard-font warnings in built installs. Resolve from pdfjs-dist/package.json (e.g. via require.resolve) instead of assuming a fixed relative depth.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e6534e5c9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const pdf = await getDocument({ data: new Uint8Array(buffer), disableWorker: true }).promise; | ||
| const pdfJsModule = await loadPdfJsModule(); | ||
| const standardFontDataUrl = fileURLToPath( | ||
| new URL("../../node_modules/pdfjs-dist/standard_fonts/", import.meta.url), |
There was a problem hiding this comment.
Resolve standard font path from pdfjs module location
Computing standardFontDataUrl via new URL("../../node_modules/...", import.meta.url) is still layout-dependent and can miss in bundled output: this repo builds with bundled mode (not unbundle), and we already expect hashed top-level dist/*.js chunks in tests (for example src/plugin-sdk/root-alias.test.ts), so if this module is emitted at dist/*.js the resulting path becomes <package-parent>/node_modules/node_modules/pdfjs-dist/standard_fonts, which does not exist. In that case PDF.js cannot load standard fonts and the fallback renderer reverts to the same warning-prone behavior this change is trying to fix.
Useful? React with 👍 / 👎.
…edup provider-hook prose list, progressive-disclose bundled-provider examples
Load Feishu setup surfaces through a setup-only barrel so onboarding does not import the Lark SDK before bundled runtime deps are staged.\n\nThanks @andrejtr.\n\nCo-authored-by: andrejtr <[email protected]>
|
Closing this PR because it looks dirty (too many unrelated or unexpected changes). This usually happens when a branch picks up unrelated commits or a merge went sideways. Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated or unexpected changes). This usually happens when a branch picks up unrelated commits or a merge went sideways. Please recreate the PR from a clean branch. |
💡 Codex Reviewopenclaw/src/media/pdf-extract.ts Lines 96 to 97 in 77d3966 Compute ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
standardFontDataUrlinto the Node PDF extraction-fallback renderer.pathname) instead offile://...hrefCloses #51455.
Problem
The non-native PDF extraction fallback could emit repeated PDF.js warnings during page-image rendering in Node:
UnknownErrorException: Ensure that the standardFontDataUrl API parameter is provided.The analysis still succeeded, but the renderer was missing the standard-font configuration PDF.js expects.
Root cause
The fallback path called
getDocument({ data, disableWorker: true })withoutstandardFontDataUrlbefore later callingpage.render(...).Fix
Provide:
and pass it into
getDocument(...).Why
.pathnameLocal verification showed that
.hrefchanged the failure into font-load warnings in this Node runtime path, while.pathnameeliminated the warning both locally and in a live post-restart check.Testing
corepack pnpm exec vitest run --config vitest.config.ts src/media/pdf-extract.test.ts src/agents/tools/pdf-tool.test.tsNotes
pnpm testrun