Skip to content

fix: Gateway stalls while background skill reviews or rooted cron jobs start - #164049

Merged
steipete merged 2 commits into
mainfrom
fix/rooted-run-plugin-generation-reuse
Oct 3, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/rooted-run-plugin-generation-reuse

Conversation

@steipete

@steipete steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: the Gateway freezes for up to ~2.5 minutes (websockets drop, Control UI reconnects time out, a chat message typed meanwhile is never admitted) when a background Skill Workshop review or a cron job with an execution root starts.

User Impact

User impact: background Skill Workshop reviews (default auto mode) and rooted cron jobs start in milliseconds on the agent's already-prepared plugins instead of rebuilding them on the Gateway main thread, so they no longer starve user-facing RPCs. Their file access stays confined to their execution root.

Why This Change Was Made

Rooted runs pass their execution root (for example <agentDir>/workshop-skills) as the run workspace. The orchestrator used that same directory as the identity of the prepared model runtime and plugin metadata, so it never matched the Gateway's configured generation and synchronously built a new one, then cold-loaded the tool plugins it lacked.

Now, when the run's bootstrap workspace resolves to the agent's canonical (non-fallback) workspace, the prepared runtime and plugin metadata are selected with that canonical workspace, while the run keeps executing, sandboxing, and compacting in its execution root. Runs whose bootstrap workspace is absent or not canonical keep their own workspace-scoped generation, so no trust boundary widens. Existing lease reuse, supersession, and admission checks are unchanged.

Evidence

Production trace (single Gateway process, isMainThread=true, one skill-workshop-review run; no log line from any subsystem during the first stall):

startup stages ... totalMs=99520 ... prepared-runtime:99404ms
core-plugin-tool stages ... totalMs=51961 ... openclaw-tools:plugin-tools:50758ms
liveness heartbeat delayed: overdue=80434ms elapsed=110434ms
host timing gap attributed to event-loop load: gap 110436ms, CPU ratio 0.59

Same reproduction before and after (real bundled plugins through runEmbeddedAgent with Gateway lifecycle active, stopping before inference):

Measurement Before After
Startup total 2,405 ms 28 ms
prepared-runtime 2,350 ms 1 ms
Plugin metadata snapshot builds 1 0
Extra runtime-registry acquisitions 1 0

The fixture's dynamic generation happened to include its tool plugin, so the production plugin-tools cold load was not reproduced. After this change the rooted run binds to the same configured generation foreground turns use, and no foreground turn in the production log emitted a slow plugin-tools stage.

Regression: run-orchestrator.rooted-proof.test.ts (“reuses configured plugins while keeping rooted file tools confined”) fails on the parent commit (generation identity assertion) and passes with the fix; it also proves the read tool reads inside the execution root and rejects a file in the canonical workspace. pnpm test src/agents/embedded-agent-runner/run-orchestrator.rooted-proof.test.ts --maxWorkers=1: 2.3 s test time, 29 s wall on a cold worktree (mostly transform). Unit coverage added for workspace selection (workspace-run.test.ts), binding (prepared-runtime-context.test.ts), and compaction (compact.sandbox-info.test.ts, compaction-runtime-context.test.ts).

Locally: 769 tests across 52 affected files passed; production and test typechecks, lint, format, docs checks, import-cycle checks, and pnpm build passed. Independent Codex autoreview (P1 threshold): scoped-clean.

Release note: Gateway no longer stalls while background Skill Workshop reviews or rooted cron jobs prepare their runtime.

…runs

Rooted runs (skill workshop reviews in auto mode, cron jobs with an
execution root) passed the execution root as workspaceDir, which also keyed
the prepared model runtime and plugin metadata. No configured generation
matched, so each run cold-built its own generation and cold-loaded tool
plugins synchronously on the Gateway main thread (observed: 99 s
prepared-runtime + 51 s plugin-tools, dropping websockets and a chat.send).

When bootstrapWorkspaceDir resolves to the agent's canonical workspace,
select the prepared runtime with that workspace and keep the run bound to
its execution root. Compaction follows the same selection. Non-canonical or
absent bootstrap workspaces keep their own generation.
@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
@steipete
steipete marked this pull request as ready for review October 3, 2026 05:08
@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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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, 1:50 AM ET / 05:50 UTC (Revision 2).

ClawSweeper review

What this changes

Rooted background agent runs and compaction reuse the agent’s prepared plugins while keeping execution and file access confined to the task directory.

Merge readiness

✅ Ready for maintainer review

The PR remains useful: current main still selects rooted runtimes by the execution workspace. The prior test-routing finding is fixed, and no blocking introduced defect was found.

