Skip to content

fix(gateway): accept concurrent first sends in shared sessions - #159371

Merged
obviyus merged 13 commits into
openclaw:mainfrom
chopin-op60:codex/fix-empty-session-send
Sep 28, 2026
Merged

obviyus merged 13 commits into
openclaw:mainfrom
chopin-op60:codex/fix-empty-session-send

Conversation

@chopin-op60

@chopin-op60 chopin-op60 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #159330

What Problem This Solves

Concurrent first sends to an empty shared conversation can fail with a branch-change error even though nobody changed branches.

User Impact

Participants can submit from the same empty starting point without manually retrying valid messages. Actual branch changes and physical-session replacements remain fenced; no configuration or migration is needed.

Why This Change Was Made

Message admission now treats the empty starting point as a valid ancestor when the request pins the matching physical session. Stop and recovery checks retain their stricter captured-leaf fence. The generic transcript classifier, writer barrier, authorization, and callers without a session ID remain unchanged.

The Gateway WebSocket test harness also retains its bound listener through startup rather than releasing the port before the Gateway adopts it. Regression coverage proves a competing listener cannot steal that socket and verifies cleanup. The unrelated residual history-worker diagnostics assertions were removed; main's deterministic held-read coverage remains intact.

No overlap with Pash/Sarah changes.

Evidence

Real Gateway/WebSocket comparison on main 92b337d61552 and candidate 3f942bc92bf9547acd4abf9bfaa60ab76d897a96, with fresh Gateway/UI builds, isolated state, and a credential-free synthetic loopback Responses provider:

  • Twelve distinct authenticated client connections capture one new empty shared conversation. Hold the first model response after its user message persists, then concurrently submit the other eleven clients' captured null leaf and matching session ID with default queue behavior.
  • Main: 1 accepted, 11 rejected with INVALID_REQUEST / active-leaf-changed. Candidate: all 12 accepted.
  • Candidate transcript contains every original input exactly once, in order 0–11. Separate clients read identical histories; the physical session stays unchanged and all work settles. Independent read-only SQLite counts confirm all twelve inputs and integrity_check=ok.
  • Immediate idempotency replay adds no transcript entry. Non-empty and named-ancestor sends succeed. A stale null leaf without a session ID is rejected.
  • Real rewind and branch switching rotate physical identity; stale null and copied-exact expectations are rejected without writes. A genuine branch switch raced against chat.send: the switch succeeded, the send was rejected with active-leaf-changed, and no raced message entered the transcript.

This is controlled real-transport concurrency, not a 30-browser load test or external-provider test. The runtime results remain attributed to the earlier tested head, not the refreshed commit.

The refreshed branch preserves the contributor's follow-up commits, merges main 026348d107c729ac905d8075114f582336d4bfd1, and retains the stop/recovery and reserved-listener fixes. On the reconciled source:

  • 271 tests passed across six focused Gateway files, including all 227 directive-tag/admission tests, stop-cascade, listener handoff and fixture lifetime checks: 112.22 seconds wrapper wall (109.25 seconds Vitest), --maxWorkers=1.
  • After removing the unrelated history-worker diagnostics assertions, its six tests passed again: 25.60 seconds wrapper wall (23.12 seconds Vitest). The other five files were unchanged.
  • Selected gateway-root, gateway-server, and gateway-methods type graphs passed; type-aware lint and formatting passed for all eight remaining changed files.

Earlier CI attempts encountered history-projection, Gateway port-collision, and history-broadcast timing failures. The refreshed head is bbdad3aa3a2ba47918e79121b9f474749d50c83d.

@clawsweeper

clawsweeper Bot commented Sep 27, 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 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 28, 2026, 11:12 AM ET / 15:12 UTC (Revision 17).

ClawSweeper review

What this changes

The branch lets the Gateway admit concurrent first messages to one shared session and updates Gateway admission and test-fixture coverage.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still rejects concurrent first sends from a captured empty session, and the proposed guard preserves rejection after a physical-session change. The prior review reported no code findings; the current head has downstream checks running after the earlier preflight concern.

Priority: P1
Reviewed head: bbdad3aa3a2ba47918e79121b9f474749d50c83d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused patch has credible real-transport proof and useful fence coverage, with no discrete correctness finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body reports a real Gateway/WebSocket before-and-after concurrency run for the changed admission path, with all 12 candidate sends accepted once and stale branch expectations rejected before writes. Those observations belong to an earlier head whose production guard and harness are unchanged here; focused current-head tests are supplemental. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body reports a real Gateway/WebSocket before-and-after concurrency run for the changed admission path, with all 12 candidate sends accepted once and stale branch expectations rejected before writes. Those observations belong to an earlier head whose production guard and harness are unchanged here; focused current-head tests are supplemental. No stored-data contract changes.
Evidence reviewed 7 items Current main still rejects the empty-leaf race: Current main accepts an exact or named-ancestor relation, but a null leaf becomes off-path after the first append and has no empty-ancestor exception.
Introduced production guard: The new exception applies only to message admission with a supplied matching physical session ID; the other callers retain their strict guard.
Sibling fences: Stop and recovery call the same leaf guard without the empty-ancestor option; admission separately checks for a changed backing session.
Findings None None.
Security None None.

