Skip to content

fix(codex): materialize native tool-output images from raw response items - #154033

Closed
chelsealong wants to merge 2 commits into
openclaw:mainfrom
chelsealong:fix/codex-tool-output-image-153949
Closed

chelsealong wants to merge 2 commits into
openclaw:mainfrom
chelsealong:fix/codex-tool-output-image-153949

Conversation

@chelsealong

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #153949.

Codex's native ImageView tool (and other native tools that hand back an
image) surfaces to OpenClaw as a raw function_call_output /
custom_tool_call_output response item whose output array contains a
nested {"type":"input_image","image_url":"data:image/png;base64,..."}
entry. CodexGeneratedMediaProjection.recordRaw (the Codex media owner)
only recognized raw image_generation_call items and returned immediately
for anything else, so this event shape was silently dropped.
readCodexResponseOutput deliberately omits non-text tool output from the
text transcript on the assumption that the media owner picks it up
(extensions/codex/src/app-server/event-projector-tool-output.ts:129), so
the image bytes never reached the transcript or Control UI at all: the
assistant's reply referenced "the screenshot above" while no attachment
existed anywhere.

What Changed

  • CodexGeneratedMediaProjection.recordRaw now also inspects
    function_call_output / custom_tool_call_output raw items, scanning
    their output array for input_image entries.
  • Each image_url is validated through the existing
    sanitizeInlineImageDataUrl guard (same validation already used for
    Codex history payload sanitization) and decoded via the existing
    parseImageDataUrl helper.
  • Valid images are materialized through the exact same
    recordImage/materializeImage path already used for
    image_generation_call results, so they get the same size cap,
    concurrent-completion dedupe, and delivery/transcript wiring as
    generated images, and are marked as a side effect
    (hadPotentialSideEffects).
  • Invalid or missing image_url values are skipped (fail closed): no
    placeholder, no partial write.

This is scoped to the raw-response-item media owner only; it does not
touch the image_generation_call path, billing/side-effect
classification for actual image generation, or the separate
dynamic-tool-image rendering path added in #120577 (which covers a
different event shape — dynamic tool results carried on typed thread
items, not this nested raw input_image payload).

Evidence

New regression test, reverted against the pre-fix source
(git checkout HEAD~1 -- extensions/codex/src/app-server/event-projector-media.ts)
to confirm it fails without the change:

$ node scripts/run-vitest.mjs extensions/codex/src/app-server/event-projector.media.test.ts -t "saves a native tool-output input_image"
...
FAIL  |extension-codex| extensions/codex/src/app-server/event-projector.media.test.ts > CodexAppServerEventProjector media projection > saves a native tool-output input_image as reply media
AssertionError: Target cannot be null or undefined.
 ❯ extensions/codex/src/app-server/event-projector.media.test.ts:394:34
    392|     const mediaUrl = result.toolMediaUrls?.[0];
    393|
    394|     expect(result.toolMediaUrls).toHaveLength(1);

Restored the fix and reran — passes:

$ node scripts/run-vitest.mjs extensions/codex/src/app-server/event-projector.media.test.ts -t "saves a native tool-output input_image"
✓ |extension-codex| extensions/codex/src/app-server/event-projector.media.test.ts > CodexAppServerEventProjector media projection > saves a native tool-output input_image as reply media 51ms
Test Files  1 passed (1)
     Tests  1 passed | 29 skipped (30)

Full relevant suites, all passing (89 tests):

$ node scripts/run-vitest.mjs extensions/codex/src/app-server/event-projector.media.test.ts extensions/codex/src/app-server/event-projector.replay-safety.test.ts extensions/codex/src/app-server/run-attempt.final-media.test.ts src/agents/embedded-agent-runner/run/tool-media-payloads.test.ts
...
Test Files  1 passed (1)   # media.test.ts + replay-safety.test.ts: 50 passed
Test Files  1 passed (1)   # run-attempt.final-media.test.ts: 9 passed
Test Files  1 passed (1)   # tool-media-payloads.test.ts: 24 passed

Formatting/lint on the changed files:

