Skip to content

[Bug]: post-dispatch chat.send rejection can overwrite terminal abort #90999

Description

@nxmxbbd

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

If chat.abort has already made a chat.send run terminal, a later post-dispatch rejection from the same run can overwrite the cached terminal abort with status:"error" and broadcast an error.

Steps to reproduce

  1. Start from current main at 59a8137b04.
  2. Add a regression that starts chat.send, lets dispatch begin, calls chat.abort for the same run, then rejects the dispatch promise after the abort.
  3. Run node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat-b.test.ts.

Expected behavior

The terminal abort should remain the terminal chat.send result. A same-run dispatch rejection that arrives after the abort should not rewrite chat:<runId> to status:"error" or emit a late chat error for that already-aborted run.

Actual behavior

The regression fails on current main: the chat:<runId> dedupe entry becomes { runId, status:"error", summary:"Error: dispatch exploded after abort" } instead of the expected terminal timeout/aborted payload.

OpenClaw version

Current main at 59a8137b04.

Operating system

Linux source checkout.

Install method

Source checkout; repro uses node scripts/run-vitest.mjs.

Model

N/A --- source-level Gateway repro; no model request is invoked.

Provider / routing chain

N/A --- source-level Gateway repro; no provider routing path is invoked.

Additional provider/model setup details

N/A --- the repro controls the Gateway handler dispatch/abort ordering directly; no provider or model setup is involved.

Logs, screenshots, and evidence

$ git switch --detach 443e8455311d8517c2250d0e3ac1e5983d64e2c9
$ node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat-b.test.ts

Failed Tests 2

FAIL  gateway-methods ../../src/gateway/server.chat.gateway-server-chat-b.test.ts > gateway server chat > chat.send post-dispatch rejection after abort preserves the terminal abort
AssertionError: expected { …(3) } to deeply equal ObjectContaining{…}
-   "status": "timeout",
+   "status": "error",
+   "summary": "Error: dispatch exploded after abort",

FAIL  gateway-server ../../src/gateway/server.chat.gateway-server-chat-b.test.ts > gateway server chat > chat.send post-dispatch rejection after abort preserves the terminal abort
AssertionError: expected { …(3) } to deeply equal ObjectContaining{…}
-   "status": "timeout",
+   "status": "error",
+   "summary": "Error: dispatch exploded after abort",

Tests 2 failed | 68 passed (70)

Impact and severity

Affected: Gateway clients that retry or observe terminal chat.send results after aborting a run whose dispatch later rejects.
Severity: Medium; the run was already terminally aborted, but the later rejection can present the outcome as a dispatch error.
Frequency: deterministic for this post-dispatch abort/rejection ordering.
Consequence: clients can see stale error state for an already-aborted run, and same-run retry observes the wrong cached terminal status.

Additional information

A fix should preserve two orderings separately: abort-before-dispatch-reject keeps the abort terminal; dispatch-reject-before-late-abort keeps the error terminal and clears any late abort tombstone so a later same-id retry cannot replay the stale abort.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions