Repository navigation
refactor: keep plugin work and cleanup owned during retirement - #144252
Conversation
35e43a7 to
383d65c
Compare
|
🦞👀 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. |
Dependency GuardThis PR changes dependency-related files. Maintainers should confirm these changes are intentional. Changed files:
Maintainer follow-up:
|
Dependency graph changes notedThis PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin, a member of
Security review is still recommended before merge when the dependency graph change is intentional. |
|
Codex review: blocked before merge. Reviewed September 11, 2026, 4:25 PM ET / 20:25 UTC (Revision 13). ClawSweeper reviewWhat this changesThe branch keeps plugin code, callbacks, active work, and cleanup attached to their owning instance during retirement, with corresponding SDK, consumer, and build changes. Merge readiness⛔ Blocked before merge - 3 items remain This remains a useful, maintainer-owned foundation that current main does not implement. All 566 introduced paths match the previous reviewed head byte-for-byte; the earlier donor-release repair remains present, and this review found no additional actionable defect. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw loads plugins into registries used by Gateway requests, agents, model helpers, and services. This change coordinates their execution and resource lifetimes so retiring a registry does not prematurely dispose dependencies still in use. flowchart TD
A[Plugin source and metadata] --> B[Managed plugin instance]
B --> C[Registry and SDK handles]
C --> D[Admit work against live owner]
D --> E[Requests, streams, and services]
C --> F[Registry retirement]
F --> D
E --> G[Drain and release resources]
F --> G
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one instance lifetime owner while preserving the documented SDK and startup contracts exercised by the recorded fresh-install and stable-upgrade proof. Do we have a high-confidence way to reproduce the issue? Yes for the targeted retirement scenarios: the source and existing two-Gateway and prepared-publication regressions define concrete paths. This read-only review did not execute a failing current-main reproduction. Is this the best way to solve the issue? Yes. Central instance ownership addresses the lifetime mismatch, preserves existing SDK result shapes, and has explicit startup and upgrade evidence; no competing implementation is needed. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a56463d58cbe. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (12 earlier review cycles; latest 8 shown)
|
…am end (#202368) Root cause: extensions/msteams/src/messenger.ts:120 renders reply text through `getMSTeamsRuntime().channel.text.chunkMarkdownTextWithMode`, but a late Teams stream settlement (`reply-dispatcher.ts:455`, run from `onSettled`) renders its fallback outside the plugin instance runtime slot added in #144252, so the lookup throws `MSTeams runtime not initialized` (src/plugin-sdk/runtime-store.ts:84) and the fallback reply is dropped without a log line. Related: #59731, #18636, #56040 (earlier lost Teams replies; none proves this exact regression) ## What Problem This Solves When Teams rejects the end of a streamed reply (for example a partial-mode answer with a Markdown table, where the rendered table no longer matches the already-streamed raw text), OpenClaw is meant to send the rest of the answer as a normal message. Since v2026.10.1 that recovery message is silently dropped, so the user only sees a cut-off, never-finalized stream. ## User Impact Teams users get the rest of the answer as a message when the stream cannot be completed, instead of a truncated reply with no error. ## Why This Change Was Made The Teams reply renderer now uses the pure SDK chunker (`openclaw/plugin-sdk/reply-chunking`), which is the same function the runtime chunker re-exports, so rendering no longer depends on the plugin runtime being reachable. Output is unchanged. The test file no longer installs a runtime stub, so the render tests prove rendering works without one; the unused runtime chunker stubs are removed. Other late msteams send paths checked: the dispatcher's failure system event uses the `core` captured at dispatcher creation, and `sendMSTeamsMessages` reads the runtime only through `user-agent.ts` (already caught). No other late path uses this lookup. ## Evidence Isolated `ocx src` Gateway with the real msteams plugin, a Teams connector fixture that enforces Microsoft's documented streaming rule (403 ContentStreamNotAllowed when streamed content changes), and a scripted model (two tool calls, then a table answer) in a 1:1 chat, partial streaming mode. - Before (main e728605): the stream shows "Tools found: | Tool | Scope | ... | whoami | Graph" and is never closed; no fallback message reaches the connector. A temporary log line in a scratch copy showed the fallback (the rest of the table, ending with the `list | MCP` row) was built and render threw `MSTeams runtime not initialized`. - After: the same run sends the remainder of the table once as a normal message (HTTP 201 from the connector). - Controls: a successful progress-mode stream sends no extra message; partial-mode plain text is identical before and after. - Unit: `messenger.test.ts` fails on main with `MSTeams runtime not initialized` and passes with the fix. Observed proof lines (connector request logs, base and candidate): #202368 (comment) Merge danger: two-way door, a revert fully undoes it; no state, config or contract change. Blast radius: Microsoft Teams reply rendering only. Co-authored-by: Ayaan Zaidi <[email protected]>
…am end (openclaw#202368) Root cause: extensions/msteams/src/messenger.ts:120 renders reply text through `getMSTeamsRuntime().channel.text.chunkMarkdownTextWithMode`, but a late Teams stream settlement (`reply-dispatcher.ts:455`, run from `onSettled`) renders its fallback outside the plugin instance runtime slot added in openclaw#144252, so the lookup throws `MSTeams runtime not initialized` (src/plugin-sdk/runtime-store.ts:84) and the fallback reply is dropped without a log line. Related: openclaw#59731, openclaw#18636, openclaw#56040 (earlier lost Teams replies; none proves this exact regression) ## What Problem This Solves When Teams rejects the end of a streamed reply (for example a partial-mode answer with a Markdown table, where the rendered table no longer matches the already-streamed raw text), OpenClaw is meant to send the rest of the answer as a normal message. Since v2026.10.1 that recovery message is silently dropped, so the user only sees a cut-off, never-finalized stream. ## User Impact Teams users get the rest of the answer as a message when the stream cannot be completed, instead of a truncated reply with no error. ## Why This Change Was Made The Teams reply renderer now uses the pure SDK chunker (`openclaw/plugin-sdk/reply-chunking`), which is the same function the runtime chunker re-exports, so rendering no longer depends on the plugin runtime being reachable. Output is unchanged. The test file no longer installs a runtime stub, so the render tests prove rendering works without one; the unused runtime chunker stubs are removed. Other late msteams send paths checked: the dispatcher's failure system event uses the `core` captured at dispatcher creation, and `sendMSTeamsMessages` reads the runtime only through `user-agent.ts` (already caught). No other late path uses this lookup. ## Evidence Isolated `ocx src` Gateway with the real msteams plugin, a Teams connector fixture that enforces Microsoft's documented streaming rule (403 ContentStreamNotAllowed when streamed content changes), and a scripted model (two tool calls, then a table answer) in a 1:1 chat, partial streaming mode. - Before (main 96278b8): the stream shows "Tools found: | Tool | Scope | ... | whoami | Graph" and is never closed; no fallback message reaches the connector. A temporary log line in a scratch copy showed the fallback (the rest of the table, ending with the `list | MCP` row) was built and render threw `MSTeams runtime not initialized`. - After: the same run sends the remainder of the table once as a normal message (HTTP 201 from the connector). - Controls: a successful progress-mode stream sends no extra message; partial-mode plain text is identical before and after. - Unit: `messenger.test.ts` fails on main with `MSTeams runtime not initialized` and passes with the fix. Observed proof lines (connector request logs, base and candidate): openclaw#202368 (comment) Merge danger: two-way door, a revert fully undoes it; no state, config or contract change. Blast radius: Microsoft Teams reply rendering only. Co-authored-by: Ayaan Zaidi <[email protected]>
…am end (#202368) Root cause: extensions/msteams/src/messenger.ts:120 renders reply text through `getMSTeamsRuntime().channel.text.chunkMarkdownTextWithMode`, but a late Teams stream settlement (`reply-dispatcher.ts:455`, run from `onSettled`) renders its fallback outside the plugin instance runtime slot added in #144252, so the lookup throws `MSTeams runtime not initialized` (src/plugin-sdk/runtime-store.ts:84) and the fallback reply is dropped without a log line. Related: #59731, #18636, #56040 (earlier lost Teams replies; none proves this exact regression) ## What Problem This Solves When Teams rejects the end of a streamed reply (for example a partial-mode answer with a Markdown table, where the rendered table no longer matches the already-streamed raw text), OpenClaw is meant to send the rest of the answer as a normal message. Since v2026.10.1 that recovery message is silently dropped, so the user only sees a cut-off, never-finalized stream. ## User Impact Teams users get the rest of the answer as a message when the stream cannot be completed, instead of a truncated reply with no error. ## Why This Change Was Made The Teams reply renderer now uses the pure SDK chunker (`openclaw/plugin-sdk/reply-chunking`), which is the same function the runtime chunker re-exports, so rendering no longer depends on the plugin runtime being reachable. Output is unchanged. The test file no longer installs a runtime stub, so the render tests prove rendering works without one; the unused runtime chunker stubs are removed. Other late msteams send paths checked: the dispatcher's failure system event uses the `core` captured at dispatcher creation, and `sendMSTeamsMessages` reads the runtime only through `user-agent.ts` (already caught). No other late path uses this lookup. ## Evidence Isolated `ocx src` Gateway with the real msteams plugin, a Teams connector fixture that enforces Microsoft's documented streaming rule (403 ContentStreamNotAllowed when streamed content changes), and a scripted model (two tool calls, then a table answer) in a 1:1 chat, partial streaming mode. - Before (main e728605): the stream shows "Tools found: | Tool | Scope | ... | whoami | Graph" and is never closed; no fallback message reaches the connector. A temporary log line in a scratch copy showed the fallback (the rest of the table, ending with the `list | MCP` row) was built and render threw `MSTeams runtime not initialized`. - After: the same run sends the remainder of the table once as a normal message (HTTP 201 from the connector). - Controls: a successful progress-mode stream sends no extra message; partial-mode plain text is identical before and after. - Unit: `messenger.test.ts` fails on main with `MSTeams runtime not initialized` and passes with the fix. Observed proof lines (connector request logs, base and candidate): #202368 (comment) Merge danger: two-way door, a revert fully undoes it; no state, config or contract change. Blast radius: Microsoft Teams reply rendering only. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit b24f06f) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit bb510f348153fcd9c8c8a788a4e5c985ea57174f)
…am end (openclaw#202368) Root cause: extensions/msteams/src/messenger.ts:120 renders reply text through `getMSTeamsRuntime().channel.text.chunkMarkdownTextWithMode`, but a late Teams stream settlement (`reply-dispatcher.ts:455`, run from `onSettled`) renders its fallback outside the plugin instance runtime slot added in openclaw#144252, so the lookup throws `MSTeams runtime not initialized` (src/plugin-sdk/runtime-store.ts:84) and the fallback reply is dropped without a log line. Related: openclaw#59731, openclaw#18636, openclaw#56040 (earlier lost Teams replies; none proves this exact regression) ## What Problem This Solves When Teams rejects the end of a streamed reply (for example a partial-mode answer with a Markdown table, where the rendered table no longer matches the already-streamed raw text), OpenClaw is meant to send the rest of the answer as a normal message. Since v2026.10.1 that recovery message is silently dropped, so the user only sees a cut-off, never-finalized stream. ## User Impact Teams users get the rest of the answer as a message when the stream cannot be completed, instead of a truncated reply with no error. ## Why This Change Was Made The Teams reply renderer now uses the pure SDK chunker (`openclaw/plugin-sdk/reply-chunking`), which is the same function the runtime chunker re-exports, so rendering no longer depends on the plugin runtime being reachable. Output is unchanged. The test file no longer installs a runtime stub, so the render tests prove rendering works without one; the unused runtime chunker stubs are removed. Other late msteams send paths checked: the dispatcher's failure system event uses the `core` captured at dispatcher creation, and `sendMSTeamsMessages` reads the runtime only through `user-agent.ts` (already caught). No other late path uses this lookup. ## Evidence Isolated `ocx src` Gateway with the real msteams plugin, a Teams connector fixture that enforces Microsoft's documented streaming rule (403 ContentStreamNotAllowed when streamed content changes), and a scripted model (two tool calls, then a table answer) in a 1:1 chat, partial streaming mode. - Before (main e728605): the stream shows "Tools found: | Tool | Scope | ... | whoami | Graph" and is never closed; no fallback message reaches the connector. A temporary log line in a scratch copy showed the fallback (the rest of the table, ending with the `list | MCP` row) was built and render threw `MSTeams runtime not initialized`. - After: the same run sends the remainder of the table once as a normal message (HTTP 201 from the connector). - Controls: a successful progress-mode stream sends no extra message; partial-mode plain text is identical before and after. - Unit: `messenger.test.ts` fails on main with `MSTeams runtime not initialized` and passes with the fix. Observed proof lines (connector request logs, base and candidate): openclaw#202368 (comment) Merge danger: two-way door, a revert fully undoes it; no state, config or contract change. Blast radius: Microsoft Teams reply rendering only. Co-authored-by: Ayaan Zaidi <[email protected]> Release adaptation: Use existing public SDK chunkMarkdownTextWithMode directly; remove fake runtime test dependency. No protocol or behavior redesign. (cherry picked from commit b24f06f) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 7320370485b22c18413601ea1d4c48afe4c054d6) (cherry picked from commit 1ac61645dc785776a4015ddbbc0e2e9ea0974189)
Related: #135599, #141280. The Control UI drain fix merged separately in #145118 (
b78d472e).What Problem This Solves
Plugin preparation and registry replacement could dispose dependencies still used by requests, model helpers, or another Gateway. This foundation lets accepted work keep its supplying plugin instance through completion and cleanup, providing the prerequisite for restart-free plugin management.
Why This Change Was Made
One managed instance owns its registered callbacks, runtime-store slots, captured source, and disposal. Registries and metadata caches retain their own dependencies; retirement stops new ordinary calls, while admitted consumers and surviving Gateways keep their exact owners. Idle cached publications release their holds when those owners retire. The separate CLI registry, setup-loader state, and runtime-boundary implementation are removed.
The design preserves synchronous registration and startup loading, including TypeScript/Jiti behavior and Bun's native loader semantics. It also carries the related CI repairs: runtime-dependent startup and package tests declare the canonical build prerequisite; SDK readiness covers the resolved relative imports used by compiled bundled plugins; and the now-merged Control UI prerequisite observes Gateway drain before sidecar teardown. The subsequent management cut supplies enable, disable, install, uninstall, and explicit reload orchestration. No operator option, SQLite schema/migration, or protocol-version change is introduced.
User Impact
Requests and setup flows keep their plugin dependencies until their work and cleanup finish. Plugin authors can use
api.lifecycle.onDisposeandapi.lifecycle.signal; the existing lifecycle contract remains supported. Cleanup is best effort, with visible failures and bounded disposer waits. Plugins remain responsible for unmanaged timers, listeners, sockets, watchers, and child processes; native objects and engine caches are not universally reclaimed. Fresh captured-source reload requires Node's synchronous module hooks, while Bun retains its native/Jiti startup behavior. See plugin lifecycle and cleanup.Evidence
Earlier Linux built-Gateway startup/RPC/shutdown proof passed on tree
005e642e, including a throwing cleanup callback and natural exit of both Gateways. Later source-bound regressions cover shared-Gateway retention, memory acquisition, captured-source loading and Bun startup. These historical results retain their original identities.All three final native compatibility flows passed on tree
840b890d: configured TypeScript upgrade from preserved official2026.9.2state, fresh TypeScript startup, and a JavaScript/CJS/asset plugin installed by the actual stable CLI. Each returned two ordered plugin RPCs and healthy status, started/stopped once, and exited naturally within the unchanged ten-second grace. Config, plugin bytes, managed install records and stable snapshots remained unchanged; all processes/groups ended and ports closed. Both drivers verified source and all 23,717 built artifacts before/after. Prior failures and the separate diagnostic replay remain preserved. This completes the fresh-start/stable-upgrade replay requested in ClawSweeper revision 8, reviewed onc63.The published
2026.9.3upgrade-survivor replay passed in 235 seconds on the actual failing CI mergee5024e2fplus the sealed SDK readiness fix, tree6b31ee12. Its candidate Gateway canary exited 0 in 12.817 seconds; the earlier run failed after 63.437 seconds with the Node ESM linking race. Migration, cron, agent, installed-plugin, repeat-update and doctor continuation checks passed. This is causal SDK proof on that source, not a run of the rebased PR head; all owned leases were closed.Focused corrections passed 602 package/planner tests and 51 SDK owner/sibling tests with the SDK changed-file gate. The Control UI fix passed 35 tests and real 80 MiB filesystem integration, including cancelled staging cleanup and a successful fresh generation. The exact eight-file correction on
840b890dcompleted a scoped-clean P2 review. Runtime JavaScript, SDK/plugin companions, UI and metadata rebuilt in 157.6 seconds using the existing skip-declarations profile; earlier declarations were preserved.The real rebase onto
7adce1e1replayed all seven commits. The four resolved files match the reviewed main/F combinations, including main's install authority checks, full media preflight table and per-handler prompt capability. All 17 checked SDK/UI/native-compatibility owner files remain byte-identical to the proven840b890dsource; dependency manifests are unchanged. On rebased parenteebf9fd3, 161 tests across nine installer/media/hook/memory files passed in 94.81 seconds. The selected changed-file gate passed, including core production/test types, all three dead-export scans, typed lint, formatting, and repository guards.CI on parent
eebf9fd3, testing mergec21a7698, finished with 125 successful jobs and 11 skipped. The upgrade Docker lane, Windows lanes and real-Gateway UI E2E passed. Two native PR-harness cases failed because main's new contributor-credit check requested an endpoint missing from the shared fake GitHub client. The six-line fixture-only correction derives authors from the synthetic Git repository and preserves credit verification. Both original cases reproduced red then passed on that exact CI source; all 16 selected tooling checks and independent P2 review passed. Production code is unchanged by this final correction.The latest rebase preserves main's asynchronous transcript snapshots and revision checks at the write boundary alongside per-entry plugin cleanup. Its single conflict was resolved without discarding either owner contract. On
518125d1, all 127 tests across six transcript files, production types, targeted typed lint, formatting and diff checks passed. All 17 previously checked loader/startup compatibility owners remain byte-identical to the live-tested source; dependency fields and lockfiles are unchanged.Full CI on
518125d1passed: 128 successful jobs, 11 skipped, and the required gate green. The final main refresh resolves only the independently updated native PR fixture; all 264 foundation production paths and the tested PR workflow/fixture are byte-identical to that green source. Current-head CI subsequently passed as recorded below.Downstream integration on combined tree
18b3d63calso passed fresh normal builds and the agent-management/TypeScript reload flow, embedded/native continuity, and install/update/uninstall flows. Those runs include the later management cuts; model responses were synthetic, while the Gateway, agents, tools, installer and pinned native Codex executable were real. All owned processes, ports and Testboxes closed.Current head:
ddfd8e413e177f1c8552de9c4e9a097ba1f760d6, treea7b3f8a92818530f550aad6ffffd45ae747a0551, base97e6e3cd4e400529ff729119f5aa030e33196037. Current-head CI passed with 128 successful jobs, 11 skipped, and the required gate green. The final conflict resolution preserves the tested production and fixture code; historical/isolated proof retains its original source identities.Against this main base, the foundation cut adds 5,106 production lines, 15,106 test/support lines, 432 tooling lines and 175 documentation lines; config/baselines decrease by 11 and the lockfile grows by three. Growth implements instance admission, captured-source ownership and retained cleanup. The later management cut is counted separately. No new operator configuration, schema, persisted format or protocol version is introduced.
Retained follow-ups: attribute the filtered lifecycle-test failure whose original-order file passed; document the internal
previousRegistryprecondition for explicit host overrides; clarify shipped CWD-relative CLIresolvePath; and remove the source-only channel helper's obsolete external-dist retry path.