Skip to content

fix(sandbox): retire plugin backends with registry lifecycle - #130662

Merged
steipete merged 2 commits into
mainfrom
codex/fix-openshell-backend-lifecycle
Aug 27, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/fix-openshell-backend-lifecycle

Conversation

@steipete

@steipete steipete commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #130518, which separated built-in sandbox defaults from explicit backend registrations.

What Problem This Solves

Fixes stale OpenShell and MXC sandbox backend registrations after their owning plugin registry retires. Gateway startup can be cancelled after eager plugin registration but before plugin services start; a service-only cleanup hook never runs in that case. The initial draft fixed normal OpenShell hot reload but missed this cancellation boundary.

Why This Change Was Made

Both plugins now retain the existing backend disposer in the existing plugin-runtime lifecycle. Registry replacement and shutdown own cleanup independently of whether services ever started. The no-op cleanup services are removed, leaving one cleanup owner.

Registration stays eager because sandbox CLI commands load full plugins without starting Gateway services. Only unscoped plugin disable/restart retires the global backend; session/run cleanup and reset/delete leave it available. The core registry's generation-aware, idempotent disposer remains unchanged, so a late old cleanup cannot erase a newer backend.

No core SDK/API, configuration, storage, backend default, platform readiness, or provider transport change is introduced. Production LOC is +24/-11 (net +13); the growth retains OpenShell's previously discarded disposer and expresses the necessary global-versus-scoped cleanup boundary in both plugins. Tests add a net 277 lines.

User Impact

OpenShell and MXC backend availability follows the active plugin generation, including interrupted startup. Retired registrations cannot remain available after disable or reappear when later generations retire. CLI backend discovery remains available before service startup.

Release-note intent: fix stale OpenShell/MXC sandbox backend availability after plugin disable, reload, or cancelled startup. This does not revoke already-created backend handles or change sandbox execution.

Evidence

Both new native public-SDK registry-retirement regressions failed before the runtime-owner correction and passed afterward. They register the real plugin API and retire the actual registry without ever starting services. OpenShell covers factory, manager, and workdir hooks; MXC covers factory/manager and its absent workdir hook. Entry tests also cover eager availability, global disable/restart, scoped cleanup for all four reasons including defined empty IDs, repeated disposal, both stale-generation orders, non-full modes, and MXC platform/binary-failure controls.

Final local tests pass: 110 OpenShell tests across seven files, 66 MXC tests across nine passing files, and 13 core sandbox-registry ownership tests. MXC's 56 Windows-only tests are skipped on this macOS host and are not counted as Windows proof. Tests use the repository wrapper, one worker, and this checkout's own frozen-lockfile dependencies. The full changed-file typecheck/lint/guard gate passes, including zero runtime import cycles. The fresh isolated Codex P0–P2 review reports no actionable findings.

The corrected candidate aa0f5049aebd7e718369235866098e0c3123e8f8 passes the canonical full build (8m23s), including all 63 external plugin local-dist builds and the existing UI performance budget. Actual compiled Gateway testing passes the complete same-boot enabled/disabled/re-enabled/workdir-change/disabled cycle. A fresh disabled Gateway exposes no hooks. Both owned processes exit normally and their ports close; all 11,784 compiled files and dependency identities remain unchanged. This run uses Node 24.20.0.

The separately reproduced cancellation gap also passes against this exact compiled candidate: the real loader eagerly registers all hooks, the real startup owner is cancelled before services start, and normal registry clear removes all hooks. Require-factory then reports not registered, and repeated clear remains safe. No provider command is invoked. The old failing pre-service cancellation receipt is preserved; a normal reload-only result is not substituted for this boundary.

Native Windows registration validation passes all 16 MXC entry tests on Node 24.20.0 / pnpm 11.22.0, from an exact-head fresh checkout and frozen lockfile on Azure Crabbox (run_819c6e85bd20). Readiness, binary resolution, and backend factories are declared test fixtures. The machine has no IsoEnvBroker service, so compiled MXC/container execution was not run. The run exited 0 and its lease was released. Earlier launcher failures occurred before product tests and are not counted as proof.

Exact-head hosted CI run 33105489824 is green, including openclaw/ci-gate: 33 successful jobs, 20 path-selected skips, no failures. The earlier automated cancellation finding is addressed by the runtime-owner correction and the actual compiled cancellation regression. No earlier draft-skipped CI is counted as validation.

