Repository navigation
refactor: consolidate plugin runtime ownership and facades - #168006
Conversation
|
🦞👀 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. What this changesThis 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.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe 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
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -50, Other 0. Total -50 across 4 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
Reviewed October 9, 2026, 9:20 PM ET / October 10, 2026, 01:20 UTC (Revision 5). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…168006) * refactor: consolidate plugin runtime ownership and facades * refactor: type plugin runtime adapters without assertions * refactor: keep session updates at the runtime boundary
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
updateSessionStoreEntrySDK 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 currentupdateSessionEntryowner.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, atb2b07665c2be57c4be7bf861c1cf9aae9bfd5bce(mergeede44e51f0e8).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"]', andpnpm 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.git diff --check: passed.src/plugins/runtime/runtime-agent.test.ts: 25 files / 255 tests passed in 155.99 s, including preparation.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.tsEarlier full-tree and real Gateway evidence
On source
871de15b23c1d83e82fef342b6bfd9b63bb2cf13, fresh Blacksmith Testboxtbx_01m4ha9tgt1zpc2ah09x9ywyd8verified the complete candidate tree065b8f46bb5a0117f02a4b69db6d1bad8c9f56aband 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 unchangedagents.ts:2config-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 buildpassed 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 andrestartRequiredwas false.pnpm openclaw plugins disable registry-runtime-proofthen produced route 404 while/healthremained 200. All owned child processes were joined and the lease was stopped. No real model or channel messages were used.Exact current line accounting
src/plugins/registry-runtime.tssrc/plugins/registry-runtime-session-ownership.tssrc/plugins/registry-runtime-channel.tsThe 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.