Skip to content

refactor: consolidate plugin runtime ownership and facades - #168006

Merged
steipete merged 6 commits into
mainfrom
refactor/plugin-registry-runtime-deslop
Oct 10, 2026
Merged

steipete merged 6 commits into
mainfrom
refactor/plugin-registry-runtime-deslop

Conversation

@steipete

@steipete steipete commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Plugin runtime registration had grown past its 700-line lint limit, with repeated facade construction and session ownership policy spread across modules.

User Impact

No user-visible behavior change. Plugin SDK contracts, lazy loading, runtime identity, session ownership checks, and reload/disable behavior remain unchanged; no migration or configuration changes are required.

Why This Change Was Made

Session mutation policy lives with the lazily loaded session-ownership checks. The runtime resolver retains the single updateSessionStoreEntry SDK invocation; its owner prepares the guarded update callback, and the resolver forwards all options through the supplied runtime. This preserves method lookup before parameter spreading and avoids bypassing the host adapter, which already delegates persistence to the current updateSessionEntry owner.

A dedicated channel-runtime owner keeps registered channel caches and revocation together. Typed context-builder overloads preserve sync/async signatures without assertions, and ownership predicates use only the fields they inspect. Shared facade, descriptor, and post-await scope handling remove duplication while retaining receivers, cache identity, lease custody, and authority checks.

The resolver is 690 lint-counted lines. Production code decreases by 50 lines versus the merged main base. The assertion baseline was canonically shrunk from 5 to 1 for registry-runtime.ts; no destination allowance or SAFETY exemption was added. The session-accessor debt baseline is unchanged: exactly one legacy SDK write site remains in the original module, with zero in the ownership module.

Evidence

Current head: 01a09fd8b0c07893409c39acde8ceb191cfd3d19. Main was merged first, without rebasing, at b2b07665c2be57c4be7bf861c1cf9aae9bfd5bce (merge ede44e51f0e8).

  • ADDITIONAL_CHECK_GROUP=source-contracts bash scripts/ci-additional-checks.sh: passed all five scripts (export-name collisions, session-accessor boundary, SQLite transaction boundary, session-transcript reader boundary, SQLite session schema).
  • pnpm check:assertion-safety --base b2b07665c2be57c4be7bf861c1cf9aae9bfd5bce: passed, 2,858 files and 6,777 grandfathered assertions.
  • pnpm tsgo:core, pnpm tsgo:core:test --ci-graphs-json '["core-test-plugins-platform","core-test-agents-sessions","extensions-test"]', and pnpm tsgo:extensions: passed.
  • node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/plugins/registry-runtime.ts src/plugins/registry-runtime-channel.ts src/plugins/registry-runtime-session-ownership.ts: passed, including max-lines.
  • Oxfmt for the three runtime files and git diff --check: passed.
  • All 24 plugin registry/compat files plus src/plugins/runtime/runtime-agent.test.ts: 25 files / 255 tests passed in 155.99 s, including preparation.
  • Six session-accessor writer files on the exact commit: 6 files / 189 tests passed (see command below).
  • Fresh Codex branch autoreview against the merged base: scoped-clean through P2; no accepted/actionable findings. It confirmed preserved checks, option forwarding, method lookup order, and scope handling.

No test, assertion, or baseline was weakened. The three-site session write regression is removed by keeping the write at its existing runtime boundary, rather than expanding or relocating its allowance. The assertion baseline remains an exact shrink-only generated change.

Session-accessor writer proof command
pnpm test \
  src/config/sessions/session-accessor.conformance.test.ts \
  src/config/sessions/session-accessor.reply-init-concurrency.test.ts \
  src/config/sessions/session-accessor.sqlite-branches.test.ts \
  src/config/sessions/session-accessor.sqlite-message-cut.test.ts \
  src/config/sessions/session-accessor.test.ts \
  src/config/sessions/transcript.test.ts
Earlier full-tree and real Gateway evidence