Likely related people: steipete and obviyus are routing candidates based on verified recent area commits; source-line introduction attribution remains unverified.

Priority: P1
Reviewed head: d5177be32cac63e98c7a0acc6065abcccbd10811

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused runtime-reuse repair with relevant boundary evidence and the prior test-routing defect resolved.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured paired run exercises the changed preparation owner through runEmbeddedAgent with real bundled plugins and Gateway lifecycle active, observing startup fall from 2,405 ms to 28 ms. Real-tool assertions demonstrate allowed task-root reads and rejected outside reads; inference and the separate plugin-tools cold-load stage remain outside the demonstrated scenario. 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 captured paired run exercises the changed preparation owner through runEmbeddedAgent with real bundled plugins and Gateway lifecycle active, observing startup fall from 2,405 ms to 28 ms. Real-tool assertions demonstrate allowed task-root reads and rejected outside reads; inference and the separate plugin-tools cold-load stage remain outside the demonstrated scenario. No stored-data contract changes.
Evidence reviewed 8 items Pinned introduction and review continuity: Reviewed the merge-base-to-head changes at d5177be. The sole change since the previous reviewed head registers the rooted proof test in databaseWorkerCoreTestFiles, directly addressing the previous P2 finding and rank-up request.
Existing host-process routing: The infra project includes databaseWorkerCoreTestFiles and explicitly uses pool: forks; agent projects exclude those files. Registration repairs the host-broker prerequisite without weakening admission guards. Tests were inspected, not executed during this read-only review.
Runtime selection preserves execution confinement: Canonical borrowing requires an explicit bootstrap workspace, configured roster, canonical workspace match, and no fallback. Binding preserves the requested execution workspace while adopting committed runtime configuration and agent directories.
Findings None None.
Security None None.

How this fits together

The embedded agent runner prepares models, plugins, and tools for foreground turns and background jobs. Workspace selection determines which prepared runtime it uses, while sandbox preparation determines where the run can access files.

flowchart TD
  A[Background review or cron job] --> B[Resolve agent and bootstrap workspace]
  B --> C{Canonical bootstrap workspace?}
  C -->|Yes| D[Reuse prepared agent plugins]
  C -->|No| E[Workspace scoped runtime]
  D --> F[Execute within task root]
  E --> F
  F --> G[Rooted tools and compaction]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +66, Tests +297, Docs +2. Total +365 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 5 84 18 +66
Tests 6 298 1 +297
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 384 19 +365

Review metrics

Metric Value Why it matters
Preparation latency 2,405 ms before; 28 ms after The supplied paired production-boundary run directly measures the startup work responsible for starving Gateway RPCs.
Production versus test growth production +66 net lines; tests +296; test routing +1 Production growth separates runtime identity from execution confinement; the larger test addition exercises their real composition.

Technical review

Best possible solution:

Use the existing prepared-runtime owner for canonical plugin facts and retain the task root as the execution and filesystem boundary throughout runs and compaction.

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

Yes: prepare the agent’s Gateway runtime, then invoke runEmbeddedAgent with a different execution root and canonical bootstrap workspace. Current main keys preparation by the execution root; supplied before/after evidence exercises this path, though this review did not execute it.

Is this the best way to solve the issue?

Yes: separating prepared plugin identity from execution workspace fixes the mismatched reuse key without adding a competing cache or changing filesystem policy.

AGENTS.md: found and applied where relevant.

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

Labels

Label 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 captured paired run exercises the changed preparation owner through runEmbeddedAgent with real bundled plugins and Gateway lifecycle active, observing startup fall from 2,405 ms to 28 ms. Real-tool assertions demonstrate allowed task-root reads and rejected outside reads; inference and the separate plugin-tools cold-load stage remain outside the demonstrated scenario. No stored-data contract changes.
  • 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.

