Skip to content

[codex] fix gateway chat.abort send race#84274

Closed
NianJiuZst wants to merge 1 commit into
openclaw:mainfrom
NianJiuZst:codex/fix-chat-abort-send-race-84176
Closed

[codex] fix gateway chat.abort send race#84274
NianJiuZst wants to merge 1 commit into
openclaw:mainfrom
NianJiuZst:codex/fix-chat-abort-send-race-84176

Conversation

@NianJiuZst

Copy link
Copy Markdown
Contributor

Summary

  • register chat.send runs in chatAbortControllers before awaited attachment/model preparation so immediate chat.abort calls can still find the active run
  • short-circuit pre-dispatch sends that were already aborted so they do not enqueue a chat run or reach dispatchInboundMessage
  • update the attachment parsing race test and add a focused regression that aborts during attachment preparation

Root Cause

chat.send only registered its abort controller after awaited attachment preparation finished, while chat.abort returns aborted: false immediately when the runId is absent. An immediate abort during image/file preparation could therefore miss the in-flight run window.

Verification

  • node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat-b.test.ts src/gateway/server-methods/chat.abort-authorization.test.ts src/gateway/chat-abort.test.ts

Real behavior proof

Behavior addressed: chat.abort no longer misses an active chat.send run when the abort arrives during attachment preparation.
Real environment tested: Local Gateway Vitest harness on rebased upstream/main.
Exact steps or command run after this patch: node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat-b.test.ts src/gateway/server-methods/chat.abort-authorization.test.ts src/gateway/chat-abort.test.ts
Evidence after fix: Added a regression in src/gateway/server.chat.gateway-server-chat-b.test.ts that starts chat.send with an image attachment, blocks attachment preparation on model-catalog resolution, issues chat.abort immediately, and asserts aborted: true, active-run cleanup, and no downstream dispatch.
Observed result after fix: The immediate abort succeeds during attachment preparation and the targeted Gateway suite passes on latest upstream/main.
What was not tested: No live gateway/manual UI repro, no broad pnpm check*, and no Crabbox/Testbox run.

Fixes #84176

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: M triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels May 19, 2026
@clawsweeper

clawsweeper Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close this PR as superseded: it targets a valid Gateway abort race, but #84306 is the open canonical fix for the same issue with live Gateway proof plus additional cleanup/error handling that this branch is missing.

Canonical path: Use #84306 as the canonical review and landing path for the Gateway abort race, and close this duplicate branch to avoid splitting review across two similar fixes.

So I’m closing this here and keeping the remaining discussion on #84306.

Review details

Best possible solution:

Use #84306 as the canonical review and landing path for the Gateway abort race, and close this duplicate branch to avoid splitting review across two similar fixes.

Do we have a high-confidence way to reproduce the issue?

Yes from source inspection: current main awaits attachment/model preparation before registering the abort controller, and chat.abort returns aborted:false if the run id is absent. I did not execute the repro because this review was read-only.

Is this the best way to solve the issue?

No for this branch as-is: early registration is the right direction, but the canonical sibling is the safer solution because it also handles aborted prep failures, cleans pre-dispatch media, and supplies live Gateway proof.

Security review:

Security review cleared: The diff only touches Gateway TypeScript behavior and tests, with no concrete security or supply-chain concern found.

What I checked:

Likely related people:

  • steipete: Recent GitHub path history shows repeated work on the central Gateway chat handler and tests, including session route projection, stop matching, transcript IO, and duplicate attachment send races. (role: recent area contributor; confidence: high; commits: 02f8fb7147c0, 8477a67fafc6, 9f7d606469ec; files: src/gateway/server-methods/chat.ts, src/gateway/server.chat.gateway-server-chat-b.test.ts)
  • BunsDev: Path history ties BunsDev to active WebChat send dedupe and sessions abort wait semantics, both adjacent to this race and active-run behavior. (role: adjacent behavior contributor; confidence: medium; commits: bd2f8560fee6, 1f1f70a23f86; files: src/gateway/server-methods/chat.ts, src/gateway/server.chat.gateway-server-chat-b.test.ts)
  • frankekn: Recent history shows work routing WebChat images through imageModel, which is the same attachment/model-preparation path involved in this race. (role: recent attachment-path contributor; confidence: medium; commits: e6d04550cac7; files: src/gateway/server-methods/chat.ts, src/gateway/server.chat.gateway-server-chat-b.test.ts)
  • VACInc: Recent path history includes stop-active-turns work in the same Gateway chat handler, making this a plausible routing candidate for abort lifecycle review. (role: adjacent abort contributor; confidence: medium; commits: b72f0081836e; files: src/gateway/server-methods/chat.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 6048cd43a5ab.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels May 19, 2026
@NianJiuZst
NianJiuZst marked this pull request as ready for review May 20, 2026 01:22
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui gateway Gateway runtime merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: chat.abort fails when called immediately after chat.send due to race condition

1 participant