Proof scope is plugin registration lifecycle, not authenticated OpenShell/MXC provider execution, Windows container execution, existing-handle revocation, or managed plugin installation. Both plugins remain external packages; compiled local proof must use the canonical external-plugin local-dist build output and its declared dependencies, not a copied source plugin.

Bind the explicit backend disposer to the plugin service lifetime so disabling or reloading OpenShell retires its factory, manager, and workdir hooks together. Preserve the core registry's stale and repeated disposer semantics.
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. 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 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 3:28 PM ET / 19:28 UTC.

ClawSweeper review

What this changes

Moves OpenShell and MXC sandbox-backend disposal from service lifetime to plugin-registry lifecycle cleanup, with regression coverage for registry retirement before services start.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer handling: current main still lacks registry-owned cleanup for these explicit sandbox registrations, while the proposed lifecycle callbacks match the registry’s cleanup ownership and generation semantics.

Priority: P2
Reviewed head: aa0f5049aebd7e718369235866098e0c3123e8f8
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with direct lifecycle coverage and no actionable source defect found.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable to the maintainer-authored PR proof gate; its body nevertheless describes compiled Gateway and registry-retirement validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable to the maintainer-authored PR proof gate; its body nevertheless describes compiled Gateway and registry-retirement validation.
Evidence reviewed 6 items Current-main gap: At fetched main, OpenShell eagerly registers a process-wide backend but does not retain its disposer in a registry lifecycle callback, so registry retirement has no plugin-owned backend cleanup.
Current-main service boundary: At fetched main, MXC cleanup is attached only to a plugin service stop, which does not cover a registry retired before services start.
Registry cleanup owner: Registry replacement invokes prior runtime lifecycle callbacks as restart or disable according to whether the plugin remains loaded; registry clear waits and runs the same cleanup path.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/openshell/index.test.ts extensions/mxc/test/plugin.test.ts

Result: PASS (completed)

[test] starting test/vitest/vitest.extension-misc.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130662-uwyIQm/target

 ✓  extension-misc  extensions/openshell/index.test.ts (14 tests) 86ms

 Test Files  1 passed (1)
      Tests  14 passed (14)
   Start at  19:29:38
   Duration  25.39s (transform 21.05s, setup 953ms, import 24.01s, tests 86ms, environment 0ms)

[test] starting test/vitest/vitest.extensions.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130662-uwyIQm/target

Assertions:

  • PASS expect_output: Test Files

How this fits together

Sandbox plugins register process-wide backend factories, managers, and workspace resolvers that the CLI and agent sandbox consume. Plugin-registry replacement or shutdown must retire those registrations without allowing an older generation to remove a newer one.

flowchart LR
  A[Plugin registration] --> B[Sandbox backend registry]
  B --> C[CLI and agent sandbox lookup]
  D[Registry replacement or shutdown] --> E[Plugin lifecycle cleanup]
  E --> F[Generation-aware disposer]
  F --> B
Loading

Decision needed

Question Recommendation
Should this maintainer-owned PR land after the current exact-head validation records confirm the registry-lifecycle behavior on its supported platforms? Approve the lifecycle ownership change: Confirm the exact-head validation records, then merge the focused owner-boundary repair.

Why: The patch changes process-wide backend availability and carries the protected maintainer label, so the final merge decision belongs to the responsible maintainer despite a clean source review.

Before merge

  • Resolve merge risk (P1) - This changes the lifetime of process-wide sandbox hooks; an integration regression could make a backend unavailable during a live generation, although the generation-aware disposer and focused lifecycle tests address that path.
  • Resolve merge risk (P1) - The supplied check rollup is truncated and the PR body describes hosted/Windows evidence as outstanding at the time it was written, so the final maintainer pass should inspect current exact-head gate results.
Agent review details

Security

None.

PR surface

Source +13, Tests +277. Total +290 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 24 11 +13
Tests 2 340 63 +277
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 364 74 +290

Review metrics

Metric Value Why it matters
Production versus test delta production +24/-11 (net +13); tests +340/-63 (net +277) The production growth is the two plugin-owned lifecycle closures; test growth covers retirement and generation ordering at the real registry boundary.

Merge-risk options

Maintainer options:

  1. Approve with exact-head validation (recommended)
    Accept the registry-lifecycle disposal path after confirming the current head’s cancellation and supported-platform validation records.
  2. Hold for platform evidence
    Pause merge until the current Windows and hosted validation state is unambiguous for this exact head.

