Skip to content

fix(gateway): Control UI reconnects freeze the Gateway while plugins reload - #167374

Merged
jalehman merged 1 commit into
mainfrom
pb-ed2/borrow-registry-without-subagent-binding
Oct 8, 2026
Merged

jalehman merged 1 commit into
mainfrom
pb-ed2/borrow-registry-without-subagent-binding

Conversation

@jalehman

@jalehman jalehman commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Related: #167351

What Problem This Solves

Fixes: the Gateway freezes for about 9–14 s whenever a Control UI tab connects or reconnects. During the freeze every request on the page stalls, and sessions.github.options times out and shows "Publication status unavailable".

User Impact

User impact: Control UI reconnects no longer stall the Gateway when large external plugins (for example a memory or contextEngine slot plugin) are installed. On the cold path, tools.effective now finishes in about half a second.

Why This Change Was Made

A cold tools.effective refresh resolves the session's dynamic runtime model through a read-only prepared runtime with loadRuntimePlugins: true. That lease never set allowGatewaySubagentBinding. Since #161267, that flag is what lets a prepared runtime borrow the admitting Gateway's live plugin instances. Without it, every cold refresh synchronously loaded the provider, memory-slot, and context-engine plugins on the event loop. Reconnects more than 120 s after the last refresh, or on a new session, always took the cold path.

The lease now sets the flag, which makes it borrow like the other Gateway-hosted prepared loads. The main inventory call in the same file already passes it. The flag's name is misleading: it is effectively the "Gateway-hosted load" marker. #167351 tracks the rename and an audit of the other callers.

Evidence

  • Live A/B on an isolated dev Gateway (separate port and state dir) with the knowledge and lossless-claw plugins loaded. Each run called tools.effective cold on a freshly created session:
    • before: res ✓ tools.effective 9731ms
    • after: res ✓ tools.effective 528ms, with no plugin load during the request
  • Production logs from the affected Gateway: 39 [plugins] loaded 3 plugin(s) events in one day, each 8.7–14 s and each triggered by a webchat connect. 12 of 13 sessions.github.options timeouts that day completed 10–30 ms after one of these loads.
  • New regression test src/agents/tools-effective-inventory.gateway-borrow.test.ts. It runs the real lookup inside a Gateway request scope and asserts that the plugin load receives borrowRegistry. It fails on main (borrowRegistry: undefined) and passes with this change. pnpm test <file> --maxWorkers=1: 64 s wall, 30 s Vitest duration, mostly transform; the test body takes about 1 s. It runs in the database-worker project because the prepared runtime needs the host SQLite broker.
  • 7 related files / 68 tests pass: tools-effective-inventory* (including the real-plugin cold-provider suite), prepared-model-runtime.registry-borrow, and server-methods/tools-effective.
  • pnpm check:changed: everything passed except core lint, which flagged only a dangling _context name in the new test. That is fixed and the touched files lint clean; the full lint lane was not rerun afterwards.
  • Autoreview (Codex, gpt-5.6-sol high): scoped-clean, no findings.
  • pnpm build on the reviewed head 0ea25eb48c7: exit 0 in 9m42s. The UI bundle report lists a startup JS gzip budget violation (364.9 KiB vs 364.7 KiB); this PR touches no UI code, so that comes from the base.