$ npx oxlint extensions/codex/src/app-server/event-projector-media.ts extensions/codex/src/app-server/event-projector.media.test.ts
(no issues)
$ npx oxfmt --check extensions/codex/src/app-server/event-projector-media.ts extensions/codex/src/app-server/event-projector.media.test.ts
All matched files use the correct format.
$ git diff --check
(clean)

node scripts/check-changed.mjs's repo-wide "line-cap growth ratchet"
check fails in this checkout, but it fails identically (same file list,
same counts) on unmodified upstream/main with these two files stashed
out — it's flagging pre-existing large files unrelated to this change,
not anything this PR touches.

tsgo --noEmit on the extensions/codex project reports 1618 errors in
this checkout, all TS2307: Cannot find module 'openclaw/plugin-sdk/*'
(missing generated plugin-sdk type declarations from a partial/source-only
dependency setup) plus pre-existing any/unknown findings in unrelated
files (e.g. src/supervision-tools.ts, src/session-cli.ts). Confirmed
the exact same 1618-error count with this branch's two files stashed out
against unmodified upstream/main — the type-resolution gap is an
environment limitation of this sandbox, not something introduced here.

Was not able to run a live Codex app-server round-trip in this sandbox (no
Codex credentials/harness available here); the evidence above proves the
event-projection behavior through the same test harness and fixtures the
existing image_generation_call regression tests in this file use.

…tems

Codex's ImageView tool (and other native tools) return screenshots as a
raw function_call_output/custom_tool_call_output item whose output array
carries a nested input_image data URL. The Codex media projector only
recognized raw image_generation_call items, so this shape was dropped:
the assistant text referenced the image but no attachment ever reached
Control UI or the transcript.

Extend CodexGeneratedMediaProjection.recordRaw to also scan tool-output
items for input_image entries, validate them through the existing
sanitizeInlineImageDataUrl guard, and materialize them through the same
bounded media-save/delivery path already used for generated images.

Fixes openclaw#153949
@sobechestnut-dev

Copy link
Copy Markdown
Contributor

Thanks for picking this up. I found one correctness blocker against the issue acceptance criteria: this patch intentionally makes native screenshot/tool-output media produce hadPotentialSideEffects: true and replaySafe: false (and the new test locks that in). Ordinary view_image/screenshot results are delivery media, not image-generation side effects, so they must not trigger billing/replay-safety accounting. The generated-media side-effect identity needs to remain separate from projected tool-output attachment identity.

The focused regression matrix should also cover both custom_tool_call_output and applicable function_call_output, malformed data URLs, unsupported/non-image content, oversized payloads before persistence, repeated raw-event deduplication, and text-only output. The sanitized event from #153949 contains both id and call_id; requiring one stable identity is safer than the current raw-tool-output-${this.itemIds.size} fallback, which can materialize an ID-less repeated event twice.

I have a narrow local candidate with those cases passing plus live Control UI before/after/reload verification in progress, and I’m happy to share the diff or test fixtures so we can converge on one PR rather than duplicate work.

@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The Codex plugin saves images nested in raw tool-output events as reply attachments without counting them as image-generation side effects.

