Repository navigation
fix(plugins): fix scheduleSessionTurn for tool-execution registries - #239
Conversation
…oolDiscovery, not a narrow marker PR #236 shipped a scheduleSessionTurn fix gated on a new toolExecutionSnapshot marker set only in createCachedDescriptorPluginTool's own per-invocation load options. Live-verified on arief-openclaw-test: browser-handoff's automatic recheck still failed after that fix deployed. A hot-patched diagnostic proved the actual registry backing the call is built by resolvePluginTools' own multi-plugin discovery-scan fallback (12 plugins, toolDiscovery:true, onlyPluginIds scoped to the plugins NOT covered by cached descriptors) -- a completely different call path than createCachedDescriptorPluginTool's, so the narrow marker was never set on it (toolExecutionSnapshot=false), and the early activateGlobalSideEffects gate rejected it outright before shouldCommit was ever consulted. toolDiscovery is an existing PluginLoadOptions field, already unconditionally set true on every registry built to resolve or execute plugin tools -- single- plugin snapshots AND multi-plugin discovery scans alike -- and already part of the loader's cache key (discoveryMode). It is architecturally guaranteed never true for the migration-provider registry (its own test requires the opposite: "must still become the active registry... since it doesn't set toolDiscovery"). Threading it into PluginRegistryParams and using it as the discriminator instead of a narrow, easy-to-miss marker fixes the live bug and removes the now-redundant toolExecutionScoped cache-key work from #236 (toolDiscovery was already baked into the cache key beforehand), netting negative non-test LOC. Renamed the affected tests/helpers from toolExecutionSnapshot to toolDiscovery and added a new regression test scoped to MULTIPLE plugins (mirroring the live-observed discovery-scan registry, not just a single-plugin snapshot). Confirmed via deliberate revert to the exact deployed-and-failing condition (checking a toolExecutionSnapshot field that no longer exists) that 3 tests fail without this fix, then restored. Live-verification plan: redeploy to arief-openclaw-test (replacing the temporary diagnostic hot-patches), then retest the browser-handoff sign-in flow. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
1 issue found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/plugins/registry-types.ts">
<violation number="1" location="src/plugins/registry-types.ts:502">
P2: `toolDiscovery` now conflates the discovery snapshot with the tool's per-invocation execution snapshot, so a cached discovery registry can be reused for execution when their plugin scope matches. Preserve a separate execution-scoped discriminator through `PluginRegistryParams` and the loader cache key.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
| * registry (see ensureStandaloneRuntimePluginRegistryLoaded), regardless of how | ||
| * many plugins it scopes to. Never true for the migration-provider registry. | ||
| */ | ||
| toolDiscovery?: boolean; |
There was a problem hiding this comment.
P2: toolDiscovery now conflates the discovery snapshot with the tool's per-invocation execution snapshot, so a cached discovery registry can be reused for execution when their plugin scope matches. Preserve a separate execution-scoped discriminator through PluginRegistryParams and the loader cache key.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/plugins/registry-types.ts, line 502:
<comment>`toolDiscovery` now conflates the discovery snapshot with the tool's per-invocation execution snapshot, so a cached discovery registry can be reused for execution when their plugin scope matches. Preserve a separate execution-scoped discriminator through `PluginRegistryParams` and the loader cache key.</comment>
<file context>
@@ -493,8 +493,13 @@ export type PluginRegistryParams = {
+ * registry (see ensureStandaloneRuntimePluginRegistryLoaded), regardless of how
+ * many plugins it scopes to. Never true for the migration-provider registry.
+ */
+ toolDiscovery?: boolean;
};
</file context>
There was a problem hiding this comment.
Traced this carefully before replying, since a similar-sounding 'this is too broad' concern on #236 turned out to hide a real bug. Concluded this specific conflation isn't reachable, for three independent reasons:
- Cache-key scoping already isolates them in practice.
onlyPluginIdsis part ofbuildCacheKey'sscopeKey. A single-plugin execute() snapshot and a multi-plugin discovery scan almost always have differentonlyPluginIds, so they land on different cache keys and never share a cached object. (They can coincide when a discovery scan's "plugins not covered by cached descriptors" happens to be exactly one plugin — but see point 3.) toolDiscovery:trueregistries are never installed as the pinned active/channel/http-route registry, by construction (ensureStandaloneRuntimePluginRegistryLoaded:if (loadOptions.toolDiscovery === true) return registry;before the install call). So there's no path where a discovery-scan registry gets reused via pinned-registry matching for an execution call either — that matching (getCompatibleActivePluginRegistry) only ever matches the real, genuinely-installed active/channel registry.- Even in the coincidental-scope-match cache-hit case, the actual authorization is unaffected.
isLoadedRecordInActiveRegistry's fallback (isPluginLoadedInActiveRegistry(record.id)) always re-checks the CURRENT real active registry by plugin id — it never trusts anything about the snapshot object itself. So which specific toolDiscovery snapshot'sapihappened to be used to make the call doesn't change the answer; sharing the cached object there is a cache-efficiency detail, not a correctness gap.
Happy to add a regression test for the coincidental single-plugin-scope cache-hit case if you see a concrete way it diverges from this — leaving this thread open rather than resolving it myself, since it's a disagreement rather than a fix.
…ify a test title cubic-dev-ai flagged (PR #239) two test-only nitpicks: - Two mock cron job IDs still said "job-from-tool-execution" after the toolExecutionSnapshot -> toolDiscovery rename; renamed to job-from-tool-discovery. - The loader cache-key separation test's title claimed to compare against "a normal runtime load", but both branches inherit activate:false, making the base case a non-discovery snapshot load, not a normal (activate!=false) one. Reworded per cubic's suggestion. Replied with reasoning (not resolving) on a third P2 finding questioning whether toolDiscovery conflates discovery scans with execution snapshots -- traced the cache-key scoping, the never-installed-active invariant, and the real-active- registry-based authorization check, and don't believe it's reachable, but left the thread open for further input rather than resolving my own disagreement. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…scovery snapshots Live-verified the toolDiscovery fix (previous commit) on arief-openclaw-test: browser-handoff's automatic recheck got past the original "scheduleSessionTurn returned no job" rejection, but hit a new failure: "recheck not scheduled: could not confirm prior schedule cleared after 3 attempts", caused by "plugin session turn untag-list failed: cron service unavailable". Root cause: getHostCronService() reads registryParams.hostServices?.cron, but the ephemeral tool-resolution load path (buildPluginRuntimeLoadOptions -> resolvePluginRuntimeLoadContext, used by createCachedDescriptorPluginTool and resolvePluginTools) never threads hostServices through at all -- confirmed via source: zero references to hostServices in tools.ts or runtime/load-context.ts. Only the real gateway startup/reload paths (server.impl.ts and friends) ever pass it. So every toolDiscovery snapshot has registryParams.hostServices undefined, and scheduleSessionTurn/unscheduleSessionTurnsByTag fail even once correctly authorized. Added a shared, process-wide hostServices reference (RegistryState.hostServices in runtime-state.ts) set by setActivePluginRegistry only when a real activation explicitly provides hostServices (so a reload without them can't clobber an earlier one that had them), and threaded it through activatePluginRegistry's three call sites in loader.ts and installStandaloneRegistry's call in standalone-runtime-registry-loader.ts. getHostCronService now falls back to this shared reference -- cron is a genuine process-wide singleton, so this is always the correct instance regardless of which registry's api reached the call. Added a regression test proving a toolDiscovery snapshot with no hostServices of its own still gets cron.add called via the fallback; confirmed via deliberate revert that it fails without the fix (cron.add unreached). Live-verification plan: redeploy to arief-openclaw-test and retest the browser-handoff sign-in flow end-to-end. Co-Authored-By: Claude Sonnet 5 <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 6 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
…eset cubic-dev-ai flagged (PR #239): state.hostServices was only ever written when a caller explicitly provided it, and never cleared -- so after the first real gateway activation with hostServices, a later real activation that doesn't pass any (e.g. server-plugins.ts's/server-startup-plugins.ts's empty-registry paths) would keep inheriting the earlier one, and test teardown via createEmptyPluginRegistry() resets never cleared it either. Since getHostCronService() now falls back to this shared reference for toolDiscovery snapshots, a stale/mocked cron from an earlier activation or test could silently keep flowing into later scheduling calls. Added clearActivePluginHostServices() (runtime.ts) and wired it into clearActivatedPluginRuntimeState() (loader.ts) -- called at the start of every real reload, and already used by 15+ test files' teardown via clearPluginLoaderCache() / resetPluginRuntimeStateForTest(). This ties hostServices to each real activation's own lifecycle: a reload that doesn't provide hostServices this time genuinely loses the earlier reference instead of silently keeping it, and test teardown no longer leaks a mocked cron service across tests. Added two regression tests (runtime.test.ts): the sticky-across-a-later- activation-without-hostServices behavior stays correct, and clearActivatedPluginRuntimeState() actually clears it. Confirmed the latter fails without the fix. Simplified the scheduled-turns test file's afterEach to rely on this shared clearing instead of passing an explicit {} itself. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Live-verified the previous fix (clearActivePluginHostServices wired into clearActivatedPluginRuntimeState) on arief-openclaw-test with a hot-patched diagnostic: browser-handoff's recheck was STILL failing with "cron service unavailable" after redeploying. The diagnostic showed why -- roughly 12 seconds after a clean boot correctly set the shared hostServices reference (hostServices=true hadCron=true), a routine post-startup "agent runtime plugins pre-warm" step (ensureRuntimePluginsLoaded in src/agents/runtime-plugins.ts, via ensureStandaloneRuntimePluginRegistryLoaded) triggered a real activation with no hostServices of its own, and clearActivatedPluginRuntimeState (which that reload runs through, same as every other real reload) unconditionally wiped the reference right before setActivePluginRegistry's own "only update when explicitly given" guard had a chance to leave it alone. Nothing else ever restores it, so cron stayed unavailable for the rest of the process lifetime. clearActivatedPluginRuntimeState runs on EVERY real reload (see loadOpenClawPlugins), including callers with no reason to know about hostServices at all -- it was never a safe place for this. Removed the clearActivePluginHostServices() call from there; setActivePluginRegistry's existing sticky behavior already protects production correctly on its own. Test hygiene is instead handled by resetPluginRuntimeStateForTest (runtime.ts), which already clears state.hostServices directly and is exclusively test-only infrastructure (confirmed via source: zero non-test callers) -- exactly the surgical, test-only clearing point cubic's original finding asked for. Updated the regression test to assert clearActivatedPluginRuntimeState does NOT clear it (confirmed via deliberate reintroduction of the just-fixed bug that this exact test catches it) and added one asserting resetPluginRuntimeStateForTest does. Re-added an explicit clearActivePluginHostServices() call to the scheduled-turns test file's own afterEach, since it no longer gets that protection for free. Live-verification plan: redeploy to arief-openclaw-test and retest the browser-handoff sign-in flow end-to-end. Co-Authored-By: Claude Sonnet 5 <[email protected]>
augusteo
left a comment
There was a problem hiding this comment.
Reviewed the full diff against the PR description. All three fixes hang together and the reasoning checks out:
Bug 1 (gate widening to toolDiscovery) — sound. toolDiscovery is already set on every tool-resolution registry (single-plugin execute() snapshot AND multi-plugin discovery scan), the migration-provider registry never sets it, and the existing strict-reject tests for both the migration-provider pattern and the non-toolDiscovery never-activated case are kept and still pass. The isLoadedRecordInActiveRegistry fallback still validates the plugin by id against the real active registry, so this doesn't open durable side effects to arbitrary snapshots.
Bug 2 (shared hostServices fallback) — sound. getHostCronService falls back via ?? so a registry's own hostServices still wins when present, and cron being a process-wide singleton makes the shared reference correct by construction. setActivePluginRegistry only updates the reference when explicitly given, so a reload without hostServices can't clobber a valid one (tested).
Bug 3 (sticky reference) — the trickiest one and handled correctly. Clearing in clearActivatedPluginRuntimeState was never safe since it runs on every real reload including hostServices-unaware pre-warm; moving test-hygiene clearing to resetPluginRuntimeStateForTest (test-only) plus explicit clearActivePluginHostServices() in the contract test's afterEach is the right split. Good comment trail explaining why.
Also good: removing the now-redundant toolExecutionScoped cache-key threading nets negative non-test LOC, and toolDiscovery was already in the cache key so no cache-collision regression.
CI: all 29 check runs green (including CodeQL). Regression tests cover each bug, and the PR documents revert/reintroduce verification per fix. Live-tested end-to-end on arief-openclaw-test.
LGTM — approving.
…249) * chore(release): bump version 2026.6.11-boon.46 -> 2026.6.11-boon.47 Root version, 135 plugin manifests synced via scripts/sync-plugin-versions.ts, changed npm-shrinkwrap.json files regenerated, CHANGELOG section for boon.47. Shipping: #236/#239 (a plugin tool's own execute() handler can now reliably schedule/unschedule a cron-backed session turn, fixing the browser-handoff recheck across three sequential live-found bugs), #240 (recheck backoff cap tightened 5m -> 2m), #242 (recheck messages the customer before attaching the browser), #241 (delivery.mode: "none" cron jobs can deliver an explicit message-tool send), #243 (Chrome MCP stderr drained before connect, not after), #247 (distinct exec-trajectory label for boon-projects schedule append/list), ENG-20030 (shared turn-resume-instruction wording for boon-core/anychat-boon-web), #248 (Docker build no longer OOMs 8 GB CI runners). Base = 2026.6.11-boon.46. Gateway plus @openclaw/slack, @openclaw/msteams and @openclaw/diagnostics-prometheus bumped in lockstep; no separately published plugin source changed in this train, so a gateway roll delivers all of it. Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(release): regenerate stale extension npm-shrinkwrap.json versions for boon.47 pnpm plugins:sync bumps each plugin's package.json version but does not touch its checked-in npm-shrinkwrap.json, so 65 published extension shrinkwraps still embedded version 2026.6.11-boon.46 despite package.json already reading boon.47. Since npm-shrinkwrap.json ships inside the npm artifact, this would have published every affected plugin with a mismatched embedded version. Bumped the version field(s) in all 65 (plus the openclaw peerDependency range where present) to 2026.6.11-boon.47, matching the pattern boon.46's bump commit already applied to these same files. Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
What Problem This Solves
PR #236 fixed
scheduleSessionTurn/unscheduleSessionTurnsByTagfor calls made from inside a plugin tool's ownexecute()handler, but the fix was gated on a newtoolExecutionSnapshotmarker set only increateCachedDescriptorPluginTool's own per-invocation load options (tools.ts).Live-testing on
arief-openclaw-testsurfaced three separate bugs in that approach, fixed here in sequence, each found by deploying the previous fix and retesting the real browser-handoff sign-in flow end-to-end:Bug 1 — the authorization gate never applied to the actual registry. After deploying #236 and retesting browser-handoff, the exact same symptom recurred:
[browser-handoff] site=app.buildingconnected.com recheck not scheduled: scheduleSessionTurn returned no job. A hot-patched, reverted diagnostic (safe, temporary edits to the deployed build) traced the actual registry backing the failing call to a completely different code path:resolvePluginTools→resolvePluginToolRegistry→ensureStandaloneRuntimePluginRegistryLoaded(tools.ts), which builds a multi-plugin discovery-scan registry (12 plugins in the observed case) withtoolDiscovery: truebut notoolExecutionSnapshotmarker — that marker was only ever set atcreateCachedDescriptorPluginTool's own call site. The earlyactivateGlobalSideEffectsgate rejected this registry outright, beforeshouldCommitwas ever consulted.Bug 2 — once authorized, cron itself was unavailable. After fixing bug 1 and redeploying, the recheck got past the authorization gate but failed with
could not confirm prior schedule cleared after 3 attempts/cron service unavailable. Traced to:getHostCronService()readsregistryParams.hostServices?.cron, but the ephemeral tool-resolution load path (buildPluginRuntimeLoadOptions→resolvePluginRuntimeLoadContext) never threadshostServicesthrough at all — confirmed via source: zero references tohostServicesintools.tsorruntime/load-context.ts. Only the real gateway startup/reload paths (server.impl.tsand friends) ever pass it, so everytoolDiscoverysnapshot has no cron service of its own.Bug 3 — the bug-2 fix's own fallback got wiped ~12 seconds after every boot. After fixing bug 2 (a shared
hostServicesreference, cleared on every reload viaclearActivatedPluginRuntimeState) and redeploying, the recheck still failed with the samecron service unavailableerror. A second round of hot-patched diagnostics showed the shared reference was set correctly at boot (hostServices=true hadCron=true), then wiped ~12 seconds later by a routine post-startup "agent runtime plugins pre-warm" step (ensureRuntimePluginsLoadedinsrc/agents/runtime-plugins.ts) — a real activation with nohostServicesof its own, running through the sameclearActivatedPluginRuntimeStatethat unconditionally cleared the shared reference beforesetActivePluginRegistry's own "only update when explicitly given" guard had a chance to leave it alone. Nothing else ever restored it, so cron stayed unavailable for the rest of the process lifetime.Why This Change Was Made
Bug 1 fix: switched the discriminator from the narrow
toolExecutionSnapshotmarker totoolDiscovery— an existingPluginLoadOptionsfield already unconditionally settrueon every registry built to resolve or execute plugin tools, whether a single-plugin execute() snapshot or a multi-plugin discovery scan.ensureStandaloneRuntimePluginRegistryLoadedarchitecturally guarantees such a registry is never installed as active/channel/http-route, and the migration-provider registry (the one legitimate case that should still hard-reject) never setstoolDiscovery— its own existing test requires the opposite.toolDiscoverywas also already part of the loader's cache key before #236, making thetoolExecutionScopedcache-key threading #236 added redundant — removed here, netting negative non-test LOC.Bug 2 fix: added a shared, process-wide
hostServicesreference (RegistryState.hostServicesinruntime-state.ts), set bysetActivePluginRegistryonly when a real activation explicitly provideshostServices(so a reload without them can't clobber an earlier one that had them), threaded throughactivatePluginRegistry's call sites inloader.tsandinstallStandaloneRegistryinstandalone-runtime-registry-loader.ts.getHostCronServicenow falls back to this shared reference — cron is a genuine process-wide singleton, so this is always the correct instance regardless of which registry'sapireached the call.Bug 3 fix: removed the
clearActivePluginHostServices()call fromclearActivatedPluginRuntimeState— that function runs on every real reload (seeloadOpenClawPlugins), including callers with no reason to know abouthostServicesat all, so it was never a safe place to unconditionally clear it.setActivePluginRegistry's existing "only update when explicitly given" rule already protects production correctly on its own. Test hygiene (the reason bug 2's fix added clearing in the first place, per cubic's review feedback) is instead handled byresetPluginRuntimeStateForTest(runtime.ts), which already clearsstate.hostServicesdirectly and is confirmed exclusively test-only infrastructure (zero non-test callers in source).User Impact
Any bundled or third-party plugin tool can now reliably schedule (or unschedule) a durable, cron-backed future session turn from inside its own
execute()handler — the authorization check succeeds and the cron service resolves correctly and stays available for the life of the process, regardless of which internal registry-resolution path happens to back that specific call, and regardless of routine post-startup reloads. For browser-handoff: the automatic resume after a customer signs in should now actually fire, matching the original requirement from #229/#233/#236.Evidence
arief-openclaw-testfor bug 1: hot-patched, reverted diagnostics traced the exact failing registry's construction (stack trace + field dump), confirmingtoolExecutionSnapshot=false,activateGlobalSideEffects=false,isActivated=false, and — critically —shouldCommitwould have returnedtruehad it been reached.arief-openclaw-testfor bug 2 (after deploying the bug-1 fix): confirmed via gateway logs thatunschedulePluginSessionTurnsByTag'scron service unavailablewarning fired 3 times before browser-handoff gave up, and traced the missinghostServicesthreading via source inspection.arief-openclaw-testfor bug 3 (after deploying the bug-2 fix): the samecron service unavailableerror recurred; hot-patched diagnostics onsetActivePluginRegistry/clearActivePluginHostServices/getHostCronServiceshowed the shared reference set correctly at boot then wiped ~12s later byensureRuntimePluginsLoaded's pre-warm reload, with a full stack trace confirming the exact call path.toolDiscovery-scoped registry containing multiple plugins (not just the single-plugin snapshot case fix(plugins): let scheduleSessionTurn work from inside a plugin tool's own execution #236 tested) — mirrors the live-observed discovery-scan registry.toolDiscoverysnapshot with nohostServicesof its own still getscron.addcalled via the shared-reference fallback.clearActivatedPluginRuntimeStatedoes not clear the shared reference (confirmed via deliberate reintroduction of the just-fixed bug that this exact test catches it — it fails with the bug present), whileresetPluginRuntimeStateForTest(test-only) does.node scripts/run-vitest.mjs src/plugins/contracts/scheduled-turns.contract.test.ts— 40/40.node scripts/run-vitest.mjs src/plugins/runtime.test.ts— 22/22.node scripts/run-vitest.mjs src/plugins/loader.runtime-registry.test.ts— 28/28.activateGlobalSideEffects(commands.test.ts,registry.runtime-config.test.ts,registry.channel-guard.test.ts,session-actions.contract.test.ts,http-registry.test.ts,registry.provider-like.test.ts,host-hooks.contract.test.ts,runtime.channel-pin.test.ts,runtime-registry-boundary.test.ts,runtime-live-state-guardrails.test.ts) plus the fullsrc/agentssuite — 3477/3477 (one unrelated, pre-existing flaky worker crash insession-write-lock.test.tsconfirmed to pass 53/53 cleanly in isolation, unrelated to this change).pnpm tsgo:core— clean.pnpm check:import-cycles— 0 runtime value cycles.oxlint+oxfmt --checkon all changed files — clean.arief-openclaw-testin sequence (replacing the temporary diagnostic hot-patches each time, none remain); live retest of the browser-handoff sign-in flow in progress.🤖 Generated with Claude Code
Summary by cubic
Fixes
scheduleSessionTurn/unscheduleSessionTurnsByTagfailing from multi-plugin tool-discovery scan registries, so plugin tools can reliably schedule durable session turns from theirexecute()handler.The previous fix (#236) gated the fallback on a
toolExecutionSnapshotmarker set only increateCachedDescriptorPluginTool's single-plugin snapshot, but live testing traced the actual failing call toresolvePluginTools' multi-plugin discovery-scan registry, which never sets that marker. The fallback now keys ontoolDiscovery, the existingPluginLoadOptionsfield every tool-execution and discovery-scan registry already sets (and that's already in the loader cache key). The redundanttoolExecutionScopedcache-key threading is removed.Live testing also found the ephemeral tool-resolution load path never threads
hostServicesthrough, so everytoolDiscoverysnapshot had no cron service of its own.getHostCronServicenow falls back to a shared process-wide reference set bysetActivePluginRegistryon real activation. That reference is sticky:clearActivatedPluginRuntimeState(which runs on every real reload) deliberately does not clear it, since a reload withouthostServicesmust not wipe a valid one — test hygiene is handled byresetPluginRuntimeStateForTestand explicit clearing in the test teardown.Tests
toolDiscovery-scoped registry containing multiple plugins, for the no-hostServicescron fallback, and for the shared reference's sticky, non-cleared, and test-cleared behaviors.toolExecutionSnapshottest artifacts from the rename.Written for commit 04a5880. Summary will update on new commits.