On source 871de15b23c1d83e82fef342b6bfd9b63bb2cf13, fresh Blacksmith Testbox tbx_01m4ha9tgt1zpc2ah09x9ywyd8 verified the complete candidate tree 065b8f46bb5a0117f02a4b69db6d1bad8c9f56ab and changed-file hashes. Workflow. Crabbox's carrier commit differs from the original source SHA by design; the source tree and file hashes were checked.

The full plugin inventory was exercised, including separately routed contract, loader, and E2E projects: 594 files; 591 passed, 2 inherited failures, 1 skipped; 7,792 tests passed, 2 failed, 4 existing platform/runtime skips. The original failures were the missing workspace-guard compatibility test reference (fixed by main commit 8a8a3aad) and the unchanged agents.ts:2 config-boundary guard violation, both reproduced against the then-current main baseline. These are historical results at the named source revision, not a new full-suite run of this follow-up.

pnpm build passed in 227 s, required type graphs and lint/format checks passed, and the import-cycle check found zero runtime cycles. The original negative control was main's oxlint failure: 958 counted lines versus the 700 cap.

The real Gateway smoke passed in 14 s with isolated state/config, an ephemeral loopback port, and a synthetic external plugin. It exercised current config and cached image-generation/web-search facades, loaded v1, edited the fixture to v2, and ran pnpm openclaw plugins reload registry-runtime-proof --json. The Gateway PID stayed 28947 and restartRequired was false. pnpm openclaw plugins disable registry-runtime-proof then produced route 404 while /health remained 200. All owned child processes were joined and the lease was stopped. No real model or channel messages were used.

Exact current line accounting
File Physical lines before → after Added / deleted
src/plugins/registry-runtime.ts 997 → 711 +159 / −445
src/plugins/registry-runtime-session-ownership.ts 538 → 656 +124 / −6
src/plugins/registry-runtime-channel.ts 0 → 118 +118 / −0
Production total 1535 → 1485 +401 / −451 (net −50)

The resolver's lint-counted lines decrease from 970 to 690 on the merged base. Tests: +0/−0. Docs: +0/−0. Generated assertion baseline: +1/−1, allowance 5→1. Session-accessor debt baseline: unchanged. No changelog changes.

@clawsweeper

clawsweeper Bot commented Oct 9, 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.

@steipete
steipete marked this pull request as ready for review October 9, 2026 23:01
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR consolidates runtime facades and moves channel lifecycle and session mutation policy into focused internal owners.

Example: Reload registry-runtime-proof from v1 to v2, then disable it.

  • Before: The Gateway remains running during reload, and disabling the plugin removes its route.
  • After: The recorded Gateway run preserves that behavior: restartRequired is false, the disabled route returns 404, and health returns 200.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, net-negative refactor with preserved contracts and recorded Gateway proof; the real run retains its earlier revision identity, and current CI is still pending.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR records an isolated real Gateway exercising config, cached runtime facades, reload without restart, and disable with route removal on the earlier extraction; source comparison supports reuse for the behavior-preserving follow-ups, which also report focused current-head validation.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: No user-visible behavior change is intended; maintainers face repeated runtime wrappers and an oversized resolver.
Reason: The established area owner reduces production code and centralizes existing responsibilities without adding configuration, public API, or a competing persistence owner.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR provides a useful, smaller runtime implementation while preserving existing contracts; no actionable introduced defect was found.

Priority: P3
Reviewed head: 01a09fd8b0c07893409c39acde8ceb191cfd3d19

Before merge

None.

Findings

None.

Agent review details

How this fits together

The plugin registry supplies scoped runtime APIs to registered plugins, forwarding operations to host adapters while preserving plugin identity, lifecycle authority, and session ownership.

flowchart TD
  A[Registered plugin] --> B[Runtime resolver]
  B --> C[Cached runtime facades]
  B --> D[Channel lifecycle owner]
  B --> E[Lazy session ownership]
  C --> F[Host runtime adapters]
  D --> F
  E --> F
Loading

Technical review

Best possible solution:

Retain the focused internal owners and shared facades with the existing public runtime and persistence contracts intact.

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

