Skip to content

fix(gateway): keep chat request bursts responsive under load - #146102

Merged
steipete merged 2 commits into
mainfrom
codex/gateway-burst-latency
Sep 12, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/gateway-burst-latency

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Related: #136862

What Problem This Solves

Fixes an issue where opening a chat on a busy Gateway could take more than 30 seconds even though its session lookup and history handlers each needed less than 200 ms. Small requests sent together reached the handlers seconds apart.

Why This Change Was Made

Disable optional WebSocket compression. Browsers compress even tiny requests when permessage-deflate is negotiated, and ws serially awaits asynchronous inflate callbacks before delivering each frame. Event-loop load multiplies that delay across the startup burst; the server's outbound compression threshold cannot prevent it. Uncompressed frames reach the existing bounded, fair request scheduler together.

Remove the retired compression threshold and deflate-specific payload handoff. Preserve authenticated receiver limits, worker admission, and pre-auth/node control-frame yielding. Update the transport documentation.

CI follow-through also removes repeated snapshot-worker startup from the isolated updater test fixture. Only its explicitly initialized scratch databases use the real in-process snapshot primitive; other sources still use the actual worker. The native executor fixture moves to the existing serial process lane.

User Impact

Chat startup and other request bursts remain responsive under server load. Large histories and rosters use more bandwidth because frames are uncompressed. Clients already support the server declining this optional extension; no protocol version or configuration change is needed.

Evidence

  • Actual Chrome, ten tiny requests, synthetic 100 ms work per event-loop turn: compressed replies arrived at 401–3,104 ms; uncompressed replies all arrived at 106–118 ms. Verified Chrome set the compression bit on these small requests.

  • Independent 20-request ws reproduction: compressed 300–6,008 ms versus all uncompressed replies at 100 ms.

  • Live correlation: four requests sent together reached dispatch 1.65 s, 0.53 s, and 0.41 s apart, then completed in 98–110 ms each. This locates the delay before handler scheduling.

  • Extended the real Gateway burst regression to send compressed frames when negotiated, matching Chrome. It fails before the fix because only the first of 33 requests starts before the next immediate; all 33 start after the fix.

  • 28 focused tests passed across request scheduling, large post-auth frame roundtrips, control/close frames, public worker ingress, and broadcast failure/backpressure recovery.

  • Independent review through P2: no actionable findings.

  • CI diagnosis: the original CLI lane spent 813.57 s running tests; its 493-case updater file accounted for 803.93 s. The same four heavy cases improved from 17.495 s to 4.457 s of test work with the fixture change (74.5%). Normal-wrapper wall time improved from 30.86 s to 23.50 s.

  • The full 493-case updater file passed after the repair, as did 216 tests across native executor, real worker snapshots, ledger cold reads, source/exclusion, and configuration ownership. The native executor’s nine cases run in the serial process lane; the formerly failing healthy-upgrade case passed in 2.191 s. One Linux-only POSIX-lock case remains covered by Linux CI.

  • The first CI attempt failed one existing native-executor readiness assertion; a diagnostic rerun made steady progress but its hosted fallback amplified the slow fixture cost. No test assertions or timeouts were relaxed.

@clawsweeper

clawsweeper Bot commented Sep 12, 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 docs Improvements or additions to documentation gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 15:22
@clawsweeper clawsweeper Bot added 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 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 12:37 PM ET / 16:37 UTC (Revision 4).

ClawSweeper review

What this changes

Disables Gateway WebSocket compression to improve request bursts under load, updates transport coverage and documentation, and reduces updater test process overhead.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary: current main and the latest release still negotiate compression. No actionable introduced defects were found, and the reported browser measurements support the change.

