Repository navigation
fix: prevent corrupt viewed images from poisoning sessions - #159668
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 27, 2026, 9:50 AM ET / 13:50 UTC (Revision 2). ClawSweeper reviewWhat this changesThe branch checks native Merge readiness✅ Ready for maintainer review Keep open. Current main still passes an in-limit truncated image into native model context. The follow-up commit resolves the earlier count and reference finding, and the PR body reports production-path evidence that the repair prevents new poisoned turns. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw's flowchart LR
A[Image path or URL] --> B[Media loader]
B --> C[Native image result]
C --> D[Size and decode checks]
D --> E[Image or omission text]
E --> F[Model context]
F --> G[Session history]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +22, Tests +36. Total +58 across 3 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep valid image bytes and accurate references while preventing unreadable newly loaded images from entering session history; handle recovery of already-rejected historical blocks in its separate issue. Do we have a high-confidence way to reproduce the issue? Yes. The PR body records a before-and-after Gateway run using a truncated JPEG beside a valid image and a provider that rejects invalid bytes; current-main source shows the pass-through path. This read-only review did not rerun it. Is this the best way to solve the issue? Yes. Checking the native result before it enters model context repairs the reported path while retaining valid bytes and using the existing sanitizer and image worker. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b1935b05e881. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged as 63c680c. Thanks @chaolawo-byte for the detailed report.
|
) ## What Problem This Solves Fixes: `src/agents/tools/media-tool-file-url.windows.test.ts` fails on the Windows CI job since #159668 (for example run 36330931134, job 108652856586: `view_image` returns 0 images, "incorrect data check"). ## User Impact Test fixture only. No product behavior changes. Unblocks the Windows CI job for every PR. ## Why This Change Was Made The test's one-pixel PNG has an invalid zlib (Adler-32) checksum in its IDAT chunk. Before #159668, `view_image` only read image headers, so the broken fixture passed. #159668 made `view_image` fully decode fresh images and omit undecodable ones, which is correct, so this Windows-only test now receives no image. This replaces the fixture with a valid one-pixel grayscale PNG. It's the only copy of that corrupt base64 in `src`, `extensions`, `test` and `ui/src`. ## Evidence - Python `zlib.decompress` on the old IDAT data fails with "incorrect data check"; the new one decodes. - A throwaway test through the real `sanitizeContentBlocksImages(..., { verifyDecodability: true })`: old fixture → omitted (`text`), new fixture → kept (`image`). - The test itself is `describe.runIf(process.platform === "win32")`, so it's skipped on macOS; the Windows CI job is the real check. - Pash/Sarah overlap: none (test file only). ### Test cost - Windows CI: the test now passes in `checks-windows-node-test-1` (run 36331717411, job 108654954810): 1 test, about 1.3 s ("loads Unicode and space file URLs through registered image and PDF tools", 1308 ms). - Local single-worker run on macOS: the file is `win32`-only, so it's skipped (1 skipped); no local cost. - The change only replaces the fixture bytes; no new test was added. Co-authored-by: Ayaan Zaidi <[email protected]>
…159668) Closes openclaw#159637 ## What Problem This Solves Fixes repeated failed replies when `view_image` admits a header-valid but undecodable image into session history. ## User Impact Unreadable images now produce an omission error instead of an image block, while readable images in the same call still reach the model. Valid images retain their existing bytes and resize behavior. This prevents new poisoned results; it does not rewrite existing transcripts or add provider-rejection recovery. ## Why This Change Was Made The existing image sanitizer checked dimensions and size but passed small images through without decoding them. Native `view_image` results now request a full-decode check on that pass-through branch, using the existing image worker and a discarded 1-pixel encode. Images already undergoing resize do not get an extra check. History replay does not enable it. The existing backend-unavailable compatibility behavior remains unchanged. No new dependency, public configuration, or storage change. No overlap with Pash/Sarah changes. ## Evidence - Isolated, freshly built Gateway against a scripted vision-capable OpenAI-compatible provider that decodes received images and returns HTTP 400 `invalid_request_error` for invalid bytes. - Before: a 65,536-byte truncated JPEG without EOI plus a valid JPEG produced a 400; two subsequent turns replayed the corrupt bytes and also failed. - After: the persisted tool result contains `omitted image payload: ... Unable to decode image with Photon`, no corrupt image bytes, and the original valid JPEG. The current and subsequent turns both completed successfully. The final Gateway proof also covers all-invalid input: the mixed result reports one loaded image and only its valid reference; the all-invalid result reports zero, has no image references, and its next turn still succeeds. - JPEG, PNG, and a 2.83 MB JPEG controls passed before and after; provider payload SHA-256 values match byte-for-byte. A separate frozen-baseline/candidate sanitizer comparison exercised resizing the large JPEG from 2,834,453 to 1,446,151 bytes and produced identical output bytes. - A session with three previous images completed another Gateway turn. A worker-instrumented replay of three prior images retained all three with **zero decode tasks**. - Worker-backed fresh-result cost on Apple M3 Ultra: **79 ms/image** warm for a 2.83 MB JPEG, **0.3 ms** for a small PNG; **688 ms** on first worker use. This is the existing worker used by resize paths, not a new worker owner; first-use startup is newly paid when a session previously only passed through small images. - The new regression fails on the baseline (two image blocks, including the corrupt JPEG), and passes with the fix (one unchanged valid image plus the decode error). Mixed and all-invalid cases also assert accurate loaded counts and retained references. The final image-tool file passed 104 tests in 13.11 s wall; all four focused image files passed 116 tests in 29.37 s wall including preparation. - Fresh baseline/candidate builds completed; touched-file type diagnostics and type-aware lint passed. The builds reported pre-existing Control UI size-budget warnings on both versions; no UI files changed. Reproduction limit: unlike the older reported release, current main's supported `sessions compact` command recovered this small fixture. The initial rejection and repeated-turn poisoning were reproduced; failure after successful compaction was not. Co-authored-by: Ayaan Zaidi <[email protected]>
…claw#159771) ## What Problem This Solves Fixes: `src/agents/tools/media-tool-file-url.windows.test.ts` fails on the Windows CI job since openclaw#159668 (for example run 36330931134, job 108652856586: `view_image` returns 0 images, "incorrect data check"). ## User Impact Test fixture only. No product behavior changes. Unblocks the Windows CI job for every PR. ## Why This Change Was Made The test's one-pixel PNG has an invalid zlib (Adler-32) checksum in its IDAT chunk. Before openclaw#159668, `view_image` only read image headers, so the broken fixture passed. openclaw#159668 made `view_image` fully decode fresh images and omit undecodable ones, which is correct, so this Windows-only test now receives no image. This replaces the fixture with a valid one-pixel grayscale PNG. It's the only copy of that corrupt base64 in `src`, `extensions`, `test` and `ui/src`. ## Evidence - Python `zlib.decompress` on the old IDAT data fails with "incorrect data check"; the new one decodes. - A throwaway test through the real `sanitizeContentBlocksImages(..., { verifyDecodability: true })`: old fixture → omitted (`text`), new fixture → kept (`image`). - The test itself is `describe.runIf(process.platform === "win32")`, so it's skipped on macOS; the Windows CI job is the real check. - Pash/Sarah overlap: none (test file only). ### Test cost - Windows CI: the test now passes in `checks-windows-node-test-1` (run 36331717411, job 108654954810): 1 test, about 1.3 s ("loads Unicode and space file URLs through registered image and PDF tools", 1308 ms). - Local single-worker run on macOS: the file is `win32`-only, so it's skipped (1 skipped); no local cost. - The change only replaces the fixture bytes; no new test was added. Co-authored-by: Ayaan Zaidi <[email protected]>
Closes #159637
What Problem This Solves
Fixes repeated failed replies when
view_imageadmits a header-valid but undecodable image into session history.User Impact
Unreadable images now produce an omission error instead of an image block, while readable images in the same call still reach the model. Valid images retain their existing bytes and resize behavior. This prevents new poisoned results; it does not rewrite existing transcripts or add provider-rejection recovery.
Why This Change Was Made
The existing image sanitizer checked dimensions and size but passed small images through without decoding them. Native
view_imageresults now request a full-decode check on that pass-through branch, using the existing image worker and a discarded 1-pixel encode. Images already undergoing resize do not get an extra check. History replay does not enable it. The existing backend-unavailable compatibility behavior remains unchanged.No new dependency, public configuration, or storage change.
Evidence
invalid_request_errorfor invalid bytes.omitted image payload: ... Unable to decode image with Photon, no corrupt image bytes, and the original valid JPEG. The current and subsequent turns both completed successfully. The final Gateway proof also covers all-invalid input: the mixed result reports one loaded image and only its valid reference; the all-invalid result reports zero, has no image references, and its next turn still succeeds.Reproduction limit: unlike the older reported release, current main's supported
sessions compactcommand recovered this small fixture. The initial rejection and repeated-turn poisoning were reproduced; failure after successful compaction was not.