Skip to content

fix(gateway): reduce control-plane stalls during concurrent turns - #133429

Merged
steipete merged 2 commits into
mainfrom
codex/gateway-control-plane-fairness
Aug 30, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/gateway-control-plane-fairness

Conversation

@steipete

@steipete steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Related: #133061

What Problem This Solves

Gateway readiness, session lists, history and Control UI HTTP responses can stall during bursts of concurrent agent turns. This extends the session-update repair in #133061. It reduces measured stalls without claiming to eliminate CPU saturation or every latency tail.

Why This Change Was Made

Reuse process-stable plugin lookup facts within their existing lifecycle, resolve normalized CLI backend owners before evaluating live activation policy, and collect provider auth metadata in one owner pass. Attempt preparation shares event-loop start turns while preserving asynchronous overlap, caller context and resource cleanup. Session lists yield according to elapsed projection work instead of repeatedly requeueing cheap rows.

Preparation checkpoints and the external abort listener now share once-only timeout classification. A regression reproduced cleanup receiving cancel for a timeout before listener setup; it now receives timeout, matching the terminal outcome.

No enablement policy is cached. No public configuration, protocol, SQLite schema, persistence semantics or command concurrency settings change. Production diff +355/-367 (net -12), tests/support +412/-126, docs +1. Main's selected-parent session index and nested-tool activity ownership remain intact.

User Impact

The refactor substantially reduces measured control-plane stalls, but a later identical repeat still exceeded the two-second UI HTTP budget. CPU-pressure readiness diagnostics still report degraded load. A previously observed timeline-disabled UI HTTP tail remains a separate follow-up; it is not dismissed as host noise.

Evidence

Built current-main baseline 61edeb8a6fe90ade870d11436eb4308469ac436a and final candidate a272f175688041b1437ae7d407ee0fc6739158e9. Same configured workload: 32 turns, 48 seeded sessions, 128 updates across four clients, three history readers with five-request bursts, six subscribers, visible observer, 100 ms cadence and 1000 ms mock stream delay. Fresh isolated HOME/state and random loopback ports; synthetic streaming provider only. No production Gateway stressed or mutated.

Metric Current-main baseline Final candidate
Readiness max 1781 ms 308 ms
sessions.list max 2413 ms 160 ms
Control UI HTTP max 2398 ms 653 ms
History p99 2327 ms 626 ms
History max 2336 ms 638 ms
Fresh handshake max 743 ms 411 ms

Baseline failed; the tabulated final-candidate run passed with zero operation failures. A later fresh-cache repeat completed all32 turns and128 patches but failed the unchanged UI latency budget: UI HTTP2576ms, readiness1748ms, list1934ms, history1893ms, all operation failures zero. The harness incorrectly exited0 because UI is omitted from its control gate. This is a retained observed latency failure for the separate follow-up, not a complete-fix claim or attributed host-noise explanation. The preceding integrated head 7ace3c08c008 passed three32-turn trials (worst readiness597ms/list339ms/UI769ms/history678ms), an8-turn control and three timeline-disabled32-turn controls (UImax922ms). Final candidate raw requests prove32 streaming Responses requests plus1 embedding request; all32 turns and128 patches completed. Older baseline/candidate mock HTTP record totals65/36 varied; their extra requests cannot be classified without retained raw data. Memory indexing is observed in the later browser captures, so total HTTP record count is not a fixed-turn count.

376 integrated tests passed, followed by30 focused timeout/sibling lifecycle tests. The timeout regression failed before its correction. Full local changed-code gates, frozen-source fresh-cache sourcePerformance build, Control UI build and Codex P0 autoreviews passed. An earlier build overlapped native checkout refresh and was explicitly discarded as proof before rebuilding.

The final real-browser-under-load run also passed: real built Control UI, fresh Playwright context, real Gateway WebSocket traffic, visible session-label changes and the selected synthetic reply while load remained active. All32 turns completed; zero page errors/operation failures. Max readiness899ms/list749ms/UI1209ms/history963ms. This adds browser/asset work and is separate from the HTML-only benchmark. Two prior recordings were interrupted by the recorder's own10s reply wait; retained traces show continued control-plane service and19 persisted replies in the inspected failure. The recorder now uses the benchmark's existing120s completion deadline; the2s latency budgets were never raised. Failed captures remain retained locally.

