Skip to content

fix: keep gateway control traffic responsive under concurrent turns - #123608

Merged
steipete merged 8 commits into
mainfrom
steipete/gateway-control-plane-load
Aug 14, 2026
Merged

steipete merged 8 commits into
mainfrom
steipete/gateway-control-plane-load

Conversation

@steipete

@steipete steipete commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

octopool: pr_view served from shared cache (hit); set OCTOPOOL_FRESH=1 for a live read

What Problem This Solves

Fixes an issue where concurrent node-hosted turns could keep completing while the Gateway control plane stopped accepting new WebSocket clients and delayed health/control RPCs for several seconds.

Why This Change Was Made

Profiling showed that each turn synchronously rediscovered plugin metadata and loaded enabled tool runtimes on the Gateway event loop, then repeated durable workspace-transfer owner reads. This moves stable plugin/tool work to the Gateway lifecycle boundary, carries prepared metadata through run planning, gives accept/control work a turn before serialized workspace generations, combines transfer authorization facts into one authoritative read, and bounds retained workspace snapshots. Workspace plugin overrides still require exact owner provenance; durable environment, credential, epoch, session, generation, and tunnel-instance fencing remain enforced.

User Impact

Operators can open new Gateway clients and use health/control RPCs during node-host fan-out instead of losing observability while data-plane turns continue.

Evidence

Profile attribution

The bounded 2-node/8-turn reproduction initially measured a 9.63s authenticated connection and an 8.01s /readyz probe. Main-thread CPU attribution was:

  • plugin metadata/index discovery: 35.4%
  • workspace skill reconstruction: 14.2%
  • provider/plugin resolution: 14.0%
  • workspace transfer/reconciliation: about 10%
  • garbage collection: 8.4%

A later phase profile isolated 9.9s of synchronous resolvePluginToolRegistry -> loadOpenClawPlugins -> jiti/Babel work (34% of active samples), led by the Teams meeting tool runtime. Transfer authorization also spent 12.2% in repeated durable owner validation. Inference JSON serialization and presence fan-out were not leading frames.

Heap snapshots attributed only about 34MiB of retained growth to module/code graphs, maps, bytecode, and contexts; transcript and transfer buffers were not the retained owner. The snapshot service now prunes superseded manifests after live tokens retire.

Before/after under load

  • Original stress evidence: one new client timed out its opening handshake at 12 concurrent turns; Gateway RSS peaked around 945MiB and all turns still completed.
  • Final real rig, 3 local node hosts / 12 turns: raw WebSocket opening 1.644s; full authenticated hello-ok 1.868s; worst /readyz 1.290s; 12/12 turns completed; zero failed probes; Gateway RSS growth 112MiB.
  • CI-style gate, 3 consecutive 8-turn workspace-fanout runs: fresh authenticated connection max 54.7ms; /readyz max 1.282s; sessions.list max 1.282s; zero failed samples; turn fan-out 6.23-6.59s.

CI closeout and SQLite race disposition

Exact head: 4923d34.

  • Reworked the three benchmark lint findings without suppressions.
  • Split prepared model-runtime lease admission into the concept-named prepared-model-runtime-lease module; the owner file is 676 lines and the extracted file is 238 lines.
  • Prepared configured workspaces now resolve plugin-root presence during lifecycle publication, and retained dynamic workspace owners reuse that fact; the concurrent repeated-run regression observes one stat across simultaneous first acquisitions and retained reuse.
  • Deleted the now-unused changedEntryPaths API instead of retaining a test-only or dead production seam.
  • The SQLite concurrent-delete failure was not treated as known noise. Clean origin/main at 2af5eca passed the exact built-CLI flip proof 3/3, while the PR reproduced the CI failure immediately. The root cause was dashboard-title generation running outside session work admission after the accepted turn released its fence; it could update the session while sessions.delete was materializing and validating its archive. Title generation now owns the same session admission, so deletion waits for that writer. The archive worker's strict snapshot checks remain unchanged. The exact built-CLI flip proof then passed 3/3 on the repaired branch.

