Skip to content

fix(codex): deliver native tool output images - #154053

Closed
DonnieFi wants to merge 3 commits into
openclaw:mainfrom
DonnieFi:fix/153949-codex-tool-output-images
Closed

DonnieFi wants to merge 3 commits into
openclaw:mainfrom
DonnieFi:fix/153949-codex-tool-output-images

Conversation

@DonnieFi

@DonnieFi DonnieFi commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #153949

What Problem This Solves

Codex can return screenshots as nested input_image items inside custom_tool_call_output or function_call_output. OpenClaw previously ignored those bytes, so the assistant could refer to “the image above” while chat received no attachment.

This change projects validated nested images through the existing managed-media path. It uses stable item identities for deduplication, enforces the existing byte and MIME limits, records delivery receipts, and keeps base64 out of transcript text. Screenshot-view output remains replay-safe and is not counted as image-generation side-effect evidence. The decoder also accepts the application/octet-stream data URL currently emitted by Codex and confirms the actual image type from its bytes.

Evidence

  • Regression fixture failed before the production change for both raw response shapes.
  • 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 — 85 tests passed.
  • node scripts/check-changed.mjs -- extensions/codex/src/app-server/event-projector-media.ts extensions/codex/src/app-server/event-projector.media.test.ts — passed.
  • git diff --check — passed.
  • Fresh P1 autoreview — clean.

Related: #154033. This version keeps screenshot delivery separate from generated-image accounting and covers current Codex octet-stream output.

Evidence (clawsweeper P1/P2 follow-up)

  • [P1] Host dynamic-tool ownership: raw function_call_output echoes whose call_id was registered through recordDynamicToolCall are skipped, so model-only (media.outbound=false) dynamic-tool images can no longer be republished as host-owned reply attachments; native tool outputs such as view_image still project. Sibling codex source inspected personally at 6b9826e3aa83: dynamic.rs maps host-returned content to FunctionCallOutputContentItem under the host's call_id, and view_image.rs emits ImageViewItem { id: call_id, path }.
  • [P2] Source identity: ImageView items attach their path as the savedPath alias of ${call_id}:image:* records (both notification orders), so projectDelivery matches confirmed original-path sends: a source reply suppresses the managed copy, a target send attributes it once.
  • Regression proof: the four new cases in event-projector.media-tool-output.test.ts fail on the pre-fix projector for the intended reasons (toolMediaUrls leaked, target alias missing) and pass after the fix.
  • node scripts/run-vitest.mjs on media-tool-output, media, replay-safety, dynamic-tools, final-media, tool-media-payloads — green (3 shards); pnpm tsgo:extensions and pnpm tsgo:extensions:test — passed; oxfmt and git diff --check — clean.
  • Live Codex-to-chat runtime capture was not run locally; requesting ClawSweeper re-review on the updated head.

@clawsweeper

clawsweeper Bot commented Sep 20, 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.

@DonnieFi

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added extensions: codex size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 20, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 20, 2026
Move nested tool-output image regressions into a sibling file so the
grandfathered media suite does not grow past the line cap, and add
id-only, text-only, and mixed generation cases.
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 20, 2026
@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 21, 2026, 9:14 PM ET / September 22, 2026, 01:14 UTC (Revision 2).

ClawSweeper review

What this changes

The Codex plugin converts images nested in native tool output into managed reply attachments, with validation, deduplication, and separate image-generation accounting.

Merge readiness

⛔ Blocked before merge - 9 items remain

The fix remains necessary, and the revisions address direct tool calls, but nested Codex Code Mode output still loses the ownership and source identity needed by both earlier findings. Real behavior proof is also outstanding.