Final candidate Control UI showing the synthetic reply during load

[email protected]

Captures inspected: synthetic fixture state only. The prior timeline-disabled UI HTTP2164ms observation and final-head UI2576ms repeat remain unresolved; passing repeats do not erase them. UI/history latency were checked directly because the existing benchmark control gate omits those samples; fixing that blind spot and profiling remaining history work is a separate follow-up. No memory-leak or general capacity claim.

AI-assisted implementation. Latest ClawSweeper finding and Rank-up moves addressed by timeout regression and refreshed exact-head proof. Hosted exact-head CI/native landing checks remain pending.

@steipete steipete self-assigned this Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 30, 2026
@steipete
steipete force-pushed the codex/gateway-control-plane-fairness branch from 26dec89 to 7ace3c0 Compare August 30, 2026 18:12
@clawsweeper clawsweeper Bot added merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 2:44 PM ET / 18:44 UTC.

ClawSweeper review

What this changes

The PR yields embedded-agent preparation between stages and reuses lifecycle-owned Gateway, plugin, and provider metadata to reduce control-plane stalls during concurrent turns.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

No concrete introduced correctness or security defect was found. Keep this maintainer-owned, protected PR open until the exact-head validation completes; the prior timeout-classification finding is addressed in the current head.

Priority: P2
Reviewed head: a272f175688041b1437ae7d407ee0fc6739158e9
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The source changes and focused regression coverage are solid, with normal exact-head validation still pending.
Proof confidence 🌊 off-meta tidepool Not applicable: This member-authored PR is exempt from the external-contributor proof gate. Its submitted isolated Control UI and Gateway-load evidence is supportive, while exact-head checks remain the normal merge validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored PR is exempt from the external-contributor proof gate. Its submitted isolated Control UI and Gateway-load evidence is supportive, while exact-head checks remain the normal merge validation.
Evidence reviewed 5 items Timeout repair: The checkpoint now invokes the same once-only abort classifier as the listener, preserving TimeoutError terminal classification before it throws.
Preparation owner and coverage: Every staged preparation call uses the checkpoint, while focused tests cover ordering, async-local context, stale queued work, and timeout/cancellation paths.
Metadata boundaries: The bundled-root cache is lifecycle-owned, CLI backend lookup selects normalized manifest owners before live enablement checks, and provider auth keeps workspace-evidence filtering and disabled-plugin handling.
Findings None None.
Security None None.

How this fits together

Gateway control requests share Node’s event loop with embedded-agent setup and session projection. The changed code schedules setup stages and resolves plugin/provider/session metadata used by Control UI and Gateway clients.

flowchart LR
  A[Concurrent agent turns] --> B[Attempt preparation]
  B --> C[Event-loop stage scheduling]
  C --> D[Gateway control requests]
  E[Plugin and provider metadata] --> F[Session list projection]
  F --> D
  D --> G[Control UI and API clients]
Loading

Decision needed

Question Recommendation
Should this maintainer-owned concurrency change land after the exact-head checks complete? Complete exact-head validation: Wait for the current head’s required checks, then merge if they remain green and no new evidence contradicts the bounded performance claim.

Why: The patch has no supported mechanical repair remaining, but it changes Gateway availability behavior and is protected for explicit maintainer handling.

Before merge

  • Resolve merge risk (P2) - Hosted checks for the exact timeout-corrected head are still incomplete in the supplied rollup. The submitted concurrent-load browser evidence applies unchanged to the session-list surface, but normal exact-head validation should complete before landing.
  • Complete next step (P2) - No mechanical repair remains; protected maintainer handling and exact-head validation are the remaining merge conditions.
Agent review details

Security

None.

PR surface

Source -11, Tests +285, Docs +1. Total +275 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 11 355 366 -11
Tests 9 411 126 +285
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 767 492 +275

Review metrics

Metric Value Why it matters
Production versus test delta production +352/-364 (net -12); tests/support +414/-128; docs +1 The repair is net-negative in production while adding focused lifecycle, metadata, and session-list regression coverage.

Stored data model