Label justifications:

  • P1: Reported background-run preparation stalls disconnect Gateway clients and prevent 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 captured paired run exercises the changed preparation owner through runEmbeddedAgent with real bundled plugins and Gateway lifecycle active, observing startup fall from 2,405 ms to 28 ms. Real-tool assertions demonstrate allowed task-root reads and rejected outside reads; inference and the separate plugin-tools cold-load stage remain outside the demonstrated scenario. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured paired run exercises the changed preparation owner through runEmbeddedAgent with real bundled plugins and Gateway lifecycle active, observing startup fall from 2,405 ms to 28 ms. Real-tool assertions demonstrate allowed task-root reads and rejected outside reads; inference and the separate plugin-tools cold-load stage remain outside the demonstrated scenario. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduction and review continuity: Reviewed the merge-base-to-head changes at d5177be. The sole change since the previous reviewed head registers the rooted proof test in databaseWorkerCoreTestFiles, directly addressing the previous P2 finding and rank-up request. (test/vitest/vitest.database-worker-core-paths.mjs:20, d5177be32cac)
  • Existing host-process routing: The infra project includes databaseWorkerCoreTestFiles and explicitly uses pool: forks; agent projects exclude those files. Registration repairs the host-broker prerequisite without weakening admission guards. Tests were inspected, not executed during this read-only review. (test/vitest/vitest.infra.config.ts:14, d5177be32cac)
  • Runtime selection preserves execution confinement: Canonical borrowing requires an explicit bootstrap workspace, configured roster, canonical workspace match, and no fallback. Binding preserves the requested execution workspace while adopting committed runtime configuration and agent directories. (src/agents/workspace-run.ts:141, d5177be32cac)
  • Compaction follows the same workspace split: Compaction acquires the runtime using the canonical bootstrap workspace but retains requestedWorkspaceDir for execution. The context builder now carries bootstrapWorkspaceDir, and existing sandbox preparation derives confinement from execution workspace and sessionRoot rather than runtime metadata. (src/agents/embedded-agent-runner/compact.ts:402, d5177be32cac)
  • After-fix production-boundary evidence: The captured PR body reports a paired run through runEmbeddedAgent with real bundled plugins and Gateway lifecycle active, stopping before inference: startup 2,405 ms to 28 ms, prepared-runtime 2,350 ms to 1 ms, and zero additional metadata builds or registry acquisitions after the fix. The inspected regression executes the real read tool inside the task root and rejects a canonical-workspace file. The body explicitly discloses that the separate production plugin-tools cold-load stage was not reproduced. (src/agents/embedded-agent-runner/run-orchestrator.rooted-proof.test.ts:107, d5177be32cac)
  • Still necessary on current main and latest release: Fetched main still resolves runtime preparation from params.workspaceDir and uses that execution workspace for metadata and prepared-runtime acquisition. The inspected v2026.9.8 binding also lacks preserveExecutionWorkspace. No merged fixing PR was established; this branch remains an implementation candidate. (src/agents/embedded-agent-runner/run-orchestrator.ts, de14009aa222)

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)

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 (1 earlier review cycle)
  • reviewed 2026-10-03T05:14:53.096Z sha d3573b7 :: needs changes before merge. :: [P2] Route the rooted regression through the host-process test lane

@clawsweeper clawsweeper Bot added 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. labels Oct 3, 2026
@steipete
steipete merged commit 0c96fd0 into main Oct 3, 2026
135 checks passed
@steipete
steipete deleted the fix/rooted-run-plugin-generation-reuse branch October 3, 2026 06:05
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Oct 3, 2026
…space (#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 #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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…s start (openclaw#164049)

* fix(agents): reuse the agent plugin generation for rooted background runs

Rooted runs (skill workshop reviews in auto mode, cron jobs with an
execution root) passed the execution root as workspaceDir, which also keyed
the prepared model runtime and plugin metadata. No configured generation
matched, so each run cold-built its own generation and cold-loaded tool
plugins synchronously on the Gateway main thread (observed: 99 s
prepared-runtime + 51 s plugin-tools, dropping websockets and a chat.send).

When bootstrapWorkspaceDir resolves to the agent's canonical workspace,
select the prepared runtime with that workspace and keep the run bound to
its execution root. Compaction follows the same selection. Non-canonical or
absent bootstrap workspaces keep their own generation.

* test(agents): run the rooted prepared-runtime regression in the database worker lane
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.
yozakura-ava pushed a commit to yozakura-ava/openclaw that referenced this pull request Oct 4, 2026
…s start (openclaw#164049)

* fix(agents): reuse the agent plugin generation for rooted background runs

Rooted runs (skill workshop reviews in auto mode, cron jobs with an
execution root) passed the execution root as workspaceDir, which also keyed
the prepared model runtime and plugin metadata. No configured generation
matched, so each run cold-built its own generation and cold-loaded tool
plugins synchronously on the Gateway main thread (observed: 99 s
prepared-runtime + 51 s plugin-tools, dropping websockets and a chat.send).

When bootstrapWorkspaceDir resolves to the agent's canonical workspace,
select the prepared runtime with that workspace and keep the run bound to
its execution root. Compaction follows the same selection. Non-canonical or
absent bootstrap workspaces keep their own generation.

* test(agents): run the rooted prepared-runtime regression in the database worker lane

(cherry picked from commit 0c96fd0)
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 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