Example: Codex reads /tmp/screenshot.png and returns its PNG bytes in a raw tool-output input_image entry.

  • Before: The assistant refers to the screenshot, but the reply contains no attachment.
  • After: The patch saves the PNG in Gateway-managed media and includes its reference in the reply.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused regression protects useful behavior, but the patch retains a private-media publication defect and incorrect delivery matching.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🧂 unranked krab (1/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Users cannot see screenshots that their Codex-backed assistant says it attached.
Reason: The report establishes a concrete missing-media workflow, and the existing plugin media owner can absorb the repair without new configuration or public APIs.

Merge readiness

⛔ Blocked before merge - 6 items remain

Keep open: this PR addresses a current screenshot-delivery bug, but both previous correctness findings remain unresolved.

Priority: P2
Reviewed head: 545552b20a92f06f5d3e90bf14a1cd043def551b

Before merge

  • Add real behavior proof - Authority-chain proof required: the supplied regression exercises synthetic notifications through the projector, while inspected screenshots belong to another branch; provide redacted runtime evidence and before/after/reload screenshots for this implementation, including an allowed native screenshot and an outbound=false host-tool echo rejected before managed storage and reply delivery. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Exclude host dynamic-tool echoes from native attachment projection (P1) - A host image or computer tool can return image content with details.media.outbound=false for private model inspection. The bridge correctly excludes that result from outbound telemetry, but still sends its image bytes to Codex as inputImage content. Codex returns those bytes in a raw function_call_output under the host call_id, and this new unconditional branch saves them and marks them host-owned reply media. Correlate raw outputs with native versus host tool-call ownership before materialization so private inspection results cannot become user attachments. This is the unresolved previous P1 finding.
  • Retain the native image path when recording its managed copy (P2) - When view_image reads /tmp/screenshot.png, its typed ImageView item carries that path under the call identity, but this new image record retains only a raw-derived item ID and bytes. recordNative ignores ImageView, so no savedPath alias ever reaches projectDelivery. If the message tool subsequently sends the original path, a confirmed source reply cannot suppress this managed copy, and an outbound send cannot associate it with the delivered attachment. Retain the native path by call identity in both notification orders and attach that alias to the managed image record. This is the unresolved previous P2 finding.
  • Resolve security concern: Private image content becomes outbound media - The nearest forbidden publication case is a host-tool result explicitly marked outbound=false; its raw echo reaches managed storage and host-owned delivery without preserving that decision.
  • Resolve merge risk - The contributor must resolve GitHub's reported merge conflicts while preserving current media ownership and delivery contracts.
  • Explain or restore the original intent of Per-artifact delivery matching - 8e7443e: Original source identities and authoritative delivery receipts prevent duplicate attachments while preserving unrelated media.

Findings

  • [P1] Exclude host dynamic-tool echoes from native attachment projection — extensions/codex/src/app-server/event-projector-media.ts:141-142
  • [P2] Retain the native image path when recording its managed copy — extensions/codex/src/app-server/event-projector-media.ts:169-172
  • [high] Private image content becomes outbound media — extensions/codex/src/app-server/event-projector-media.ts:141

Provenance

  • Per-artifact delivery matching changes intended behavior without addressing why it exists (8e7443e: Original source identities and authoritative delivery receipts prevent duplicate attachments while preserving unrelated media.)

Tests

  • Missing end-to-end proof: Missing shipped Codex-to-reply evidence covers screenshot display and reload, original-path delivery matching, and rejection of private host-tool image echoes before storage and delivery.
Agent review details

How this fits together

The Codex event projector translates app-server notifications into OpenClaw replies; its media owner converts image bytes into managed attachment references consumed by delivery and transcript persistence.

flowchart TD
  A[Codex tool output] --> B[Raw response notification]
  B --> C[Codex media projector]
  C --> D[Image validation]
  D --> E[Gateway media store]
  E --> F[Delivery receipt matching]
  F --> G[Reply and transcript]
Loading

Technical review

Best possible solution:

Extend the existing Codex media owner with native-call correlation that preserves private host-tool results and original-path delivery aliases.

Do we have a high-confidence way to reproduce the issue?

The canonical report supplies a concrete raw event and missing-transcript result, and inspected current-main and release source reject that event shape; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Reusing the existing bounded media owner is appropriate, but attachment eligibility must follow tool ownership and delivery identity rather than the presence of inline image bytes alone.

Full review comments:

  • [P1] Exclude host dynamic-tool echoes from native attachment projection — extensions/codex/src/app-server/event-projector-media.ts:141-142
    A host image or computer tool can return image content with details.media.outbound=false for private model inspection. The bridge correctly excludes that result from outbound telemetry, but still sends its image bytes to Codex as inputImage content. Codex returns those bytes in a raw function_call_output under the host call_id, and this new unconditional branch saves them and marks them host-owned reply media. Correlate raw outputs with native versus host tool-call ownership before materialization so private inspection results cannot become user attachments. This is the unresolved previous P1 finding.
    Confidence: 0.99
  • [P2] Retain the native image path when recording its managed copy — extensions/codex/src/app-server/event-projector-media.ts:169-172
    When view_image reads /tmp/screenshot.png, its typed ImageView item carries that path under the call identity, but this new image record retains only a raw-derived item ID and bytes. recordNative ignores ImageView, so no savedPath alias ever reaches projectDelivery. If the message tool subsequently sends the original path, a confirmed source reply cannot suppress this managed copy, and an outbound send cannot associate it with the delivered attachment. Retain the native path by call identity in both notification orders and attach that alias to the managed image record. This is the unresolved previous P2 finding.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e7f054619274.

Merge-risk options

Maintainer options:

  1. Resolve the reported conflicts (recommended)
    The contributor should reconcile the branch with main and preserve the existing media-policy and delivery-identity owners.

Provenance checked

  • Generated-image materialization and ordering keeps the original intent (e20c029: The projector split separated media persistence from protocol ordering so asynchronous image writes could not consume newer assistant state.)
  • Bounded Gateway-managed image storage keeps the original intent (a7cecc8: Remote Codex artifacts must be transferred into bounded Gateway-owned media rather than delivered through inaccessible remote paths.)

Testing

Proof path: in-process harness.

Security

Needs attention: The patch bypasses the existing private-inspection publication decision for echoed host-tool images.

Evidence

Security concerns:

  • [high] Private image content becomes outbound media — extensions/codex/src/app-server/event-projector-media.ts:141
    The nearest forbidden publication case is a host-tool result explicitly marked outbound=false; its raw echo reaches managed storage and host-owned delivery without preserving that decision.
    Confidence: 0.99

What I checked:

Likely related people:

  • Omar Shahine: Raw commit bbad877 adds extensions/codex/src/app-server/event-projector-media.ts:106 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: bbad877aed4a; files: extensions/codex/src/app-server/event-projector-media.ts)
  • Vincent Koc: Raw commit 749dbcb adds extensions/codex/src/app-server/event-projector-media.ts:43 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 749dbcb2a7bf; files: extensions/codex/src/app-server/event-projector-media.ts)