Verification

  • Focused Vitest: 14 files / 450 tests across tooling, Gateway, agents, auto-reply, and plugin owners.
  • Additional generation-scope/auth regressions: 88 tests.
  • OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build passed on the exact final source.
  • After the ClawSweeper hot-path review, workspace plugin-root presence is now resolved asynchronously once at generation admission; the exact three-run gate remained green (fresh connection max 900ms, /readyz/sessions.list max 1.468s) with no request-time filesystem probe.
  • git diff --check and changed-file formatting passed.
  • Autoreview: clean, no accepted/actionable findings.
  • Remote changed gate passed every phase through package guards; its Daytona fallback could not run the dead-export/type phases because the 10GB lease exhausted disk while installing unrelated optional cross-platform packages. Exact-head PR CI remains the authoritative broad gate.

Production LOC: +251/-72 (net +179) | Tests: +269/-13. The production growth adds the CI load gate and explicit lifecycle/authority facts needed to remove request-time discovery without weakening workspace-plugin or worker authority boundaries.

@clawsweeper

clawsweeper Bot commented Aug 14, 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 gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 14, 2026
@steipete
steipete marked this pull request as ready for review August 14, 2026 10:41
@steipete
steipete requested a review from a team as a code owner August 14, 2026 10:41
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. 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 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 9:41 AM ET / 13:41 UTC.

ClawSweeper review

What this changes

Moves Gateway turn preparation, plugin metadata, workspace-transfer authorization, and session-title writes onto lifecycle-owned or admitted paths so control clients and health RPCs remain responsive during concurrent turns.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer review: this maintainer-authored, protected PR addresses a credible Gateway availability problem, and its prior workspace-root concurrency finding appears addressed, but the local partial clone could not retrieve the exact-head source tree for a full final-diff verdict.

Priority: P1
Reviewed head: 278dcd4fd4a9b31343e169da898214d2d5ffcdec
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The submitted evidence supports a useful availability repair, but an exact-head source and CI audit remains necessary before a merge recommendation.
Proof confidence 🌊 off-meta tidepool Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; the PR body nevertheless supplies quantitative load evidence.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; the PR body nevertheless supplies quantitative load evidence.
Evidence reviewed 5 items Current metadata fallback: Current main loads plugin metadata when no compatible lifecycle snapshot is available, establishing the hot-path boundary this PR changes.
Current workspace-transfer authority model: Current main separately re-reads environment and credential ownership when validating a transfer context; the PR proposes a combined owner read and revised in-memory fence.
Feature-history provenance: The prepared-runtime and metadata paths have substantial recent history from Peter Steinberger, including the lifecycle metadata reuse work that is adjacent to this change.
Findings None None.
Security None None.

How this fits together

Gateway clients send control RPCs and agent turns through the same Node process. This PR moves expensive per-turn discovery and shared-state writes behind lifecycle preparation and admission fences so control traffic remains responsive while preserving worker and session ownership checks.

flowchart LR
  A[Gateway clients] --> B[Control RPCs and agent turns]
  B --> C[Lifecycle-prepared plugin metadata]
  B --> D[Session and workspace admission]
  C --> E[Agent runtime and tools]
  D --> F[Worker transfer and title updates]
  E --> G[Responsive control responses]
  F --> G
Loading

Decision needed

Question Recommendation
Should this maintainer-owned Gateway availability repair proceed after exact-head CI and the control-plane stress proof are confirmed? Confirm exact-head proof and proceed: Review the final exact-head stress result and required CI, then merge if the lifecycle and authority invariants remain intact.

Why: The branch changes concurrency, session admission, plugin loading, and worker-transfer authority while carrying a protected maintainer label; this needs an accountable human merge decision.

Before merge

  • Resolve merge risk (P1) - This availability- and authority-sensitive branch still needs exact-head CI and a fresh control-plane stress result before merge; the locally available checkout could not retrieve the full exact-head tree for an independent final-diff audit.
  • Resolve merge risk (P1) - The reported production delta is positive for a bug-fix PR, so maintainers should confirm the added lifecycle/authority surface is necessary rather than retaining duplicate preparation paths.