Cold tools.effective refreshes acquired a read-only prepared runtime with
loadRuntimePlugins but without allowGatewaySubagentBinding, so prepared
registry borrowing (#161267) never applied. Each Control UI reconnect past the
120s cache synchronously reloaded the provider, memory-slot and context-engine
plugins (9-14s with large external plugins), stalling every in-flight request.

Refs #167351
@clawsweeper

clawsweeper Bot commented Oct 8, 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 agents Agent runtime and tooling size: S labels Oct 8, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 2:33 PM ET / 18:33 UTC (Revision 2).

ClawSweeper review

What this changes

The branch lets cold tool-inventory model lookups borrow compatible plugin instances from their admitting Gateway.

Example: The user reconnects Control UI with knowledge and lossless-claw installed.

  • Before: A fresh-session tools.effective request takes 9,731 ms while plugins load again.
  • After: The same cold request takes 528 ms without loading plugins during the request.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, useful repair with real Gateway before/after evidence and the requested build completed; mock call-shape coverage limits the patch’s test quality.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The complete PR body records the changed inventory path running on an isolated dev Gateway with knowledge and lossless-claw: fresh-session cold tools.effective improved from 9731 ms to 528 ms with no plugin load during the request. The inspected screenshots belong to the separate publication-row UI patch and are not used to prove this runtime fix. No persisted format or migration changes are introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Reconnecting Control UI stalls every Gateway request for several seconds and can show Publication status unavailable.
Reason: This focused repair applies the already-established Gateway plugin reuse contract to a missed cold inventory caller. The observed latency improvement substantially outweighs the small production change.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still reloads plugins on the cold inventory path. The recorded live comparison supports the fix, and the newly recorded exact-head build resolves the previous review’s blocker; no blocking patch defect was found.

Priority: P1
Reviewed head: 0ea25eb48c7a6a59094ffd424c005a47a057c980

Before merge

None.

Findings

None.

Tests

  • Low-value test src/agents/tools-effective-inventory.gateway-borrow.test.ts: borrows the admitting Gateway's plugin instances instead of loading its own: Remove this mock call-shape test: it asserts load count and borrowRegistry arguments while the loader is mocked, so it cannot establish that plugin instances are actually reused.
Agent review details

How this fits together

Control UI asks the Gateway which tools are available for a session’s selected model. The inventory resolver prepares model facts and returns filtered tool descriptions; plugin borrowing lets that preparation reuse the Gateway’s already-loaded instances.

flowchart TD
  A[Control UI reconnect] --> B[Cold tool inventory request]
  B --> C[Prepare selected model facts]
  C --> D{Compatible live Gateway plugins?}
  D -->|Yes| E[Borrow existing instances]
  D -->|No| F[Load separate instances]
  E --> G[Return filtered tool inventory]
  F --> G
Loading

Technical review

Best possible solution:

Use the existing Gateway borrowing owner for cold inventory preparation while keeping broader naming and tool-selection repairs in their linked work.

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

Yes: current source shows the cold dynamic-model lease omitting the flag required for Gateway borrowing, and the contributor records a failing real-Gateway baseline with large plugins; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes: passing the existing hosting marker repairs the missed reuse at its caller without adding another cache, loader, public API, or configuration option.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6b73b9e932c8.

Provenance checked

Testing

Proof path: shipped entry point. Added test files: 2.

Security

None.

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)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +3, Tests +67. Total +70 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 0 +3
Tests 3 67 0 +67
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 70 0 +70

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: Recorded reconnect-triggered event-loop stalls block concurrent Gateway requests for 9–14 seconds and cause publication-account discovery timeouts.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-08T18:10:52.052Z sha 0ea25eb :: needs changes before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 8, 2026
@jalehman

jalehman commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

On the low-value test note for tools-effective-inventory.gateway-borrow.test.ts: I'm keeping this test, and here's why.

The bug wasn't in the loader. #161267's suites (prepared-model-runtime.registry-borrow, server-plugin-reload.prepared-borrow) already prove that a load given borrowRegistry reuses the lender's live instances. The defect was upstream of that: the cold inventory caller never got a lender in the first place, because resolveLendingGatewayRegistry returned undefined for its lease. The only seam in question is "does this caller, inside a real Gateway request scope, resolve the admitting Gateway as lender?" That is exactly what this test checks. Everything above the loader runs for real:

  • acquireEffectiveToolInventoryRuntimeModelContext
  • the read-only prepared-runtime lease
  • prepareWorkspacePluginRegistries
  • the request-scope registry lookup, Gateway owner binding, and workspace match in resolveLendingGatewayRegistry

Only the module evaluation below that boundary is stubbed, and the existing borrow suites already own that.

It isn't a mirror of the change either:

  • On main it fails with borrowRegistry: undefined, which is the defect.
  • It would still catch a regression if the flag stayed but the lease stopped running under the request scope.
  • It would also catch a regression if the resolver's eligibility drifted, for example a workspace or owner mismatch.

The toHaveLength(1) assertion also pins that the inventory path makes one registry load, not two. Removing the test would leave this caller with no regression coverage except the 9.7 s → 0.5 s live A/B, which CI can't run.

@jalehman
jalehman merged commit cc8a38f into main Oct 8, 2026
142 of 143 checks passed
@jalehman
jalehman deleted the pb-ed2/borrow-registry-without-subagent-binding branch October 8, 2026 20:13
@jalehman

jalehman commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
…penclaw#167374)

Cold tools.effective refreshes acquired a read-only prepared runtime with
loadRuntimePlugins but without allowGatewaySubagentBinding, so prepared
registry borrowing (openclaw#161267) never applied. Each Control UI reconnect past the
120s cache synchronously reloaded the provider, memory-slot and context-engine
plugins (9-14s with large external plugins), stalling every in-flight request.

Refs openclaw#167351
RomneyDa pushed a commit that referenced this pull request Oct 11, 2026
…167374)

Cold tools.effective refreshes acquired a read-only prepared runtime with
loadRuntimePlugins but without allowGatewaySubagentBinding, so prepared
registry borrowing (#161267) never applied. Each Control UI reconnect past the
120s cache synchronously reloaded the provider, memory-slot and context-engine
plugins (9-14s with large external plugins), stalling every in-flight request.

Refs #167351

(cherry picked from commit cc8a38f)
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
Adapt openclaw#167374 for the extended-stable runtime.

Co-authored-by: RomneyDa <[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 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: S 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