Priority: P2
Reviewed head: c498cceb569ea495ffed9cca6ed42fef55fba180

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The direct-call improvements are useful, but nested-call identity defects still affect privacy and delivery correctness.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Authority-chain proof required: after repairing nested provenance, demonstrate allowed native screenshot delivery and reload persistence through a real Codex-backed chat, plus rejection of a model-only browser image emitted through an outer Code Mode call before outbound delivery. The supplied projector fixtures do not exercise that final boundary. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🧂 unranked krab (1/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Authority-chain proof required: after repairing nested provenance, demonstrate allowed native screenshot delivery and reload persistence through a real Codex-backed chat, plus rejection of a model-only browser image emitted through an outer Code Mode call before outbound delivery. The supplied projector fixtures do not exercise that final boundary. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 12 items Reviewed introduction boundary: Reviewed the pinned merge-base-to-head production diff and the complete added test file. The stale test merge was not used to attribute base-branch changes to this PR.
Still necessary on current main: Current main's raw media projector returns immediately for every type except image_generation_call, leaving nested tool-output images unprojected.
Latest supplied release has the same exclusion: The v2026.9.5 source also accepts only image_generation_call at this boundary. The local release blob was unavailable; the GitHub contents API supplied the source.
Findings 2 actionable findings [P1] Preserve host media policy through nested Code Mode output
[P2] Match nested image sources to their outer output
Security Needs attention Model-only screenshots can become outbound attachments: The deny set records nested host call IDs, but the outer custom output has another ID. Its image bytes are subsequently classified as host-owned media despite the browser tool requiring explicit outbound sharing.

How this fits together

The Codex plugin translates app-server events into OpenClaw replies. Its media projector stores image bytes and passes attachment references and delivery facts to chat delivery and transcript persistence.

flowchart TD
  A[Codex native and host tools] --> B[Raw tool output]
  A --> C[Tool ownership and source paths]
  B --> D[Media validation and projection]
  C --> D
  D --> E[Managed image storage]
  E --> F[Reply delivery and transcript]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Authority-chain proof required: after repairing nested provenance, demonstrate allowed native screenshot delivery and reload persistence through a real Codex-backed chat, plus rejection of a model-only browser image emitted through an outer Code Mode call before outbound delivery. The supplied projector fixtures do not exercise that final boundary. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Preserve host media policy through nested Code Mode output (P1) - The new guard covers direct echoes but misses nested Codex calls. Codex assigns a fresh exec-UUID to a nested OpenClaw tool, while images emitted by its enclosing cell arrive under the outer custom_tool_call_output.call_id. A browser screenshot marked media.outbound=false can therefore be emitted for model inspection under an unregistered outer ID, materialized here, and returned as hostOwnedToolMediaUrls for chat delivery. Preserve the originating media policy across this boundary and cover distinct nested/outer IDs.
  • Match nested image sources to their outer output (P2) - The source-path repair assumes the raw output ID equals the ImageView ID. In Codex Code Mode, view_image emits the nested invocation's ID, while image(...) places its pixels in the outer custom call's output. This lookup consequently misses the saved path. If the same original file was already sent through the message tool, projectDelivery cannot match that receipt and retains the managed copy for another reply. Add a regression using distinct IDs and preserve source identity without relying on equality.
  • Resolve security concern: Model-only screenshots can become outbound attachments - The deny set records nested host call IDs, but the outer custom output has another ID. Its image bytes are subsequently classified as host-owned media despite the browser tool requiring explicit outbound sharing.
  • Resolve merge risk (P1) - Nested Code Mode output currently loses the facts that distinguish model-only images from outbound attachments and already-delivered images from new replies.
  • Complete next step (P2) - Repair nested-call ownership and source matching, then provide after-fix Codex-to-chat evidence covering delivery, reload, and model-only rejection.
  • Improve patch quality - Cover distinct nested and outer call IDs while preserving outbound policy and confirmed-delivery matching.
  • Improve patch quality - Add real Codex-to-chat proof with before/after/reload screenshots and diagnostic output showing model-only rejection; redact private content, addresses, endpoints, and credentials.
  • Improve patch quality - Update the PR body with the proof to trigger a fresh review; if that does not occur, ask a maintainer to comment @clawsweeper re-review.

Findings

  • [P1] Preserve host media policy through nested Code Mode output — extensions/codex/src/app-server/event-projector-media.ts:309-316
  • [P2] Match nested image sources to their outer output — extensions/codex/src/app-server/event-projector-media.ts:335-337
  • [high] Model-only screenshots can become outbound attachments — extensions/codex/src/app-server/event-projector-media.ts:313
Agent review details

Security

Needs attention: Nested Code Mode output can bypass the existing model-only media boundary; no dependency or supply-chain changes were introduced.

PR surface

Source +116, Tests +303. Total +419 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 132 16 +116
Tests 1 303 0 +303
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 435 16 +419

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +116 lines; tests +303 lines Growth extends the existing media owner, but the regression fixtures omit distinct nested and outer call identities.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #153949
Summary: This is one of several open candidates for the same missing native screenshot projection.

Members:

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

Merge-risk options

Maintainer options:

  1. Preserve nested image provenance (recommended)
    Carry reliable ownership and source identity through outer Code Mode outputs before granting attachment delivery, then validate model-only rejection and duplicate suppression.
  2. Consolidate after a replacement is viable
    Pause this branch if the related implementation becomes a verified safe landing path covering the same ownership and delivery cases.

Technical review

Best possible solution:

Native screenshots should reach replies exactly once while host-tool images retain their outbound policy across nested Codex execution.

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

Yes, at source level: current main drops nested image outputs, and the branch's ID matching fails for Codex's separately identified nested calls and outer outputs. Runtime reproduction was not executed.

Is this the best way to solve the issue?

No, not yet: reusing managed media is appropriate, but matching only raw call IDs cannot preserve ownership or delivery identity through Codex Code Mode.

Full review comments:

  • [P1] Preserve host media policy through nested Code Mode output — extensions/codex/src/app-server/event-projector-media.ts:309-316
    The new guard covers direct echoes but misses nested Codex calls. Codex assigns a fresh exec-UUID to a nested OpenClaw tool, while images emitted by its enclosing cell arrive under the outer custom_tool_call_output.call_id. A browser screenshot marked media.outbound=false can therefore be emitted for model inspection under an unregistered outer ID, materialized here, and returned as hostOwnedToolMediaUrls for chat delivery. Preserve the originating media policy across this boundary and cover distinct nested/outer IDs.
    Confidence: 0.95
  • [P2] Match nested image sources to their outer output — extensions/codex/src/app-server/event-projector-media.ts:335-337
    The source-path repair assumes the raw output ID equals the ImageView ID. In Codex Code Mode, view_image emits the nested invocation's ID, while image(...) places its pixels in the outer custom call's output. This lookup consequently misses the saved path. If the same original file was already sent through the message tool, projectDelivery cannot match that receipt and retains the managed copy for another reply. Add a regression using distinct IDs and preserve source identity without relying on equality.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: The underlying defect affects Codex screenshot delivery within an otherwise working chat workflow.
  • merge-risk: 🚨 security-boundary: Outer Code Mode output can republish model-only host-tool images as authorized reply attachments.
  • merge-risk: 🚨 message-delivery: Distinct nested and outer call IDs prevent matching confirmed original-path sends, permitting duplicate 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. Needs real behavior proof before merge: Authority-chain proof required: after repairing nested provenance, demonstrate allowed native screenshot delivery and reload persistence through a real Codex-backed chat, plus rejection of a model-only browser image emitted through an outer Code Mode call before outbound delivery. The supplied projector fixtures do not exercise that final boundary. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [high] Model-only screenshots can become outbound attachments — extensions/codex/src/app-server/event-projector-media.ts:313
    The deny set records nested host call IDs, but the outer custom output has another ID. Its image bytes are subsequently classified as host-owned media despite the browser tool requiring explicit outbound sharing.
    Confidence: 0.95

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • omarshahine: 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-20T21:07:03.445Z sha 0fb399b :: needs real behavior proof before merge. :: [P1] Preserve outbound policy for host-owned dynamic tool images | [P2] Retain original image paths for confirmed-delivery matching

Address the clawsweeper P1/P2 findings on the raw nested-image path:

- Register host dynamic-tool call ids at recordDynamicToolCall and skip
  their raw echoes, so media.outbound=false results cannot surface as
  host-owned reply attachments.
- Carry the native view_image source path from ImageView items as a
  savedPath alias on tool-output records so confirmed original-path
  sends (source reply and target) match and the managed copy is not
  delivered twice.
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 6, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: M stale Marked as stale due to inactivity 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

1 participant