Persistent data-model change detected: persistent cache schema: src/plugins/bundled-dir.ts, vector/embedding metadata: src/plugins/plugin-cache-metadata.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete exact-head validation (recommended)
    Verify the timeout-corrected head through its normal Gateway and lifecycle checks before merging an availability-sensitive scheduling change.

Technical review

Best possible solution:

Retain the lifecycle-owned metadata and elapsed-work scheduling design, then land it after the exact-head Gateway and lifecycle validation confirms the corrected abort behavior under the normal merge gate.

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

No: this read-only review did not run the concurrent-load workload. The PR body supplies a detailed isolated Gateway and Control UI scenario, and source inspection confirms the changed owners it exercises.

Is this the best way to solve the issue?

Yes: the patch removes repeated work at lifecycle and projection owners, preserves live activation policy, and avoids new configuration or persistence surfaces rather than masking stalls with looser limits.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9050011d1e40.

Labels

Label changes:

  • add merge-risk: 🚨 availability: Event-loop scheduling and control-plane metadata changes can affect Gateway responsiveness under load.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This member-authored PR is exempt from the external-contributor proof gate. Its submitted isolated Control UI and Gateway-load evidence is supportive, while exact-head checks remain the normal merge validation.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.
  • remove merge-risk: 🚨 other: Current PR review merge-risk labels are merge-risk: 🚨 availability.

Label justifications:

  • P2: This is a bounded responsiveness improvement for Gateway control requests under concurrent agent load.
  • merge-risk: 🚨 availability: Event-loop scheduling and control-plane metadata changes can affect Gateway responsiveness under load.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This member-authored PR is exempt from the external-contributor proof gate. Its submitted isolated Control UI and Gateway-load evidence is supportive, while exact-head checks remain the normal merge validation.

Evidence

What I checked:

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the exact-head Gateway and lifecycle checks complete before merge.

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 (2 earlier review cycles)
  • reviewed 2026-08-30T18:18:58.042Z sha 7ace3c0 :: needs changes before merge. :: [P2] Preserve timeout classification before the first preparation stage
  • reviewed 2026-08-30T18:30:25.047Z sha 7ace3c0 :: needs changes before merge. :: [P2] Classify pre-stage timeouts through the canonical abort path

@steipete
steipete marked this pull request as ready for review August 30, 2026 18:23
@steipete
steipete requested a review from a team as a code owner August 30, 2026 18:23
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the pre-listener timeout classification finding. The new checkpoint and the external listener now use the same abort classifier, with once-only side effects. The regression failed before the fix because the full embedded-attempt cleanup hook received cancel instead of timeout; the timeout terminal wrapper, catalog cleanup, completion diagnostics, both checkpoint paths and repeated listener/checkpoint handling are covered. Thirty focused lifecycle tests now pass. Final changed-code validation and the updated head are in progress.

The refreshed current-main comparison and real isolated Control UI video are now in the PR body. I read the latest Rank-up moves: the timeout regression and current-head proof are addressed by this work; final exact-head CI will be checked after pushing the correction.

The review's stored-data warning is not applicable: the bundled-root field is an in-process PluginCache member invalidated by the existing generation owner. No SQLite schema, persistent cache schema, embedding metadata, migration or storage semantics change.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 30, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Final head a272f175688041b1437ae7d407ee0fc6739158e9 is ready for native preparation. Exact-head CI and openclaw/ci-gate are green. The full local changed-code gates,376 integrated tests,30 focused timeout/sibling tests, frozen-source fresh-cache runtime build and real Control UI video are recorded in the body. The latest ClawSweeper timeout finding and Rank-up moves are addressed; no schema or persistent metadata changes.

This lands the measured owner-level improvement first, as requested, not total stall remediation. A retained final-head repeat still exceeded the unchanged UI HTTP budget (2576ms) despite all32 turns/128 patches completing and zero operation failures. The current harness misses that UI violation. The separate follow-up will repair the measurement gate and investigate the remaining tail; no host-noise or memory-leak attribution is claimed.

@steipete
steipete merged commit 52eed80 into main Aug 30, 2026
255 checks passed
@steipete
steipete deleted the codex/gateway-control-plane-fairness branch August 30, 2026 18:53
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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