Skip to content

fix: Gateway stalls when background runs start outside the agent workspace - #164594

Merged
steipete merged 1 commit into
mainfrom
steipete/strange-tu-14a7fb
Oct 3, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/strange-tu-14a7fb

Conversation

@steipete

@steipete steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Related: #164049

What Problem This Solves

Fixes: the Gateway freezes for seconds to minutes (dropped websockets, lost chat.send) when a cron job, subagent, or other background run starts in a workspace other than the agent's own workspace.

User Impact

User impact: background runs outside the agent workspace no longer block other users' requests while they start. There is no configuration change and no change to which plugins or tools those runs receive.

Why This Change Was Made

Every plugin registry load is synchronous, including the Promise-returning inspection acquire, so the fix is to stop loading. Two triggers remained after #164049:

  • A run whose workspace is not the agent's canonical workspace (and has no canonical bootstrap workspace) keyed its own prepared runtime and rebuilt the whole plugin inventory on the main thread. In a Gateway, every run workspace already resolves to the same immutable boot inventory, so that rebuild duplicated the configured generation. These runs now borrow the agent's configured generation and stay bound to their own execution workspace (the selection fix: Gateway stalls while background skill reviews or rooted cron jobs start #164049 added for rooted runs); compaction follows the same rule. Runs carrying an admitted plugin generation, and hosts without the shared inventory such as direct CLI runs, keep their own generation.
  • Plugin tool resolution cold-loaded, on every turn, selected tool plugins that the prepared generation had recorded as disabled or failed (for example memory-core when the memory slot is none). Out-of-scope plugins are never recorded by the loader, so a disabled or failed record with matching origin, root, and source is a settled outcome; prepared-runtime selection already treats it that way. The rule applies only when the prepared generation owns the resolution.

Evidence

Forced [trace:embedded-run] stage summaries plus a 5 ms timer-gap meter (Vitest's monitorEventLoopDelay under-reported a 14.8 s synchronous load), in a fixture that publishes Gateway metadata ownership and the production allowGatewaySubagentBinding keys:

Non-canonical workspace run Before After
prepared-runtime stage 10,627 ms 0 ms
Worst main-thread block 10,610 ms 15 ms
Run preparation total 10,718 ms 67 ms
Tool cold loads per turn 2 0
  • run-orchestrator.rooted-proof.test.ts now covers a rooted run and an unrooted task-workspace run against one configured generation (4.9 s). It fails on the old code for each fix independently: without the selection change the task-workspace run cold-builds; without the tools change loadPluginRegistryHandle is called twice.
  • Passed locally: pnpm tsgo:core, pnpm tsgo:test:src, pnpm check:changed, and 458 tests across workspace selection, prepared-runtime context, compaction, plugin tools, the workspace-ownership harness consumers, and the orchestrator suites.
  • Codex autoreview at P2: scoped-clean.
  • Known unrelated failure: run.shared-integration.test.ts ("recovers a successor transcript from its own frozen tool projection") fails on unmodified main because its tool-result-truncation mock lacks restoreCacheTtlToolResultProjections.
  • Still synchronous by design: genuinely uncovered model selections (owners outside the startup plan) and isolated-read-only probes (tools disabled, selection owners only).

…space

Runs whose workspace was not the agent's canonical workspace (cron jobs,
subagents, and other runs without a canonical bootstrap workspace) keyed
their own prepared runtime and cold-loaded the whole plugin inventory
synchronously on the Gateway main thread. In a Gateway every run workspace
resolves to the same immutable boot inventory, so that generation was a
duplicate of the configured one. These runs now borrow the agent's
configured generation and keep their own execution workspace, the same
selection #164049 introduced for rooted runs; compaction follows it.

Plugin tool resolution also cold-loaded, on every turn, selected tool
plugins that the prepared generation had already recorded as disabled or
failed (for example memory-core outside the selected memory slot). Those
records are settled loader outcomes and are no longer reloaded.

Measured with forced [trace:embedded-run] stage summaries in a
Gateway-shaped fixture: prepared-runtime 10627 ms -> 0 ms, worst
main-thread block 10610 ms -> 15 ms, per-turn tool cold loads 2 -> 0.
@clawsweeper

clawsweeper Bot commented Oct 3, 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 agents Agent runtime and tooling size: M labels Oct 3, 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: 🐚 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 Oct 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 6:56 PM ET / 22:56 UTC.

ClawSweeper review

What this changes

Background runs and compaction reuse the agent’s prepared Gateway plugins while keeping their execution workspace, and tool resolution stops reloading plugins already recorded as disabled or failed.

Merge readiness

✅ Ready for maintainer review

This remains a useful, distinct follow-up to the merged rooted-run fix. The reviewed patch preserves execution boundaries and removes two remaining synchronous reload paths; no concrete introduced regression was found.

Priority: P1
Reviewed head: 695c12c2080604ee52453c7f8858e2984bd5f66d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant production-boundary measurements and no supported correctness findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied before/after measurements exercise real run preparation and bundled plugin loading with Gateway metadata ownership; inspected boundary coverage also executes reads and rejects outside-root access. Stopping before inference matches the changed preparation path. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied before/after measurements exercise real run preparation and bundled plugin loading with Gateway metadata ownership; inspected boundary coverage also executes reads and rejects outside-root access. Stopping before inference matches the changed preparation path. No stored-data contract changes.
Evidence reviewed 7 items Pinned introduction and merge result: Reviewed the merge-base-to-head changes. The verified test merge records the pinned main parent followed by the exact PR head, and its result retains the same focused changes.
Generation selection preserves execution workspace: Shared selection requires an immutable runtime metadata generation; explicitly admitted plugin generations retain their existing selection path. Binding keeps the requested execution directory when sharing.
Settled plugin outcomes: Only the selected prepared registry supplies settled disabled/error outcomes, and records must match manifest origin, root, and source. The loader excludes out-of-scope candidates before creating records.
Findings None None.
Security None None.

How this fits together

The Gateway prepares plugin and model runtimes before agent turns execute. Background-run preparation selects that runtime and constructs tools, so synchronous plugin reloads can stall unrelated Gateway requests.

flowchart TD
 A[Background run or compaction] --> B[Resolve execution workspace]
 B --> C{Shared Gateway inventory?}
 C -->|Yes| D[Agent prepared generation]
 C -->|No| E[Workspace generation]
 D --> F[Resolve available tools]
 E --> F
 F --> G[Execute in requested workspace]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +85, Tests +47, Docs +2. Total +134 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 102 17 +85
Tests 3 125 78 +47
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 230 96 +134

Review metrics

Metric Value Why it matters
Reported main-thread blocking 10,610 ms before; 15 ms after The measured preparation path directly explains the reported Gateway starvation.

Technical review

Best possible solution:

Reuse lifecycle-owned plugin facts for covered background runs while preserving task-local execution and explicit plugin reload recovery.

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

Yes, source establishes the noncanonical-workspace preparation and disabled-plugin reload paths, and the author reports before/after measurements through real run preparation. This review did not execute the reproduction.

Is this the best way to solve the issue?

Yes, the patch reuses the existing prepared-generation owner and its settled outcomes while preserving execution workspaces, admission, and lease handling.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 8db9539ee84a.

Labels

Label changes:

  • add P1: The reported synchronous preparation stalls disrupt active Gateway requests and chat admission.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied before/after measurements exercise real run preparation and bundled plugin loading with Gateway metadata ownership; inspected boundary coverage also executes reads and rejects outside-root access. Stopping before inference matches the changed preparation path. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied before/after measurements exercise real run preparation and bundled plugin loading with Gateway metadata ownership; inspected boundary coverage also executes reads and rejects outside-root access. Stopping before inference matches the changed preparation path. No stored-data contract changes.

Label justifications:

  • P1: The reported synchronous preparation stalls disrupt active Gateway requests and chat admission.
  • 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): The supplied before/after measurements exercise real run preparation and bundled plugin loading with Gateway metadata ownership; inspected boundary coverage also executes reads and rejects outside-root access. Stopping before inference matches the changed preparation path. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied before/after measurements exercise real run preparation and bundled plugin loading with Gateway metadata ownership; inspected boundary coverage also executes reads and rejects outside-root access. Stopping before inference matches the changed preparation path. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduction and merge result: Reviewed the merge-base-to-head changes. The verified test merge records the pinned main parent followed by the exact PR head, and its result retains the same focused changes. (c6f032fb8913)
  • Generation selection preserves execution workspace: Shared selection requires an immutable runtime metadata generation; explicitly admitted plugin generations retain their existing selection path. Binding keeps the requested execution directory when sharing. (src/agents/embedded-agent-runner/run/prepared-runtime-context.ts:23, 695c12c20806)
  • Settled plugin outcomes: Only the selected prepared registry supplies settled disabled/error outcomes, and records must match manifest origin, root, and source. The loader excludes out-of-scope candidates before creating records. (src/plugins/tools.ts:490, 695c12c20806)
  • Production-boundary evidence: The captured PR body reports preparation falling from 10,718 ms to 67 ms, worst main-thread blocking from 10,610 ms to 15 ms, and cold tool loads from two to zero. The inspected harness uses real orchestration, bundled plugins, tool construction, and read-tool execution, stopping before inference; it verifies rooted access succeeds and outside-root access is rejected. These observations were supplied by the author, not rerun during this read-only review. (src/agents/embedded-agent-runner/run-orchestrator.rooted-proof.test.ts:182, 695c12c20806)
  • Earlier fix is partial coverage: fix: Gateway stalls while background skill reviews or rooted cron jobs start #164049 merged the canonical-bootstrap rooted-run repair. Its actual patch retains workspace-specific preparation when bootstrap is absent; this PR extends that behavior rather than duplicating the merged fix. (src/agents/workspace-run.ts:142, 0c96fd043ab3)
  • Current main and release necessity: Pinned main still selects shared preparation only through canonical rooted bootstrap. The latest release contains the older binding implementation without that selection helper, so neither inspected main nor the release implements this PR’s complete repair. (src/agents/embedded-agent-runner/run/prepared-runtime-context.ts:9, 8db9539ee84a)

