Repository navigation
fix(gateway): reduce control-plane stalls during concurrent turns - #133683
Merged
Merged
Conversation
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
steipete
force-pushed
the
codex/gateway-stall-attribution
branch
from
August 31, 2026 01:19
61f5a19 to
840024d
Compare
Contributor
Author
|
Merged via squash.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Aug 31, 2026
…enclaw#133683) * fix(gateway): reduce control-plane stalls during concurrent turns * fix(bench): validate timeline evidence after gateway cleanup * test(gateway): await account startup after lifecycle handoff
This was referenced Aug 31, 2026
This was referenced Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #133477
What Problem This Solves
Resolves avoidable Gateway control-plane stalls during bursts of concurrent agent turns, particularly with diagnostic timeline recording enabled. Readiness, Control UI requests, and session history can wait while synchronous work delays WebSocket dispatch. This is a measured latency improvement, not a claim that every saturation tail or a memory leak is fixed.
Why This Change Was Made
Profiling separated time waiting before the Gateway message callback from time inside the RPC handler. It identified repeated diagnostic file operations, duplicate session-store path validation, and buffered WebSocket messages dispatched without yielding. These are cumulative costs, not one universal cause of every slow sample.
The repair stays with the owners of that work:
wsoption to yield between buffered messages while preserving frame order and validation.Production delta is +52 lines: bounded batching and explicit exit draining require a lifecycle owner; duplicate session validation and the redundant timeline-options helper are removed. Tests add 345 net lines, benchmark support 34, and documentation 6. Most benchmark diff churn is indentation from separating cleanup and result validation. No new config keys, environment variables, schema, or persistent-store semantics.
User Impact
Concurrent turns leave more opportunity for control requests to run. Diagnostic events may become visible on the next event-loop turn rather than immediately. In-process readers can explicitly flush; external readers should inspect the final artifact after normal exit. Output remains best-effort: forced termination and filesystem failures can lose pending output. The existing file helper's separately reproduced short-write handling remains a dependency follow-up, not a claimed fix here.
Evidence
Current head:
a5f72bc4172e4fc457bdd6ad2db5651953e799a6. Runtime/browser proof was captured at840024d41357ae0940d0c6033f513d847eabdf6f, rebased ontoc753bbd1ced5395fb42c113cdabda5d69bdb75d4; the final commit changes only the secret-owner isolation test. A full hash comparison confirms runtime/build/dependency parity. Both implementation commits were patch-identical across rebase. The native wrapper required the refresh; no guard was bypassed, and runtime/UI were rebuilt afterward.All runtime proof used synthetic data, fresh isolated HOME/state, and owned loopback ports. No production Gateway was exercised. Workload: 32 turns, 48 seed sessions, 128 updates/four clients, three history clients with five-request bursts, six subscribers, visible observation, 100 ms cadence, and 1000 ms mock stream delay. Limits stayed 2000 ms for control/handshake and 120000 ms for completion.
All final runs passed every budget with zero operation failures and zero measured plugin metadata rescans. Three repeats completed 96 turns, 384 updates, and 1205 history samples. The real browser connected, showed live session updates, and rendered the synthetic streaming reply without page errors. Full captures were inspected; the first capture caught a transitional blank render, while subsequent captures show the updates and reply. All 35,152 source/build/dependency hashes matched after both proofs.
Before rebase, the WebSocket-only attempt failed
sessions.listat 2116.7 ms. The combined change passed three runs (list 891.7 ms/history 645.2 ms) and a browser run (list 1950.9 ms). A complete lightweight native-write trace recorded 5236 events in 353 appends, with 127.3 ms total append occupancy during 10.4 s of load; it passed the unchanged budget with zero trace losses. Counts cover complete load-window batches, not final shutdown writes. The slowest list request still waited about 1356 ms before dispatch and spent 12 ms inside its handler.These sequential local runs are not a randomized throughput comparison, and intervening main changes also affect baseline cost. Event-loop utilization still reaches 1 and readiness frequently reports degraded health. No universal latency or memory-leak claim follows.
Validation:
pnpm build sourcePerformanceandpnpm ui:buildpassed after rebase. Fresh Codex autoreviews passed their configured P0-only scope; this is not an all-priority review claim.finally. Cleanup was restructured; the targeted changed gate then passed on Testbox run 33347056069, wrapper exit 0 and lease stopped. The first full CI run 33347261488 exposed the test-ordering defect described below; exact-head CI run 33347957849 is SUCCESS. Fresh PR rollup: 196 successful checks, 39 skips, one neutral, no failures; merge state CLEAN.16e5d6692dc). WebSocket fairness exposes that legal ordering. The fixture now awaits per-account plugin-start signals after start/reload ACKs, preserving every exact count, order, token-isolation, and lifetime assertion without retries or timeout changes. All 14 isolation tests, three handoff-contract tests, typed lint, and fresh P0 review pass.Reproduction:
Local proof additionally redirected Gateway logs into the task artifact directory. Browser proof used the same benchmark with the real built Control UI and a fresh browser context. Its first pre-rebase recorder invocation omitted the repository TypeScript loader and failed before starting a Gateway; the corrected invocations passed.
Named follow-ups: residual session-preparation/transaction work; duplicate Git revision preparation for unborn session workspaces; cold health-check package loading; the file-helper short-write defect; and the separately discovered model-alias raw-to-prepared ownership inconsistency. None is claimed fixed by this PR. Material SQLite redesign remains outside this change.
Latest ClawSweeper comment checked before landing: acknowledgement only, with no published Rank-up moves to apply. Fresh independent Codex reviews and exact-head CI are complete; no ClawSweeper approval is claimed.