Skip to content

fix(gateway): a refused attachment makes every later reply in the turn fail with delivery_ambiguous - #160379

Closed
kiranvk-2011 wants to merge 1 commit into
openclaw:mainfrom
kiranvk-2011:fix/message-action-unsent-media-rejection
Closed

kiranvk-2011 wants to merge 1 commit into
openclaw:mainfrom
kiranvk-2011:fix/message-action-unsent-media-rejection

Conversation

@kiranvk-2011

Copy link
Copy Markdown
Contributor

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_delivered without 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.action arms a pre-send delivery intent. It cancels that intent only when the Gateway's error proves nothing was sent: isConfirmedGatewayMessageActionRejection treats any non-UNAVAILABLE code as proof.

The allowlist check (LocalMediaAccessError, e.g. path-not-allowed) runs before any provider send, and the resulting OutboundDeliveryError has sentBeforeError: false. But createGatewayInflightUnavailableFailure answered it as UNAVAILABLE, which reads as "may have been sent". So the intent stayed pending, and every later terminal send in the same turn returned delivery_ambiguous or already_delivered without sending.

The fix: when the delivery error proves nothing was sent and its cause chain contains a LocalMediaAccessError, answer INVALID_REQUEST with the refusal text. This follows how the same function already unwraps unsent SessionMutationAuthorizationChangedErrors. Partial sends (sentBeforeError: true), queue custody and ordinary provider failures stay UNAVAILABLE.

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:

  1. message.send with media under /data/.openclaw/command-hub-live/… → Local media path is not under an allowed directory (nothing sent).
  2. The same file copied to <state>/workspace/outbox/ → {"status":"delivery_ambiguous","delivered":false}. Nothing was sent; no telegram/send log.
  3. Plain-text follow-up → {"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:

  1. → Local media path is not under an allowed directory: …. The model reported it as "nothing was sent".
  2. → {"ok": true, "messageId": "76"}, logged as outbound 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:

  • wrapped refusal → INVALID_REQUEST
  • unwrapped refusal → INVALID_REQUEST
  • partial send → still UNAVAILABLE
  • unknown provider failure → still UNAVAILABLE

These are pure unit tests: no timers, I/O or Gateway boot. pnpm test <file> --maxWorkers=1 took 122 s wall, 93% of it first-run transform, measured while check-changed was running on the same host. The existing client-side case in message-action-gateway-reconciliation.test.ts already proves that a non-UNAVAILABLE Gateway code cancels the pending intent.

Also run:

  • The related suites (src/gateway/server-methods/message-operation*, send*, src/infra/outbound/message-action*): 688/688 passing.
  • pnpm tsgo:core and oxlint on the changed files: clean.
  • node scripts/check-changed.mjs: passes end to end.

🤖 Generated with Claude Code

… 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]>
@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Sep 28, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 7, 2026, 2:29 PM ET / 18:29 UTC (Revision 2).

ClawSweeper review

What this changes

The 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
Reviewed head: 6ad6a93e87a564bd4d5cdfdd3c98443cd1e98267

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong real recovery evidence supports the classification, but the repair does not yet cover the Gateway-owned receipt path.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The captured body shows the changed Gateway classifier exercised on Linux Docker through Telegram: refusal followed by successful corrected attachment delivery and tool_delivered completion. This supports caller-owned recovery; Gateway-owned cleanup remains a separate solution gap. No stored-data format changes are introduced.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The captured body shows the changed Gateway classifier exercised on Linux Docker through Telegram: refusal followed by successful corrected attachment delivery and tool_delivered completion. This supports caller-owned recovery; Gateway-owned cleanup remains a separate solution gap. No stored-data format changes are introduced.
Evidence reviewed 9 items Pinned introduced change: The merge-base-to-head patch adds local-media rejection classification and four focused tests. Partial sends and held queue custody remain excluded by the existing unsent guard. The stale test merge was not used to infer removal of current-main behavior.
Current main still needs the classification: Fetched main preserves authorization errors, partial-delivery receipts, and queue custody, but still maps unsent local-media refusals to UNAVAILABLE.
Latest stable remains affected: The supplied latest release commit also lacks local-media rejection classification; this is not an already-shipped repair.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

  • Resolve merge risk (P1) - Gateway-owned terminal receipts still remain pending after a proven-unsent attachment refusal; the helper tests and caller-side live recovery do not establish recovery through that ownership path.
  • Complete next step (P2) - Complete proven-unsent local-media cancellation when the Gateway owns the terminal receipt, and verify refusal followed by a corrected send through the registered message.action handler.
