Skip to content

fix: prevent corrupt viewed images from poisoning sessions - #159668

Merged
obviyus merged 2 commits into
mainfrom
fix/view-image-undecodable-159637
Sep 27, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/view-image-undecodable-159637

Conversation

@obviyus

@obviyus obviyus commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #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.

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.

@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@obviyus
obviyus marked this pull request as ready for review September 27, 2026 13:27
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Sep 27, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 27, 2026, 9:50 AM ET / 13:50 UTC (Revision 2).

ClawSweeper review

What this changes

The branch checks native view_image results for unreadable images, reports only images retained for the model, and adds mixed and all-invalid image regressions.

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
Reviewed head: e4398cdda37b554de40f31fbe819049e0a603b20

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused production-path evidence and a baseline-failing regression support a small repair whose earlier review finding is resolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body reports the changed native view_image path through an isolated built Gateway and scripted vision provider: before the fix a truncated JPEG caused a 400 and failed later turns; afterward it became omission text, the valid JPEG remained byte-identical, and current and later turns succeeded. Mixed, all-invalid, and large-image controls are also reported. The existing transcript text/image block contract is unchanged.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body reports the changed native view_image path through an isolated built Gateway and scripted vision provider: before the fix a truncated JPEG caused a 400 and failed later turns; afterward it became omission text, the valid JPEG remained byte-identical, and current and later turns succeeded. Mixed, all-invalid, and large-image controls are also reported. The existing transcript text/image block contract is unchanged.
Evidence reviewed 9 items Current main remains affected: The in-limit branch returns the original base64 after header metadata and size checks, without a full decode.
Introduced decode check: The PR checks the in-limit pass-through branch with the existing image processor before retaining the original bytes.
Earlier finding addressed: The result now derives its loaded count and references from retained image blocks; the previous ClawSweeper review identified the earlier mismatch.
Findings None None.
Security None None.

How this fits together

OpenClaw's view_image tool loads local images or permitted URLs for a vision-capable agent. Its native result goes to the model and remains in session history for later turns.

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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +22, Tests +36. Total +58 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 37 15 +22
Tests 1 36 0 +36
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 73 15 +58

Review metrics

Metric Value Why it matters
Fresh-image decode cost 79 ms/image warm; 688 ms on first use for a 2.83 MB JPEG The PR body measures the added work on fresh native image results, including the cold-worker cost.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #159637
Summary: This PR is the candidate fix for the linked undecodable-image issue; historical provider-rejection recovery remains distinct.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports the changed native view_image path through an isolated built Gateway and scripted vision provider: before the fix a truncated JPEG caused a 400 and failed later turns; afterward it became omission text, the valid JPEG remained byte-identical, and current and later turns succeeded. Mixed, all-invalid, and large-image controls are also reported. The existing transcript text/image block contract is unchanged.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: A corrupt viewed image can cause repeated provider rejection and block subsequent replies in the affected agent session.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports the changed native view_image path through an isolated built Gateway and scripted vision provider: before the fix a truncated JPEG caused a 400 and failed later turns; afterward it became omission text, the valid JPEG remained byte-identical, and current and later turns succeeded. Mixed, all-invalid, and large-image controls are also reported. The existing transcript text/image block contract is unchanged.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports the changed native view_image path through an isolated built Gateway and scripted vision provider: before the fix a truncated JPEG caused a 400 and failed later turns; afterward it became omission text, the valid JPEG remained byte-identical, and current and later turns succeeded. Mixed, all-invalid, and large-image controls are also reported. The existing transcript text/image block contract is unchanged.

Evidence

What I checked:

  • Current main remains affected: The in-limit branch returns the original base64 after header metadata and size checks, without a full decode. (src/agents/tool-images.ts:182, b1935b05e881)
  • Introduced decode check: The PR checks the in-limit pass-through branch with the existing image processor before retaining the original bytes. (src/agents/tool-images.ts:199, e4398cdda37b)
  • Earlier finding addressed: The result now derives its loaded count and references from retained image blocks; the previous ClawSweeper review identified the earlier mismatch. (src/agents/tools/image-tool.result.ts:45, e4398cdda37b)
  • Regression coverage: The native tool test covers a truncated JPEG with and without a readable batch member, including retained bytes, counts, references, and omission text. (src/agents/tools/image-tool.test.ts:1697, e4398cdda37b)
  • Production entrypoint: The native view_image route builds this result after loading image media, establishing that the changed result builder is on the reported path. (src/agents/tools/image-tool.ts:642, e4398cdda37b)
  • Behavior proof in PR body: At the reviewed head, the PR body reports an isolated Gateway run against a scripted vision-capable provider: the truncated JPEG caused a 400 and replay failures before the fix; afterward the corrupt block was omitted, valid bytes were preserved, and current and later turns succeeded. It also reports mixed and all-invalid results, large-image controls, and measured decode cost. (e4398cdda37b)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-27T13:35:32.730Z sha 55a8a78 :: needs changes before merge. :: [P2] Report only images the model actually received

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 27, 2026
@obviyus
obviyus merged commit 63c680c into main Sep 27, 2026
195 checks passed
@obviyus
obviyus deleted the fix/view-image-undecodable-159637 branch September 27, 2026 14:57
@obviyus

obviyus commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Merged as 63c680c. Thanks @chaolawo-byte for the detailed report.

view_image now checks that a fresh image fully decodes before sending it. An unreadable file (for example a truncated JPEG) becomes an omission note instead of an image block, so the provider no longer rejects the whole request and the session keeps working. Readable images in the same call still reach the model with identical bytes. On a real isolated Gateway, main returned HTTP 400 on that turn and the following ones; with this change the turn and later turns succeed, and the result reports only the images actually sent. The check runs once per fresh result off the main thread (about 80 ms for a 2.8 MB JPEG) and never re-decodes history. Sessions already poisoned by an earlier bad image are not rewritten.

obviyus added a commit that referenced this pull request Sep 27, 2026
)

## 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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 28, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 28, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: view_image forwards undecodable images verbatim; one truncated JPEG permanently breaks a session

1 participant