Technical review

Best possible solution:

Keep explicit backend disposal in each owning plugin’s runtime lifecycle and land only after the maintainer confirms the exact-head lifecycle and platform validation records.

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

Yes, source-reproducible: current main registers the hooks eagerly while lacking registry-lifecycle disposal, and the introduced tests drive registry retirement before services start. This read-only review did not execute the regression locally.

Is this the best way to solve the issue?

Yes: the plugin registry already owns retirement and invokes runtime lifecycle cleanup, so retaining and disposing the registration callback there is narrower and more maintainable than service-only cleanup.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Not applicable to the maintainer-authored PR proof gate; its body nevertheless describes compiled Gateway and registry-retirement validation.
  • 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:

  • P2: This is a bounded sandbox-backend availability repair rather than an emergency runtime outage.
  • merge-risk: 🚨 availability: The PR changes when process-wide OpenShell and MXC backend hooks become unavailable during registry retirement.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Not applicable to the maintainer-authored PR proof gate; its body nevertheless describes compiled Gateway and registry-retirement validation.

Evidence

What I checked:

  • Current-main gap: At fetched main, OpenShell eagerly registers a process-wide backend but does not retain its disposer in a registry lifecycle callback, so registry retirement has no plugin-owned backend cleanup. (extensions/openshell/index.ts:20, b9d01e71270e)
  • Current-main service boundary: At fetched main, MXC cleanup is attached only to a plugin service stop, which does not cover a registry retired before services start. (extensions/mxc/src/plugin.ts:49, b9d01e71270e)
  • Registry cleanup owner: Registry replacement invokes prior runtime lifecycle callbacks as restart or disable according to whether the plugin remains loaded; registry clear waits and runs the same cleanup path. (src/plugins/host-hook-cleanup.ts:424, aa0f5049aebd)
  • Generation safety: The backend disposer is idempotent and skips retired predecessors, so cleanup from an older plugin registry cannot restore or erase a newer backend generation. (src/agents/sandbox/backend.ts:75, 4e92ea645a89)
  • Owner-boundary regression coverage: The introduced tests exercise real registry replacement without starting services, global versus scoped cleanup, repeated disposal, and both generation-retirement orders for OpenShell and MXC. (extensions/openshell/index.test.ts:156, aa0f5049aebd)
  • Related merged work: The earlier merged sandbox-registry change established generation-aware explicit registration disposal but explicitly left plugin registration cleanup to this follow-up. (src/agents/sandbox/backend.ts:75, 4e92ea645a89)

Likely related people:

  • steipete: Authored merged explicit sandbox-registration lifetime work and the current focused follow-up. (role: introduced adjacent registry-lifetime behavior and recent area contributor; confidence: high; commits: 4e92ea645a89, aa0f5049aebd; files: src/agents/sandbox/backend.ts, extensions/openshell/index.ts, extensions/mxc/src/plugin.ts)

Rank-up moves

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

  • Confirm the current exact-head hosted and Windows validation records before merge.

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 (3 earlier review cycles)
  • reviewed 2026-08-27T03:50:55.547Z sha 8d25efb :: found issues before merge. :: [P2] Move backend registration into the service start boundary
  • reviewed 2026-08-27T04:33:21.735Z sha 8d25efb :: found issues before merge. :: [P2] Register the backend from the service start boundary
  • reviewed 2026-08-27T18:45:05.108Z sha aa0f504 :: needs maintainer review before merge. :: none

@steipete steipete changed the title fix(openshell): retire sandbox backend with plugin services fix(sandbox): retire plugin backends with registry lifecycle Aug 27, 2026
@steipete
steipete marked this pull request as ready for review August 27, 2026 18:50
@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 Aug 27, 2026
@steipete
steipete merged commit 430d2ca into main Aug 27, 2026
178 of 181 checks passed
@steipete
steipete deleted the codex/fix-openshell-backend-lifecycle branch August 27, 2026 19:54
@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 28, 2026
…w#130662)

* fix(openshell): unregister sandbox backend on plugin stop

Bind the explicit backend disposer to the plugin service lifetime so disabling or reloading OpenShell retires its factory, manager, and workdir hooks together. Preserve the core registry's stale and repeated disposer semantics.

* fix(sandbox): retire plugin backends with registry lifecycle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: openshell maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. 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