PR surface

Source +57, Tests +33. Total +90 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 82 25 +57
Tests 1 33 0 +33
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 115 25 +90

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #153949
Summary: These candidates address the same missing projection of nested native tool-output images.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The central bug loses requested screenshots in Codex-backed replies, with a limited workflow blast radius.
  • merge-risk: 🚨 message-delivery: Missing native source-path aliases prevent managed screenshot copies from matching confirmed sends and source replies.
  • merge-risk: 🚨 security-boundary: Raw host-tool echoes can turn explicitly private inspection images into host-owned reply attachments.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-20T20:30:01.656Z sha 5384058 :: needs real behavior proof before merge. :: [P2] Keep screenshot attachments separate from generation side effects
  • reviewed 2026-09-20T21:03:45.861Z sha 545552b :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-06T22:43:39.683Z sha 545552b :: needs real behavior proof before merge. :: [P1] [P1] Exclude host dynamic-tool echoes from native attachment projection | [P2] [P2] Retain the native image path when recording its managed copy

Reviewed October 27, 2026, 9:16 PM ET / October 28, 2026, 01:16 UTC (Revision 4).

…ounting

Projected native tool-output images (e.g. a screenshot from Codex's
ImageView) were being tracked in the same identity set as real
image-generation results, so hasGeneratedMedia() reported them as a
billable/replay-unsafe side effect. Delivery media from a tool-output
attachment carries no such side effect; only actual generated images do.
@chelsealong

Copy link
Copy Markdown
Contributor Author