How this fits together

Control UI clients send messages to the Gateway with the conversation's physical session ID and displayed transcript leaf. Gateway admission checks those values before dispatching work and writing the message to the session transcript.

flowchart LR
A[Control UI clients] --> B[Chat send request]
B --> C[Gateway admission]
C --> D{Session and leaf still valid?}
D -->|Yes| E[Queued agent work]
E --> F[Session transcript]
D -->|No| G[Branch change response]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +19, Tests +109. Total +128 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 3 37 18 +19
Tests 5 234 125 +109
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 271 143 +128

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #159330
Summary: This PR is the candidate fix for the linked concurrent first-send issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Land the scoped admission guard through the native PR gates, retaining the physical-session fence and strict Stop and recovery behavior.

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

Yes. Current-main source explains the empty-leaf rejection, and the linked issue supplies a real Gateway and Control UI reproduction; this review did not execute the current head.

Is this the best way to solve the issue?

Yes. The exception stays at message admission, requires the matching physical session, and leaves Stop and recovery guards strict.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 03f92a56beca.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The current Gateway rejects valid concurrent first sends in a real shared-conversation workflow.
  • merge-risk: 🚨 message-delivery: Changing admission for concurrent sends affects which messages reach the transcript; the supplied transport proof and branch-switch cases address the identified risk.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports a real Gateway/WebSocket before-and-after concurrency run for the changed admission path, with all 12 candidate sends accepted once and stale branch expectations rejected before writes. Those observations belong to an earlier head whose production guard and harness are unchanged here; focused current-head tests are supplemental. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports a real Gateway/WebSocket before-and-after concurrency run for the changed admission path, with all 12 candidate sends accepted once and stale branch expectations rejected before writes. Those observations belong to an earlier head whose production guard and harness are unchanged here; focused current-head tests are supplemental. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

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

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 (16 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-27T13:30:54.828Z sha a33eb29 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-27T17:51:00.753Z sha cb130eb :: needs maintainer review before merge. :: none
  • reviewed 2026-09-27T18:09:36.072Z sha 696cc61 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-28T04:35:46.016Z sha f3fad49 :: blocked before merge. :: none
  • reviewed 2026-09-28T05:47:22.390Z sha 2d49112 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-28T06:31:13.512Z sha ea98334 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-28T06:41:52.290Z sha ea98334 :: needs changes before merge. :: none
  • reviewed 2026-09-28T14:59:41.655Z sha ea98334 :: blocked before merge. :: none

@chopin-op60
chopin-op60 marked this pull request as ready for review September 27, 2026 03:35
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed 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. labels Sep 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 27, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Sep 27, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. P2 Normal backlog priority with limited blast radius. 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 27, 2026
@clawsweeper clawsweeper Bot added the status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. label Sep 27, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 27, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Sep 28, 2026
@obviyus

obviyus commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks @chopin-op60 for the follow-up fixes. I'm retaining the stop/recovery leaf fences and the reserved-listener fixture repair with its regression coverage. I'm removing only the remaining diagnostics-channel assertions from session-history-broadcast.worker.test.ts: they are unrelated to concurrent first-send admission, and current main already covers the held-read timing deterministically. Your commits and the rest of the repair remain preserved.

@obviyus

obviyus commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Maintainer landing override for exact head bbdad3aa3a2ba47918e79121b9f474749d50c83d.

Review. The ClawSweeper review is ready on this SHA, and the security-sensitive review found no sensitive product changes.

CI. Fresh run 36440816784, attempt 2, finished with no cancelled selected jobs. The SDK retention lane that failed in attempt 1 passes. The only failures are mocked-Gateway Control UI browser tests. This PR touches no UI files, and those tests don't exercise chat-send admission, the active-leaf fence, or the e2e-ws harness:

@obviyus
obviyus merged commit b4e3631 into openclaw:main Sep 28, 2026
417 of 429 checks passed
@obviyus

obviyus commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Landed in b4e3631. Concurrent first sends now accept a captured empty starting point only within the same physical session; branch switches, Stop, and recovery retain their fences. The real 12-client Gateway comparison changed from 1 accepted / 11 rejected to all 12 accepted exactly once, with ordering, idempotency, and branch-switch controls; the reconciled focused Gateway suite passed 271 tests. Maintainer CI disposition is recorded in #159371 (comment).

Thank you @chopin-op60 for the fix and follow-up safeguards, and @vyctorbrzezowski for the detailed report and reproduction in #159330. The issue is closed.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 29, 2026
…law#159371)

* fix(gateway): accept concurrent first sends in shared sessions

* test(gateway): retain fixture ports and verify worker reads

* fix(gateway): retain leaf fences for stop and recovery

* test(gateway): use current host SQL observer signature

* test(gateway): adopt reserved listener in fixture lifecycle

* test(gateway): keep history worker assertions out of chat admission fix

---------

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: Concurrent first sends to an empty shared conversation are rejected as branch changes

2 participants