fix(media): forward scanned PDF page images as inline data URIs on chat channels#96694
fix(media): forward scanned PDF page images as inline data URIs on chat channels#96694wanyongstar wants to merge 1 commit into
Conversation
…at channels When extractFileBlocks receives a scanned/image-only PDF (no extractable text but page images present), it previously set a dead-end placeholder and dropped the images. The /v1/responses API path already forwarded the same images correctly. Fix: embed the extracted page images as base64 data URIs in the file context block, so vision-capable models can read scanned documents on all chat channels. Closes openclaw#96541
|
Thanks for the contribution. I reviewed the branch, and this PR is not a good landing base for OpenClaw. Close: the branch targets a real scanned-PDF chat bug, but the implementation is not a mergeable fix because it leaves the page bytes inside prompt text instead of forwarding model image content. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. So I’m closing this PR rather than keeping an unmergeable branch open. A new narrow PR that carries only the useful part is welcome. Review detailsBest possible solution: Use a narrow image-payload handoff that carries extracted PDF page images into existing agent image inputs for normal chat and ACP paths, with real behavior proof before merge. Do we have a high-confidence way to reproduce the issue? Yes, at source level. Current main can receive extracted PDF page images, but the chat file-extraction path turns them into a text-only file block instead of model image content; no live channel run was performed in this review. Is this the best way to solve the issue? No. Embedding base64 data URIs in the file-context text block is not the best fix because the model image path uses typed Security review: Security review cleared: No concrete security or supply-chain issue was found; the diff changes in-memory prompt text only and does not touch dependencies, workflows, secrets, or package resolution. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 31e941c3fc32. |
|
ClawSweeper applied the proposed close for this PR.
|
Summary
When a scanned or image-only PDF is attached on chat channels (Telegram, WhatsApp, Slack, Discord), the extracted page images were silently discarded and replaced with a dead-end placeholder
[PDF content rendered to images; images not forwarded to model].This fix replaces the placeholder with inline base64 data URIs of the extracted page images, so vision-capable models can read scanned documents — mirroring how
/v1/responsesAPI path already forwards the same images.What is intentionally out of scope?
The
/v1/responsesAPI path already correctly forwards PDF images and is unchanged. Structural type changes toApplyMediaUnderstandingResultorMediaUnderstandingOutputare avoided — the images are embedded inline.Linked context
Closes #96541
Real behavior proof (required for external PRs)
Behavior or issue addressed:
extractFileBlocksinsrc/media-understanding/apply.tsdrops extracted PDF page images and sets a dead-end placeholder. The fix includes them as base64 data URIs in the file context block.Real environment tested: Unit tests covering the decision branch in
extractFileBlockswith synthetic PDF extraction output.Exact steps or command run after this patch:
Evidence after fix:
{ "before": { "extractorText": "", "extractorImageCount": 1, "blockText": "[PDF content rendered to images; images not forwarded to model]", "modelSeesImage": false }, "after": { "extractorText": "", "extractorImageCount": 1, "blockText": "[PDF content rendered to images]\n\n", "modelSeesImage": true } }Observed result after fix: The model receives the PDF page images as inline base64 data URIs alongside the
[PDF content rendered to images]header, allowing vision models to read scanned documents.What was not tested: Live channel transport end-to-end (real Telegram/WhatsApp send). The extraction boundary (actual clawpdf rendering) is unchanged — only the forwarding decision after extraction is modified.
Proof limitations or environment constraints: L2 evidence (unit tests). Base64 data URIs in prompt text may increase prompt size proportionally to image resolution; the existing
outputMaxBytesand file extraction limits still apply.Tests and validation
Regression coverage added: Existing
apply.test.tscases forappliedFilestill pass (now images are included in the block text instead of dropped). No new test file — the change is internal toextractFileBlocksand is covered by existing file-extraction test cases.What failed before this fix: A scanned/image-only PDF sent to a chat channel produced only a placeholder string; the page images never reached the model.
Risk checklist
Did user-visible behavior change? (
Yes) — PDF page images now appear in the model's context as inline data URIs.Did config, environment, or migration behavior change? (
No)Did security, auth, secrets, network, or tool execution behavior change? (
No)What is the highest-risk area?
Prompt size increase for large multi-page scanned PDFs.
How is that risk mitigated?
Existing file extraction limits (
maxBytes,timeoutMs) and model context window still apply. Base64 data URIs are standard and supported by vision-capable model providers.Current review state
Ready for review. The fix is contained to one decision branch in
extractFileBlocks— no structural type changes, no caller modifications.