Repository navigation
fix(gateway): a refused attachment makes every later reply in the turn fail with delivery_ambiguous - #160379
fix(gateway): a refused attachment makes every later reply in the turn fail with delivery_ambiguous#160379kiranvk-2011 wants to merge 1 commit into
Conversation
… the turn's replies message.action reported a LocalMediaAccessError (path outside the media allowlist, raised before any provider send) as UNAVAILABLE. The message tool treats UNAVAILABLE as 'may have been sent', so a terminal reply's pre-send delivery intent stayed pending and every later send in the same turn - the corrected path or plain text - came back delivery_ambiguous / already_delivered. The agent then stopped and the user saw 'I generated a reply but could not deliver it'. When the delivery error proves nothing was sent and its cause is a LocalMediaAccessError, answer INVALID_REQUEST with the refusal text: the client cancels the intent and the model gets an actionable validation error. Partial sends and unknown provider outcomes stay UNAVAILABLE. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🦞👀 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: blocked before merge. Reviewed October 7, 2026, 2:29 PM ET / 18:29 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR reports proven-unsent local attachment refusals as validation errors so later replies in the same turn can retry. Merge readiness⛔ Blocked before merge - 2 items remain This remains useful: current main and the latest stable release lack the fix, and the new production report confirms the failure persists. The recorded recovery is convincing, but Gateway-owned receipt cleanup remains incomplete. Priority: P1 Review scores
Verification
How this fits togetherThe Gateway dispatches message-tool requests to channel transports and records terminal reply delivery intents to prevent duplicate sends. Its error responses determine whether callers can safely cancel an intent and retry. flowchart TD
A[Message tool request] --> B[Terminal delivery intent]
B --> C[Attachment validation]
C -->|Allowed| D[Channel transport]
C -->|Refused before sending| E[Gateway error classification]
E --> F[Receipt cancellation and retry]
D --> G[Delivery receipt reconciliation]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +28, Tests +50. Total +78 across 2 files. View PR surface stats
Review metricsNone. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Make proven-unsent media refusal cancel the terminal intent at its actual owner while preserving partial-send, queue-custody, and unknown-outcome safeguards. Do we have a high-confidence way to reproduce the issue? Yes, from source: arm a terminal receipt, reject local media before dispatch, then retry within the same source turn. Production reports corroborate the mechanism; this read-only review did not execute it. Is this the best way to solve the issue? Partly: the classification is a narrow repair for caller-owned intents, but the Gateway-owned handler also needs proven-unsent cancellation and a registered-handler regression. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4581d2ae6d12. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
A note on the red checks, so they don't cost review time. None of the failing suites import the changed file (
I can't re-run jobs from a fork. A maintainer re-run of the failed jobs should show whether they're flakes. |
|
Confirmed another production occurrence on OpenClaw 2026.9.8 (
The installed Offline component check (no production writes): extracted the unchanged installed
All five checks passed. This is component evidence, not an end-to-end test of this PR or proof that every Gateway-owned receipt path clears correctly. The installed Gateway-owned handler's catch also only reconciles partial-delivery errors; please include a registered-handler test to prove cleanup when that side owns the terminal receipt. Checked latest stable, latest beta ( |
|
Thanks @kiranvk-2011. Here's what we found checking this against current main. The narrow defect reproduces. A registered The reported turn-wide failure doesn't reproduce. We ran a built Gateway at 2b988ee with a QA channel routed through the Gateway and a mock provider. The refused So this needs a decision from the delivery or receipt owner: which real turn reaches that claimed-turn path, and whether the pending receipt is reachable in production. The contributor head's CI is also red. Leaving this open for that owner rather than landing it on component evidence alone. |
|
Thanks @kiranvk-2011. The turn-wide This does not mean main adopted the proposed |
Related: #128971, #143461
What Problem This Solves
Fixes: when an agent attaches a file from outside the local media allowlist, the refusal locks the whole turn. The agent's retry with an allowed path, and even a plain-text reply, come back
delivery_ambiguous/already_deliveredwithout being sent, and the user gets "I generated a reply but could not deliver it".User Impact
User impact: a refused attachment is now an ordinary, actionable error ("Local media path is not under an allowed directory: …"). The agent can retry with a file it is allowed to send, and the reply goes through. Sends that may have reached the provider behave as before.
Why This Change Was Made
For a terminal source reply,
message.actionarms a pre-send delivery intent. It cancels that intent only when the Gateway's error proves nothing was sent:isConfirmedGatewayMessageActionRejectiontreats any non-UNAVAILABLEcode as proof.The allowlist check (
LocalMediaAccessError, e.g.path-not-allowed) runs before any provider send, and the resultingOutboundDeliveryErrorhassentBeforeError: false. ButcreateGatewayInflightUnavailableFailureanswered it asUNAVAILABLE, which reads as "may have been sent". So the intent stayed pending, and every later terminal send in the same turn returneddelivery_ambiguousoralready_deliveredwithout sending.The fix: when the delivery error proves nothing was sent and its cause chain contains a
LocalMediaAccessError, answerINVALID_REQUESTwith the refusal text. This follows how the same function already unwraps unsentSessionMutationAuthorizationChangedErrors. Partial sends (sentBeforeError: true), queue custody and ordinary provider failures stayUNAVAILABLE.Evidence
Live reproduction: 2026.9.6 on current main, Linux Docker, claude-cli (Claude Code 2.1.280), Telegram forum topic,
message_tool_only. I read the model's tool calls from the Claude Code session log.Before, one turn went:
message.sendwith media under/data/.openclaw/command-hub-live/…→Local media path is not under an allowed directory(nothing sent).<state>/workspace/outbox/→{"status":"delivery_ambiguous","delivered":false}. Nothing was sent; notelegram/sendlog.{"status":"already_delivered","delivered":false}. The run ended "mute" and the stranded-reply retry hit the same state, so the user got "could not deliver it". It repeated on every later turn that tried an attachment.After this change, the same two sends in one turn:
Local media path is not under an allowed directory: …. The model reported it as "nothing was sent".{"ok": true, "messageId": "76"}, logged asoutbound send ok … operation=sendDocument … threadId=35.The user's own retry then received the attached file and a normal reply, with the run outcome
tool_delivered.Tests: new
src/gateway/server-methods/message-operation-result.media-rejection.test.ts, 4 cases:INVALID_REQUESTINVALID_REQUESTUNAVAILABLEUNAVAILABLEThese are pure unit tests: no timers, I/O or Gateway boot.
pnpm test <file> --maxWorkers=1took 122 s wall, 93% of it first-run transform, measured whilecheck-changedwas running on the same host. The existing client-side case inmessage-action-gateway-reconciliation.test.tsalready proves that a non-UNAVAILABLEGateway code cancels the pending intent.Also run:
src/gateway/server-methods/message-operation*,send*,src/infra/outbound/message-action*): 688/688 passing.pnpm tsgo:coreand oxlint on the changed files: clean.node scripts/check-changed.mjs: passes end to end.🤖 Generated with Claude Code