Likely related people:

  • Peter Steinberger: Raw commit 0c96fd0 adds src/agents/workspace-run.ts:142 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0c96fd043ab3; files: src/agents/workspace-run.ts)
  • vincentkoc: 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.

@steipete
steipete merged commit 1660c03 into main Oct 3, 2026
132 of 133 checks passed
@steipete
steipete deleted the steipete/strange-tu-14a7fb branch October 3, 2026 23:27
@steipete

steipete commented Oct 3, 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 4, 2026
…space (openclaw#164594)

Runs whose workspace was not the agent's canonical workspace (cron jobs,
subagents, and other runs without a canonical bootstrap workspace) keyed
their own prepared runtime and cold-loaded the whole plugin inventory
synchronously on the Gateway main thread. In a Gateway every run workspace
resolves to the same immutable boot inventory, so that generation was a
duplicate of the configured one. These runs now borrow the agent's
configured generation and keep their own execution workspace, the same
selection openclaw#164049 introduced for rooted runs; compaction follows it.

Plugin tool resolution also cold-loaded, on every turn, selected tool
plugins that the prepared generation had already recorded as disabled or
failed (for example memory-core outside the selected memory slot). Those
records are settled loader outcomes and are no longer reloaded.

Measured with forced [trace:embedded-run] stage summaries in a
Gateway-shaped fixture: prepared-runtime 10627 ms -> 0 ms, worst
main-thread block 10610 ms -> 15 ms, per-turn tool cold loads 2 -> 0.
Linux2010 added a commit to Linux2010/openclaw that referenced this pull request Oct 12, 2026
… settled outcomes

Addresses review findings on the retained-reuse path:

- Match registration inputs before reuse: the retained registry is only
  consulted when its recorded load-context state shares the prepared
  generation's registration config key and workspace; registries without
  recorded state are not reused. Callers with different plugin config keep
  cold loading instead of receiving closures registered under another config.
- Honor settled prepared outcomes: matching disabled/error records are
  settled generation outcomes (openclaw#164594) and are now excluded before retained
  probing, so retained registrations cannot revive an owner the prepared
  generation already settled.
- Accept optional workspaceDir, matching PluginRuntimeLoadContext's type.
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 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: 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