This refactor reports no user-facing defect; source comparison confirms duplicated wrappers and dispersed policy in the original implementation.

Is this the best way to solve the issue?

The consolidation is proportionate: it removes duplicated construction, preserves receiver binding and lazy session loading, and retains the canonical session-write adapter.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Registry composition and channel owner keeps the original intent (fbade91: Split the large registry closure into focused modules with explicit shared state while preserving registration and runtime contracts.)
  • Channel admission and canonical Gateway binding keeps the original intent (97a53a9: Bind passive participant provenance to exact live records and finalized context facts; subsequent official-install repair preserves canonical Gateway ownership.)
  • Runtime lifetime and facade identity keeps the original intent (40d735e: Release retired registry graphs while preserving facade identity, adopted owners, and invocation-time registry selection.)
  • Session ownership policy keeps the original intent (35ebb96: Keep ownership checks lazily resolved at the plugin execution boundary without claiming a broader retirement contract.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduced change: The pinned introduction diff contains the channel extraction, session-policy relocation, shared facade construction, and assertion allowance shrink from 5 to 1; production changes total +401/-451 with no test changes. (src/plugins/registry-runtime.ts:43, 01a09fd8b0c0)
  • Session adapter preserved: The resolver retains the existing updateSessionStoreEntry invocation and forwards all options; the ownership module prepares its guarded callback, and the unchanged host adapter delegates persistence to updateSessionEntry. (src/plugins/registry-runtime.ts:586, 01a09fd8b0c0)
  • Lifecycle and ownership coverage: Existing session tests cover foreign locked-session owners and retirement during asynchronous reads; channel tests cover untrusted, replaced, retired, and rollback-owned records; facade coverage preserves interception across adoption and source replacement. (src/plugins/registry.runtime-session-ownership.test.ts:29, 01a09fd8b0c0)
  • Facade provenance: The merged predecessor perf(plugins): bound retained heap across runtime reloads #166751 established source-owned facade identity and invocation-time registry selection; the shared implementation preserves both. (src/plugins/registry-runtime.ts:483, 40d735e451b1)
  • Recorded real Gateway proof: The complete PR body records an isolated Gateway run on 871de15 exercising config, cached image-generation/web-search facades, reload without restart, and disable with route removal. Later source changes preserve the exercised path. The linked workflow is cancelled, and raw job-log retrieval was blocked at its Azure storage redirect; it is not credited as green CI. (871de15b23c1)
  • Current-head checks: REST inspection found one core test-type check still running and the aggregate CI gate pending, with no observed failing checks; GitHub reports the reviewed head mergeable. (01a09fd8b0c0)

PR surface

Source -50, Other 0. Total -50 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 401 451 -50
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 4 402 452 -50

Review metrics

Metric Value Why it matters
Production versus test LOC Production +401/-451; tests +0/-0 The refactor removes 50 production lines while reusing existing owner-boundary coverage.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is internal maintenance with preserved user-visible behavior and no demonstrated urgent regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • 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 (4 earlier review cycles)
  • reviewed 2026-10-09T23:07:04.219Z sha 871de15 :: needs changes before merge. :: [P2] Preserve assertion-ratchet compliance across the file extraction
  • reviewed 2026-10-09T23:14:37.444Z sha 871de15 :: needs changes before merge. :: [P2] Preserve assertion-ratchet compliance across the extraction
  • reviewed 2026-10-09T23:55:01.536Z sha 4060ba8 :: needs changes before merge. :: [P2] Preserve assertion-ratchet compliance across the extraction
  • reviewed 2026-10-10T00:29:38.211Z sha cf2b77e :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 9:20 PM ET / October 10, 2026, 01:20 UTC (Revision 5).

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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 10, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 7008414 into main Oct 10, 2026
135 checks passed
@steipete
steipete deleted the refactor/plugin-registry-runtime-deslop branch October 10, 2026 02:22
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…168006)

* refactor: consolidate plugin runtime ownership and facades

* refactor: type plugin runtime adapters without assertions

* refactor: keep session updates at the runtime boundary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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