Agent review details

Security

None.

PR surface

Source +28, Tests +50. Total +78 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 28 0 +28
Tests 1 50 0 +50
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 78 0 +78

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Make proven-unsent media refusal cancel the terminal intent at its actual owner while preserving partial-send, queue-custody, and unknown-outcome safeguards.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove proof: telegram-e2e: Current Telegram visible-proof status is not_needed.

Label justifications:

  • P1: Production reports show an attachment refusal suppressing later terminal replies, including on the latest stable release.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The captured body shows the changed Gateway classifier exercised on Linux Docker through Telegram: refusal followed by successful corrected attachment delivery and tool_delivered completion. This supports caller-owned recovery; Gateway-owned cleanup remains a separate solution gap. No stored-data format changes are introduced.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body shows the changed Gateway classifier exercised on Linux Docker through Telegram: refusal followed by successful corrected attachment delivery and tool_delivered completion. This supports caller-owned recovery; Gateway-owned cleanup remains a separate solution gap. No stored-data format changes are introduced.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/gateway/server-methods/message-operation-result.media-rejection.test.ts --maxWorkers=1.
  • [P1] pnpm test src/gateway/server-methods/send.test.ts --maxWorkers=1.
  • [P1] pnpm test src/infra/outbound/message-action-gateway-reconciliation.test.ts --maxWorkers=1.
  • [P1] node scripts/check-changed.mjs.
  • [P1] git diff --check.

What I checked:

  • Pinned introduced change: The merge-base-to-head patch adds local-media rejection classification and four focused tests. Partial sends and held queue custody remain excluded by the existing unsent guard. The stale test merge was not used to infer removal of current-main behavior. (src/gateway/server-methods/message-operation-result.ts:84, 6ad6a93e87a5)
  • Current main still needs the classification: Fetched main preserves authorization errors, partial-delivery receipts, and queue custody, but still maps unsent local-media refusals to UNAVAILABLE. (src/gateway/server-methods/message-operation-result.ts:61, 4581d2ae6d12)
  • Latest stable remains affected: The supplied latest release commit also lacks local-media rejection classification; this is not an already-shipped repair. (src/gateway/server-methods/message-operation-result.ts:61, fc23bc864e45)
  • Real after-fix recovery: The captured PR body records Linux Docker and Telegram forum-topic execution: a refused attachment was followed in the same turn by a successful corrected attachment, messageId 76, a sendDocument success log, and tool_delivered completion. This exercises the changed Gateway classification through an actual transport. The downloaded image was inspected and is an unrelated steering illustration, not behavior proof. (6ad6a93e87a5)
  • New production evidence and coverage limit: fix(gateway): a refused attachment makes every later reply in the turn fail with delivery_ambiguous #160379 (comment) reports the same failure on 2026.9.8 after a rejected file type. HostReadMediaTypeError extends LocalMediaAccessError, so the classification covers that refusal. The commenter explicitly distinguishes component checks from end-to-end proof and identifies Gateway-owned receipt cleanup as remaining work. (src/media/local-media-access.ts:39, 6ad6a93e87a5)
  • Gateway-owned cleanup remains missing: The registered message.action handler arms a terminal receipt before dispatch. Its dispatch catch settles partial delivery only and rethrows local-media rejection without cancelling the receipt. Returning INVALID_REQUEST later cannot clear that Gateway-owned intent. This gap predates the introduced patch, so it is remaining solution coverage rather than an introduced-regression finding. (src/gateway/server-methods/send.ts:444, 6ad6a93e87a5)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • shakkernerd: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Complete Gateway-owned proven-unsent cancellation and add a registered message.action refusal-then-retry regression.

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-28T10:49:22.657Z sha 6ad6a93 :: needs maintainer review before merge. :: none

