Repository navigation
fix: Gateway stalls when background runs start outside the agent workspace - #164594
Conversation
…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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 6:56 PM ET / 22:56 UTC. ClawSweeper reviewWhat this changesBackground 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 Review scores
Verification
How this fits togetherThe 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +85, Tests +47, Docs +2. Total +134 across 8 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…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.
… 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.
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:
memory-corewhen the memory slot isnone). 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'smonitorEventLoopDelayunder-reported a 14.8 s synchronous load), in a fixture that publishes Gateway metadata ownership and the productionallowGatewaySubagentBindingkeys:prepared-runtimestagerun-orchestrator.rooted-proof.test.tsnow 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 changeloadPluginRegistryHandleis called twice.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.run.shared-integration.test.ts("recovers a successor transcript from its own frozen tool projection") fails on unmodifiedmainbecause itstool-result-truncationmock lacksrestoreCacheTtlToolResultProjections.