Fixed the correctness blocker: `hasGeneratedMedia()` was keyed off the same `itemIds` set used for projected tool-output attachments, so a native tool-output image (e.g. an ImageView screenshot) was flagged as a billable/replay-unsafe image-generation side effect. Split identity tracking so only actual image-generation results (native imageGeneration items, raw image_generation_call events) count toward hadPotentialSideEffects/replaySafe; tool-output-projected images no longer do. Updated the regression test's expectation accordingly (hadPotentialSideEffects: false, replaySafe: true for the tool-output case) and confirmed it fails without the fix via git checkout HEAD~1 -- extensions/codex/src/app-server/event-projector-media.ts. Full suite (89 tests across the four files listed in the PR) still passes, oxlint/oxfmt clean.

Left the broader test-matrix/identity-fallback suggestions for a follow-up so we don't duplicate the local candidate you mentioned — happy to look at your diff/fixtures if you want to share them.

@chelsealong

Copy link
Copy Markdown
Contributor Author

Re the remaining "real behavior proof" checklist item: I can't produce a live Codex round-trip or before/after Control UI screenshots from this sandbox — no OpenAI/Codex API credentials are provisioned, outbound network to the Codex API host is blocked, and this checkout is source-only (no node_modules, no built Control UI) rather than something I can stand up to run/screenshot. I don't want to fake that evidence. @sobechestnut-dev mentioned they already have live Control UI before/after/reload verification in progress on their local candidate — that seems like the more direct path to satisfying this requirement than a second attempt from here. A maintainer can also trigger the @openclaw-mantis verify comment ClawSweeper suggested if live-capture tooling is available to them.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 20, 2026
@chelsealong

Copy link
Copy Markdown
Contributor Author

Re-checked the sandbox specifically for this re-review round: api.openai.com is actually reachable from here (returns 401 — auth required), so network egress isn't the blocker I described earlier; the real gap is that no OpenAI/Codex API credentials are provisioned in this environment, and this checkout is source-only (no node_modules, no built Control UI), so there's no app to run or screenshot even with credentials. I still can't produce a live Codex-to-Control-UI round trip or before/after reload screenshots from here without fabricating them. That capability exists on #154053 (sobechestnut-dev's candidate, already in progress per their earlier comment) or via a maintainer-triggered @openclaw-mantis verify run if live-capture tooling is available to them.

@chelsealong

Copy link
Copy Markdown
Contributor Author

Checked the `check-test-types-core-2` CI failure (log wasn't readable via the Checks UI, but `gh run view --log-failed` worked):

```
src/state/openclaw-state-db-task-identifiers.test.ts(6,3): error TS2459: Module '"../agents/subagents/registry/subagent-registry.store.sqlite.js"' declares 'bindSubagentRunRecord' locally, but it is not exported.
```

That file isn't touched by this PR (which only changes the two `extensions/codex` files listed above) and doesn't exist at all on this branch's HEAD — it's a src/state test. On current `upstream/main`, `bindSubagentRunRecord` has been moved out of `subagent-registry.store.sqlite.ts` into a new `subagent-registry.store.codec.ts`, and the test correctly imports it from there. This branch is 120 commits behind `main` and still has the old (pre-move) layout, so the merge-time type check trips on a symbol relocation this PR never touched. Syncing the branch with `main` would resolve it; I haven't done that here since it's unrelated to the requested fix and outside this PR's scope. `openclaw/ci-gate`'s other failure is the known CLA-signing gate, unrelated to code.

No update to the "real behavior proof" checklist item: still no Codex API credentials or a built Control UI in this sandbox to produce a live before/after round trip, as noted in the two comments above.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 6, 2026
@chelsealong

Copy link
Copy Markdown
Contributor Author

I rechecked the unchanged PR head and current main. Main still drops images nested in raw tool output. The October 6 review’s two findings remain unresolved on this branch: host-tool image echoes can bypass the private-inspection decision, and managed screenshot copies lack the original path needed for delivery matching. I made no code changes and cannot provide the requested live Codex screenshot and reload evidence from this environment.

@clawsweeper clawsweeper Bot removed the status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. label Oct 14, 2026
@roboclaw-bot roboclaw-bot added the clawtributors PR from a clawtributor label Oct 28, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 28, 2026
@chelsealong chelsealong closed this Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawtributors PR from a clawtributor extensions: codex merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex tool-output screenshots are dropped before Control UI reply

3 participants