Priority: P2
Reviewed head: 7a405508ff2360dc70da4f99674efbce31d1ef77

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with relevant measured behavior, preserved boundary coverage, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Reported Chrome and real ws request bursts under injected event-loop load demonstrate the compression delay and faster uncompressed replies; the inspected Gateway regression connects that mechanism to production transport and scheduling. Tests provide additional payload and control-frame coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Reported Chrome and real ws request bursts under injected event-loop load demonstrate the compression delay and faster uncompressed replies; the inspected Gateway regression connects that mechanism to production transport and scheduling. Tests provide additional payload and control-frame coverage.
Evidence reviewed 8 items Current main still has the affected behavior: The fetched main revision still enables permessage-deflate with an outbound threshold; the branch's transport change remains absent.
Latest release check: The v2026.9.4 source also negotiates compression. GitHub contents inspection succeeded after local retrieval of the historical blob failed.
Production boundary and dependency signal: The transport explicitly loads the npm ws implementation and disables its optional compression extension. pnpm-lock.yaml pins ws 8.21.3; this establishes the relevant dependency contract. Authentication timing, the bounded scheduler, and receiver payload limits remain intact.
Findings None None.
Security None None.

How this fits together

The Gateway receives WebSocket requests from browser and other clients, authenticates connections, and schedules their handlers. Compression processing happens before that scheduler, so decompression delays can stall otherwise inexpensive chat requests.

flowchart LR
  A[Browser and client requests] --> B[Gateway WebSocket transport]
  B --> C[Uncompressed frame decoding]
  C --> D[Authentication and payload limits]
  D --> E[Bounded request scheduler]
  E --> F[Chat and other handlers]
  F --> G[Client replies]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -29, Tests -84, Docs -2. Total -115 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 3 14 43 -29
Tests 6 83 167 -84
Docs 1 5 7 -2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 102 217 -115

Review metrics

Metric Value Why it matters
Transport default Compression disabled; 0 new configuration options The PR trades smaller history transfers for faster request admission without changing payload limits or the wire protocol version.

Technical review

Best possible solution:

Keep request admission responsive through uncompressed transport while preserving scheduling fairness, authentication limits, and the documented larger-transfer tradeoff.

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

Yes: compressed request bursts under event-loop load have a clear source-backed reproduction path, supported by reported Chrome and ws measurements; this review did not execute it.

Is this the best way to solve the issue?

Yes: disabling the optional extension removes the delay before scheduling at its owner, and the outbound threshold cannot prevent browsers from compressing tiny requests.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 78ca70be45ac.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. Reported Chrome and real ws request bursts under injected event-loop load demonstrate the compression delay and faster uncompressed replies; the inspected Gateway regression connects that mechanism to production transport and scheduling. Tests provide additional payload and control-frame coverage.

Label justifications:

  • P2: Addresses load-dependent chat startup latency with a bounded transport change and concrete before/after measurements.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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): Reported Chrome and real ws request bursts under injected event-loop load demonstrate the compression delay and faster uncompressed replies; the inspected Gateway regression connects that mechanism to production transport and scheduling. Tests provide additional payload and control-frame coverage.
  • proof: sufficient: Contributor real behavior proof is sufficient. Reported Chrome and real ws request bursts under injected event-loop load demonstrate the compression delay and faster uncompressed replies; the inspected Gateway regression connects that mechanism to production transport and scheduling. Tests provide additional payload and control-frame coverage.

Evidence