Agent review details

Security

None.

PR surface

Source +291, Tests +295, Other +132. Total +718 across 38 files.

View PR surface stats
Area Files Added Removed Net
Source 24 537 246 +291
Tests 12 328 33 +295
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 137 5 +132
Total 38 1002 284 +718

Review metrics

Metric Value Why it matters
Production versus test LOC production +179 net; tests +256 net (PR body) The bug-fix branch materially grows production lifecycle and authority code, so maintainers should confirm the growth remains the single canonical preparation path.

Stored data model

Persistent data-model change detected: durable storage schema: src/gateway/worker-environments/node-worker-tunnel.ts, durable storage schema: src/gateway/worker-environments/node-workspace-transfer-service.test.ts, durable storage schema: src/gateway/worker-environments/node-workspace-transfer-service.ts, durable storage schema: src/gateway/worker-environments/store.ts, durable storage schema: src/gateway/worker-environments/workspace-reconcile-core.ts, durable storage schema: src/gateway/worker-environments/workspace-result-staging.ts, and 13 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Validate the exact head under control-plane load (recommended)
    Require the final head to pass its control-latency stress gate and required CI before accepting the lifecycle and authority changes.

Technical review

Best possible solution:

Keep one lifecycle-owned metadata and admission path, then merge only after the exact head demonstrates bounded control latency and green required checks without weakening workspace or transfer ownership fencing.

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

Yes. The PR describes a bounded multi-node workspace-fanout scenario that measures fresh authenticated connections, ready probes, and completed turns; the changed benchmark is the intended reproduction harness.

Is this the best way to solve the issue?

Unclear. Lifecycle-owned metadata and admission fences match the affected ownership boundaries, but the exact final tree was unavailable locally, so the complete final implementation cannot be confirmed as the best form.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5523f8a334c9.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; the PR body nevertheless supplies quantitative load evidence.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The PR targets Gateway control and health responsiveness during concurrent live turns, where loss of observability affects active operators.
  • merge-risk: 🚨 compatibility: It changes plugin metadata reuse, auth-planning inputs, session admission, and worker-transfer ownership checks used by existing deployments.
  • merge-risk: 🚨 availability: It changes event-loop scheduling and control-plane work admission, directly affecting Gateway responsiveness under load.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; the PR body nevertheless supplies quantitative load evidence.

Evidence

What I checked:

  • Current metadata fallback: Current main loads plugin metadata when no compatible lifecycle snapshot is available, establishing the hot-path boundary this PR changes. (src/plugins/plugin-metadata-snapshot.ts:337, 5523f8a334c9)
  • Current workspace-transfer authority model: Current main separately re-reads environment and credential ownership when validating a transfer context; the PR proposes a combined owner read and revised in-memory fence. (src/gateway/worker-environments/node-workspace-transfer-service.ts:176, 5523f8a334c9)
  • Feature-history provenance: The prepared-runtime and metadata paths have substantial recent history from Peter Steinberger, including the lifecycle metadata reuse work that is adjacent to this change. (src/agents/prepared-model-runtime.ts:403, 1b2920a5200c)
  • Prior finding follow-up: The reviewed head is a successor of the prior ClawSweeper-reviewed SHA, and its commit message explicitly addresses coalescing workspace-root preparation. (src/agents/prepared-model-runtime-lease.ts, 278dcd4fd4a9)
  • Exact-head inspection gap: The local partial clone has the PR commit object but not its required tree objects; Git attempted its promisor remote and network resolution failed, so the complete exact-head diff could not be read locally. (278dcd4fd4a9)

Likely related people:

  • steipete: Recent main history repeatedly covers prepared model runtimes, plugin metadata, and Gateway responsiveness. (role: recent area contributor; confidence: high; commits: 1b2920a5200c, 192885c4e811, 0aa85c7f83fe; files: src/agents/prepared-model-runtime.ts, src/plugins/plugin-metadata-snapshot.ts)
  • Jason (Json): History attributes a prior concurrent Gateway RPC responsiveness repair to this contributor. (role: adjacent Gateway contributor; confidence: medium; commits: 77f7560b4184; files: src/agents/prepared-model-runtime.ts)

