Repository navigation
fix(codex): don't resend a generated image the agent already sent as a copy - #186889
sukhdeepjohar wants to merge 3 commits into
Conversation
…a copy A Codex turn that sent a byte-identical copy of a generated image with message() still delivered the generated image again at the end of the turn, because confirmed sends matched generated images only by path. Record a content key for each attachment when message media is prepared, for files in the agent workspace or Gateway media read without following symlinks, and carry it on the confirmed delivery. Generated images get the same key when saved, so a send of a same-bytes copy counts as delivery of that image. Other paths keep path-only matching. Fixes openclaw#186719
|
🦞👀 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. What this changesThis PR matches confirmed image deliveries by content as well as path so an already-sent copy is not sent again. Example: A Codex turn sends /out/fix/workspace/copy.png with the caption "copy test", containing the generated image's exact bytes.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a concrete duplicate-image bug still present on current main; the reviewed patch has no actionable findings and its current-head gates pass. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Codex adapter projects generated images and confirmed message-tool receipts into destination-scoped delivery evidence consumed by final-reply media deduplication. flowchart TD
A[Codex image events] --> B[Generated media projection]
C[Message attachment preparation] --> D[Confirmed delivery receipt]
D --> B
B --> E[Destination scoped reply deduplication]
E --> F[Telegram delivery]
Technical reviewBest possible solution: Use captured content identity within the existing confirmed-delivery projection while preserving destination matching and uncertain-send behavior. Do we have a high-confidence way to reproduce the issue? Current-main source explains the different-path miss, and the contributor supplies a controlled before/after Telegram reproduction; no target code was executed during this review. Is this the best way to solve the issue? The patch fixes identity at preparation and projection rather than adding transport-specific deduplication, preserving the existing receipt owner and final-reply consumer. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 69af8448ba6d. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +106, Tests +15, Docs +3. Total +124 across 5 files. Added test files: 0. 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. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed November 2, 2026, 9:20 PM ET / November 3, 2026, 02:20 UTC (Revision 3). |
|
The red @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…up-tool-image # Conflicts: # extensions/codex/src/app-server/event-projector-media.ts
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Performance acceptance rule, set before measurement: compare main and the repaired head through an isolated built Gateway, native Codex app-server, and Telegram Test Server. Use a generated image sent from the same path so both versions perform the same delivery. Run serially in alternating baseline/candidate order, with at least five warm samples per version and cold samples reported separately. Record host load and the exact observed timing boundary. Candidate median and p95 turn/final-delivery latency must remain within 20% of main. This comment records the target, not a passing result. |
|
Measured against this rule (one run, serial, alternating order):
Result: warm median -1.0% and p95 -6.6%; the single cold sample is +3.4%. All within 20%, and inside run-to-run spread (warm main ranged 3,838–4,404 ms). Gap: I don't have access to the Telegram Test Server credentials, so delivery went to the session's own chat rather than Telegram. The added work (reading and hashing attachments up to the existing 64 MB cap) runs before the message reaches any channel, so the channel doesn't change it. Telegram's own send latency was not part of this run. |
Closes #186719
What Problem This Solves
Fixes: in a Codex turn, the agent sends a generated image with
message(action=send, media=...)using its own byte-identical copy of the file (another path), and Telegram then shows the same photo a second time when the turn ends.User Impact
A generated image the agent already delivered as a copy is no longer sent again by the end-of-turn flush. Images the turn did not deliver are still sent, and a copy with different bytes is still treated as a different image.
Why This Change Was Made
The Codex harness decides which generated images are already delivered by matching each confirmed
message()send against the generated image's known paths (the Gateway media-store copy and Codex'ssavedPath). A copy the agent made itself has neither path, so the generated image stays pending and, inmessage_tool_onlymode, is delivered again as host-owned media.This change adds content identity to that matching, recorded when the bytes are fixed:
copy.png) or a~/path is resolved first the way the message send loads it (from the agent workspace, or the home directory), so a copy named without its folder is keyed too. Paths anywhere else are never read here and keep path-only matching; the message tool's own media policy still decides whether they can be sent. The confirmed delivery carries the key next to its paths, so a later overwrite of the same path cannot change what the send is taken to have delivered. This read happens during preparation, before the tool's own checks, which is why it is limited to those two directories, which the agent already writes to; the key never appears in any output and only counts once the send is confirmed delivered.savedPath.Accepted edge case: a file rewritten in the moment between preparation and the channel reading it would be keyed by its earlier bytes.
The runtime-behavior docs now say that a confirmed send of a same-bytes copy counts as delivery.
Evidence
Test (red on
main, green here).event-projector.media.test.ts: the existing "local image delivery evidence" test becomes a table driven through the real Codex dynamic-tool bridge and projection:main, where only the copy's path is recorded);copy.png): resolved in the workspace and matched (fails without the bare-name resolution, passes with it);With
main's Codex code and this test file (run on the proof bench), exactly the byte-identical row fails; the other 15 tests in the file pass.The final reply reads these results through the existing route-scoped dedupe (
filterMessagingToolReplyPayload), which drops media listed in a matching target'smediaUrls; the new row asserts the generated image is in that list for the Telegram target, the same output shape the existing path-alias test checks.Test lines are net +15 against
main(+28/−13): the seven cases fold into the existing local-delivery test rather than new tests, and a remote-path test reuses the shared Codex image path fixture.Checks on the current head (merged with
mainat1c03d49956e, which rewroteevent-projector-media.ts; isolated Linux test VM, no network):node-app-server.runtime.test.ts› "gates native resource readiness, resumes exact state, and retains failed-cleanup custody", which fails the same way on unchangedmain.dynamic-tools.test.ts(52 tests), which failed in this PR's earlier CI run, passes onmainand here.Checks on the earlier head (
f34fd634a11, before the merge), on the same kind of VM:run-attempt.steering.test.ts"settles submitted steering before terminal tool interruption (consumed)" ("Codex cancellation could not confirm the turn stopped" after 16.8 s, with six lanes sharing the machine). Rerun alone, that file passes 5/5 with this change and 5/5 onmain.pnpm tsgo:extensionsandpnpm tsgo:extensions:test; oxlint and oxfmt on the changed files.Live run: real Gateway, real Codex app-server, real Telegram. An isolated Gateway built from
mainand from this branch, with the agent on the bundled Codex app-server (0.164.0) andmessages.visibleReplies: message_tool, connected to a real Telegram test bot. A person sent one DM to the bot per run. The model's replies were scripted by a local HTTPS proxy, so the turn is the reporter's sequence every time: a generated image, thenmessage(send)with a byte-identical copy at another workspace path and the caption "copy test". Everything else was real: Codex, the Gateway's image handling, the end-of-turn delivery and Telegram. The copy was written by the harness, standing in for the agent's owncp.Telegram chat on
main(the captioned photo, then the same photo again without a caption):Telegram chat with this change (the captioned photo once):
Proof artifice: the model's replies were scripted by a local HTTPS proxy, and the harness wrote the byte-identical copy in place of the agent's own
cp; Codex, the Gateway, end-of-turn delivery and Telegram were real.The live run used the earlier head; the merge and the bare-name resolution do not change the absolute-path copy it exercises. The photo counts come from the Telegram chat itself. As in the issue, the Gateway logged no outbound send line for these photos, so the log could not count them.