What I checked:

  • Current main still has the affected behavior: The fetched main revision still enables permessage-deflate with an outbound threshold; the branch's transport change remains absent. (src/gateway/server-runtime-state.ts:315, 78ca70be45ac)
  • Latest release check: The v2026.9.4 source also negotiates compression. GitHub contents inspection succeeded after local retrieval of the historical blob failed. (src/gateway/server-runtime-state.ts:314, 3a9d69db306c)
  • Production boundary and dependency signal: The transport explicitly loads the npm ws implementation and disables its optional compression extension. pnpm-lock.yaml pins ws 8.21.3; this establishes the relevant dependency contract. Authentication timing, the bounded scheduler, and receiver payload limits remain intact. (src/gateway/server-runtime-state.ts:313, 7a405508ff23)
  • Dependency confirms serial decompression: Verified ws 8.21.3 tag c791e707eab3c13dd9a261d2479c3cc4a49a6fed and its package repository metadata. In lib/receiver.js, compressed data enters INFLATING and resumes frame processing from the decompression callback; lib/websocket-server.js negotiates the extension only when enabled. (lib/receiver.js:517, c791e707eab3)
  • Behavior proof and regression coverage: The supplied body snapshot, sourceRevision 2033beabd578d5c06838b3f07cbdbd88ccafc125a3c25266695bb403d2c421e2, reports actual Chrome replies improving from 401–3,104 ms to 106–118 ms under injected event-loop work, plus independent ws measurements. The inspected real-Gateway regression injects negotiated compressed frames before the fix and verifies all 33 request starts after it; separate cases preserve large authenticated frames and control-frame behavior. These executions were reported by the author, not rerun during this read-only review. (src/gateway/server/ws-connection/request-start.server.test.ts:110, 7a405508ff23)
  • Updater shortcut stays within test fixtures: Only database paths explicitly initialized by the test fixture use the existing in-process snapshot primitive; other paths retain the real worker. Independent worker, cold-ledger, and POSIX-lock tests remain. The serial process lane includes the native executor fixture without weakening its assertions or timeouts. (src/cli/update-cli.test.ts:2063, 7a405508ff23)

Likely related people:

  • steipete: 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 (3 earlier review cycles)
  • reviewed 2026-09-12T15:28:37.336Z sha 5f32f31 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-12T16:00:54.768Z sha 5f32f31 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-12T16:32:03.537Z sha 7a40550 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Sep 12, 2026
@steipete

steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor Author

The updater fixture's matched heavy cases improved from 17.495 s to 4.457 s of test work. All 493 updater cases and 216 boundary/configuration tests pass. The native executor fixture now runs in the existing serial process lane. Production snapshot behavior, test assertions, and timeouts are unchanged.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 12, 2026
@steipete
steipete merged commit e61e45a into main Sep 12, 2026
190 checks passed
@steipete
steipete deleted the codex/gateway-burst-latency branch September 12, 2026 16:39
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
…w#146102)

* fix(gateway): keep chat request bursts responsive under load

* test(cli): avoid repeated fixture snapshot process startup
steipete added a commit that referenced this pull request Oct 16, 2026
…bursts (#173933)

Re-enable permessage-deflate on Gateway sockets with no context takeover in
either direction, and replace ws's streaming zlib path per connection with
one inline zlib call per message. ws inflated every browser frame (browsers
compress even tiny requests) through threadpool round trips and stopped
parsing until each finished, so bursts serialized behind busy event-loop
turns (#146102); outbound streaming deflate likewise cost a turn per 16 KiB
and blocked the socket's send queue.

Inline results return on nextTick (setImmediate for receivers that must
yield), inflated size stays bounded by the receiver's live payload limit, and
errors fall back to ws's own path for canonical close codes. Frames of 16 KiB
and up are compressed at level 1; hello-ok, which carries device tokens, is
sent uncompressed.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
…bursts (openclaw#173933)

Re-enable permessage-deflate on Gateway sockets with no context takeover in
either direction, and replace ws's streaming zlib path per connection with
one inline zlib call per message. ws inflated every browser frame (browsers
compress even tiny requests) through threadpool round trips and stopped
parsing until each finished, so bursts serialized behind busy event-loop
turns (openclaw#146102); outbound streaming deflate likewise cost a turn per 16 KiB
and blocked the socket's send queue.

Inline results return on nextTick (setImmediate for receivers that must
yield), inflated size stays bounded by the receiver's live payload limit, and
errors fall back to ws's own path for canonical close codes. Frames of 16 KiB
and up are compressed at level 1; hello-ok, which carries device tokens, is
sent uncompressed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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.

1 participant