@kiranvk-2011

Copy link
Copy Markdown
Contributor Author

A note on the red checks, so they don't cost review time. None of the failing suites import the changed file (src/gateway/server-methods/message-operation-result.ts).

  • subagent-completion-blocked.e2e.test.ts also fails locally on this PR's parent commit 19e67698e without this change: same assertion, pending instead of suspended inside vi.waitFor's default window. It's pre-existing and timing-sensitive.
  • server.sessions.create.spawn.test.ts passes locally on this branch (11/11). The CI failure was an unhandled worker turn authority changed.
  • The other failures are an install-policy message check, control-plane HTTP 500s and a startup-health count.

I can't re-run jobs from a fork. A maintainer re-run of the failed jobs should show whether they're flakes.

@alexph-dev

Copy link
Copy Markdown
Contributor

Confirmed another production occurrence on OpenClaw 2026.9.8 (fc23bc8), Node 24.19.0, Telegram DM, native Codex message-tool delivery. This time the refusal was file type, not a path outside the allowlist:

  1. message(action="send", final=true, media="<allowed-workspace>/report.diff") threw OutboundDeliveryError: Host-local media sends only allow buffer-verified images, audio, video, PDF, Office documents, archives, and validated plain-text documents (got unknown).
  2. A corrected Markdown attachment in the same turn returned delivery_ambiguous, delivered:false, Do not retry it, without a Telegram outbound success receipt.
  3. A new inbound turn restored ordinary text delivery. Sending the valid Markdown attachment as a nonterminal supporting artifact in a fresh turn also returned a successful native Telegram receipt. We did not clear receipt state or disable duplicate-send protection.

The installed HostReadMediaTypeError extends LocalMediaAccessError, so this PR's proposed classification covers this refusal as well.

Offline component check (no production writes): extracted the unchanged installed createGatewayInflightUnavailableFailure, isConfirmedGatewayMessageActionRejection, and terminal-disposition functions; used in-memory receipt/transport stand-ins and the actual error-class definitions. Applied the PR's equivalent classification only inside the harness:

Input Installed Proposed classification
Direct HostReadMediaTypeError UNAVAILABLE; pending intent not cancelled; next disposition delivery-ambiguous INVALID_REQUEST; cancellation eligible; startable
Wrapped HostReadMediaTypeError, nothing sent Same failure Same recovery
Partial send + media error UNAVAILABLE; ambiguous Unchanged
Queue-held delivery + media error UNAVAILABLE; ambiguous Unchanged
Unknown provider timeout UNAVAILABLE; ambiguous Unchanged

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 (v2026.10.1-beta.1), and current-main source before reporting. The proposed local-media classification is absent from both the fetched beta and main message-operation-result.ts. No runtime patch, session-state edit, or restart was performed.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. labels Oct 7, 2026
@obviyus

obviyus commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks @kiranvk-2011. Here's what we found checking this against current main.

The narrow defect reproduces. A registered message.action send whose local-media attachment is refused, directly or wrapped, leaves the Gateway-owned delivery receipt pending. A repair on top of current main passed 101 focused tests and kept the partial-send, queue-custody and unknown-outcome guards.

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 /etc/hosts attachment was rejected with an accurate error, and both later replies in the same turn delivered. That flow never reaches the pending terminal-intent owner, and we couldn't find a real entry point that does.

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.

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @kiranvk-2011. The turn-wide delivery_ambiguous lockout described here is superseded by #185730 (9344233): it removed the pre-send terminal source-reply receipt from both the registered Gateway handler and the caller path. I checked the current owners and main ancestry; a refused attachment can no longer strand that retired intent.

This does not mean main adopted the proposed INVALID_REQUEST classification—local-media errors still use UNAVAILABLE. A separate classification improvement would need a current consumer failure; the pending-receipt mechanism this PR repairs no longer exists. No new real-channel refusal/retry test was run. Closing as superseded, with thanks for the investigation and reproduction evidence.

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

Labels

gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants