[codex] fix image completion duplicate sends#87991
Conversation
|
Codex review: needs maintainer review before merge. Reviewed May 29, 2026, 3:10 PM ET / 19:10 UTC. Summary PR surface: Source +21, Tests +52. Total +73 across 5 files. Reproducibility: yes. The linked issue and PR comments give a concrete shipped-beta Discord reproduction with one image_generate completion producing 12 posts, and current main source still routes active generated-media completions through requester wake before fallback direct delivery; I did not run the live repro locally. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Mantis proof suggestion Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land this only after maintainers accept the fail-closed generated-media direct-delivery tradeoff, or replace it with an artifact-level idempotency guard that preserves safe fallback without allowing duplicate media posts. Do we have a high-confidence way to reproduce the issue? Yes. The linked issue and PR comments give a concrete shipped-beta Discord reproduction with one image_generate completion producing 12 posts, and current main source still routes active generated-media completions through requester wake before fallback direct delivery; I did not run the live repro locally. Is this the best way to solve the issue? Yes, with a maintainer caveat. Direct-first deterministic generated-media delivery is the narrowest fix for prompt-driven duplicate sends, while terminal failed direct attempts are the unresolved policy tradeoff because fallback can either rescue a failed upload or duplicate a partially posted artifact. AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against 7aca07072323. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +21, Tests +52. Total +73 across 5 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
|
|
Reopened because #87989 reproduced again after updating the affected instance to New evidence: one The bot closure pointed at the message-tool terminal guard, but the reproduced tool calls all had explicit route keys ( |
Live Dicky validation
Retest result: This proves the patched path delivered the generated image directly and did not wake the requester session into the old |
|
@clawsweeper please re-review. Addressed the P2 fallback edge in e6e0569:
Validation: Result: 4 files passed, 174 tests passed. |
|
@clawsweeper please re-review latest head 7d2ed55. Follow-up changes:
Validation: Result: 6 files passed, 214 tests passed. |
7d2ed55 to
19dfdad
Compare
|
@clawsweeper re-review Rebased onto current |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Follow-up proof for the fallback edge ClawSweeper flagged, plus a live repro of the exact failure mode. A patched test instance was still running the earlier PR dist shape where primary generated-media direct delivery only stopped fallback when it returned const generatedMediaDelivery = await tryGeneratedMediaPrimaryDirectDelivery();
if (generatedMediaDelivery?.delivered) return generatedMediaDelivery;That is not enough. If the platform send posts media successfully and then throws during post-send bookkeeping/mirroring, the direct attempt returns a failed result even though Discord already has the file. The old branch then falls through to active wake/requester handoff and duplicates the generated media. Live evidence from the same generated artifact:
So this was direct/generated-media delivery followed by requester-agent fallback on the same artifact. The current PR head fixes that by treating any generated-media direct attempt as terminal for this path, and by marking direct delivery failure Local targeted gate on current head: I also deployed the current branch delta to the same test instance and restarted the gateway; the patched dist now has: if (generatedMediaDelivery) return generatedMediaDelivery;
...
terminal: trueGateway came back healthy: CLI/Gateway @clawsweeper please re-review this head. |
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. Re-review progress:
|
|
Thanks for the report and patch. I checked this against today's main history, and this PR is now superseded by the maintainer-side completion-delivery changes that landed after it:
Current main also already has the partial-send terminal guard and dispatch stop behavior this PR was trying to add, while the remaining direct-first generated-media change conflicts with the newer requester-agent contract and the same tests now merge-conflict. Closing this as superseded rather than merging an older delivery shape. If this still reproduces on current main, please open a fresh issue/PR with a new repro against the current requester-agent media completion path. |
Summary
Fixes generated-media completion delivery so successful
image_generate/music_generate/video_generatecompletions with expected media URLs are delivered directly and idempotently before waking the requester agent.Root Cause
The completion path already had deterministic generated-media direct delivery, but only as a fallback after the requester-agent/message-tool handoff. That left successful media completions dependent on prompt obedience: the requester agent was told to call
message.sendonce, then remain silent. If the completion session context already contained repeated historicalmessagetool calls, the model could copy that pattern and send the same media attachment multiple times.Changes
Fixes #87995.
Follow-up to closed #87989; GitHub did not allow reopening the closed issue, and the bug reproduced on
2026.5.28-beta.1.Validation
OPENCLAW_TEST_FAST=1 node_modules/.bin/vitest run src/agents/run-wait.test.ts src/agents/subagent-announce-dispatch.test.ts src/agents/subagent-announce-delivery.test.ts --reporter=dot(214 passed)node_modules/.bin/oxfmt --write --no-error-on-unmatched-pattern src/agents/run-wait.test.ts src/agents/subagent-announce-delivery.ts src/agents/subagent-announce-delivery.test.ts src/agents/subagent-announce-dispatch.ts src/agents/subagent-announce-dispatch.test.tsgit diff --cached --checkReal behavior proof
image_generate/music_generate/video_generatecould wake the requester agent and cause repeatedmessage.sendcalls with the same media attachment. This proof verifies the fixed direct delivery path on a real OpenClaw instance.2026.5.28-beta.1 (84fd629), patched with this PR's runtime change.@Dicky make an image of the last hour of this channel.messagetool for that image, so the previous repeated-send path was not entered.