Rank-up moves

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

  • Confirm the final head's required CI and control-plane stress result against the current merge result.

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 (5 earlier review cycles)
  • reviewed 2026-08-14T10:47:49.453Z sha 4b0e83c :: found issues before merge. :: [P2] Remove the request-time workspace filesystem probe
  • reviewed 2026-08-14T10:58:37.376Z sha cae39e7 :: found issues before merge. :: [P1] Preserve the current-first transfer helper contract | [P2] Remove the request-time workspace filesystem probe | [P3] Remove the release-owned changelog entry
  • reviewed 2026-08-14T11:10:43.106Z sha 39f1b80 :: needs changes before merge. :: [P2] Eliminate the per-turn workspace root probe | [P2] Thread prepared metadata through auth selection
  • reviewed 2026-08-14T12:45:13.846Z sha 16a87d3 :: found issues before merge. :: [P2] Remove the per-turn workspace-root probe
  • reviewed 2026-08-14T13:12:10.139Z sha 4923d34 :: needs changes before merge. :: [P2] Coalesce first dynamic-workspace root resolution

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 14, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 14, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 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:

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 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:

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 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 status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@steipete steipete self-assigned this Aug 14, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Exact-head CI is green in run 31807558395. The calibrated control-plane load gate passed three consecutive runs at the approved 4s p100 bound; the 2s fresh-handshake bound remains unchanged.

@clawsweeper

clawsweeper Bot commented Aug 14, 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:

@steipete
steipete merged commit 530b33e into main Aug 14, 2026
175 checks passed
@steipete
steipete deleted the steipete/gateway-control-plane-load branch August 14, 2026 14:17
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 15, 2026
…penclaw#123608)

* fix(gateway): preserve control-plane responsiveness under load

* fix(plugins): accept prepared readonly manifests

* refactor(plugins): prepare workspace ownership before metadata reuse

* chore: leave changelog updates to release flow

* fix(gateway): finish control-plane load repair

* perf(gateway): reuse prepared workspace root facts

* perf(gateway): coalesce workspace root preparation

* test(gateway): calibrate control-plane load bound
Kimiyu-186 added a commit that referenced this pull request Aug 25, 2026
Backport the session-title admission fix from upstream commit 530b33e (#123608) without its unrelated gateway changes. Keep asynchronous disk-budget scans out of the transcript stat regression fixture.
Kimiyu-186 added a commit that referenced this pull request Aug 25, 2026
…ion generations (#128980)

* fix(sessions): keep gateway responsive while large transcript archives are built (#112424)

* fix(sessions): keep gateway responsive during transcript archiving

* test(sessions): strengthen archive worker coverage

* fix(sessions): bound archive worker concurrency

* test(sessions): normalize rollback paths on Windows

* fix(sessions): load source archive worker on node 22

* fix(sessions): align archive fencing with session windows

* test(sessions): adapt cleanup race to archive worker

* fix(sessions): harden archive worker lifecycle

* style(sessions): format archive lifecycle tests

* fix(sessions): release writer lane during archive work

---------

Co-authored-by: Josh Lehman <[email protected]>
(cherry picked from commit 9bfe292)

* fix(sessions): release writer lane during transcript archival (#119460)

(cherry picked from commit 141a16f)

* fix(gateway): fence background titles during session archival

Backport the session-title admission fix from upstream commit 530b33e (#123608) without its unrelated gateway changes. Keep asynchronous disk-budget scans out of the transcript stat regression fixture.

* test(ui): settle custodian mobile layout assertions (#116613)

(cherry picked from commit 871abad)

---------

Co-authored-by: Heming Zeng <[email protected]>
Co-authored-by: Josh Lehman <[email protected]>
Co-authored-by: Jason (Json) <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts 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