Repository navigation
fix(plugins): let scheduleSessionTurn work from inside a plugin tool's own execution - #236
Conversation
…s own execution Root cause of the browser-handoff automatic-recheck failure (previously mistaken for a plugin-registry retirement race, see #233): every plugin tool's execute() handler resolves a fresh, narrow registry scoped to just that one plugin, per invocation (createCachedDescriptorPluginTool in tools.ts, activate:false, never installed via setActivePluginRegistry). This is by design and works fine for normal tool calls, but scheduleSessionTurn's shouldCommit check (isLoadedRecordInActiveRegistry) required THIS specific registry to be activated -- which it never is, even though the same plugin is genuinely loaded gateway-wide. Confirmed live on arief-openclaw-test: a hand-patched diagnostic showed 'activateGlobalSideEffects is false on this registry' firing on every single attempt, and a stack-trace patch on setActivePluginRegistry showed this narrow registry was never installed as the active pointer at all -- it's simply never checked against the right thing. Fix: isLoadedRecordInActiveRegistry now falls back to checking the real, system-wide active registry by plugin id (new isPluginLoadedInActiveRegistry in runtime.ts) whenever the caller's own registry was never activated at all. Registries that WERE installed active with side effects deliberately off (e.g. the migration-provider registry from ensureStandaloneMigrationProviderRegistryLoaded) keep the original, stricter rejection -- only a never-activated snapshot gets the fallback. scheduleSessionTurn/unscheduleSessionTurnsByTag's own activateGlobalSideEffects gates were narrowed the same way. Tests: two new regression tests -- one proving scheduleSessionTurn now succeeds when called through a narrow, never-activated registry while the plugin is loaded in a separate real active one (confirmed it fails for the right reason with the fix reverted), and one proving a registry that WAS installed active with side effects off still correctly refuses (confirmed cron.add gets called when THAT gate is removed). 36/36 in scheduled-turns.contract.test.ts (2 new), 155 across every other test file that references activateGlobalSideEffects. tsgo:core, check:import-cycles, oxlint, oxfmt all clean. 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.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
… to tool-execution snapshots cubic-dev-ai flagged (PR #236) that the never-activated fallback in isLoadedRecordInActiveRegistry was keyed only on isPluginRegistryActivated(registry), so it applied to any side-effects-off registry that was never marked active -- not just a plugin tool's own per-invocation execute() snapshot. A tool-discovery descriptor scan or the CLI-only registry is also never-activated, and would have incorrectly bypassed the activateGlobalSideEffects hard-reject for scheduleSessionTurn/unscheduleSessionTurnsByTag whenever the same plugin id happened to be loaded in whatever registry is currently active. Added an explicit toolExecutionScoped/toolExecutionSnapshot marker, set only at createCachedDescriptorPluginTool's own load-options call site, and gated both the fallback and the early activateGlobalSideEffects reject on it, so the loosened by-id check only ever applies to the exact registry it was designed for. Also trimmed two verbose comments (runtime.ts, registry.ts) and two verbose test titles per cubic's style feedback, and added a regression test proving a never-activated, non-tool-execution registry still gets rejected -- confirmed it fails without the toolExecutionSnapshot marker (TypeError from cron.add being called with no cron service). 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).
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
…er cache key cubic-dev-ai's re-review of PR #236 flagged a P1: the toolExecutionScoped marker added in the previous commit is set on PluginLoadOptions but was never part of the loader's cache identity (buildCacheKey / resolvePluginLoadCacheContext). An ordinary tool-discovery load and a plugin tool's own execute() snapshot can otherwise compute the identical cache key (same onlyPluginIds/toolDiscovery/ activate), so whichever one runs first gets cached and reused for the other -- silently handing back a registry whose toolExecutionSnapshot doesn't match what the caller asked for, reintroducing the exact bug the marker exists to fix. Added toolExecutionScoped to buildCacheKey's params and folded it into the returned cache key string, and threaded options.toolExecutionScoped through resolvePluginLoadCacheContext's call to it. Added a regression test asserting the two cache keys differ for otherwise-identical options -- confirmed it fails without the threading (the two keys were identical). Also added the positive unscheduleSessionTurnsByTag test cubic asked for (P3): the existing toolExecutionSnapshot coverage only exercised scheduleSessionTurn, not the identical gate applied to unscheduleSessionTurnsByTag. Co-Authored-By: Claude Sonnet 5 <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
…ure helpers cubic-dev-ai flagged (PR #236) that the same ~30-line registry+record+api setup was duplicated across four tests in scheduled-turns.contract.test.ts (schedule, unschedule, migration-provider, and non-tool-execution-snapshot rejection). Extracted activateWorkflowPluginFixtureRegistry() (installs the real, activated registry with the plugin loaded gateway-wide) and createWorkflowPluginRegistryApi() (builds a separate, never-activated, side-effects-off registry + record + api, optionally marked toolExecutionSnapshot) and switched all four tests to use them. Net -53 LOC in the test file; behavior unchanged (all 38 tests still pass). Co-Authored-By: Claude Sonnet 5 <[email protected]>
augusteo
left a comment
There was a problem hiding this comment.
Review — approve
Verified against the actual head (f4a2cb0c), not just the PR description.
Root cause analysis checks out. Traced the full path: createCachedDescriptorPluginTool (tools.ts) builds a fresh per-invocation registry with activate: false and never installs it via setActivePluginRegistry, so the old liveness check (isPluginRegistryActivated(registry)) could never pass for any plugin tool calling scheduleSessionTurn from inside its own execute(). The 100%-reproducible browser-handoff symptom follows deterministically from that, independent of the #233 race.
What I verified:
- The fallback is correctly gated on
toolExecutionSnapshot, so genuinely-never-activated loads (tool-discovery scans, CLI-only registry) keep the strict rejection — confirmed by the new negative test. - The migration-provider pattern (installed active, side effects deliberately off) still rejects — covered by a dedicated test.
- The loader cache-key separation (
toolExecutionScopeMode) closes the real hole where a cached tool-discovery snapshot (no marker) could be reused for an execute() call, silently reintroducing the bug. Good catch, and it has a test. isPluginLoadedInActiveRegistrychecks the plugin id withstatus === "loaded"in the system-wide active registry — plugin code can't forge the marker since only the host setstoolExecutionScopedwhen building load options. No new privilege: a tool only gains scheduling ability for a plugin that is already loaded and executing.- No secrets, injection, or authz concerns in the diff.
Non-blocking observations:
registry.tsfall-through branch ofisLoadedRecordInActiveRegistrydropped theisPluginRegistryActivated(registry)term from the original check. Today this is unreachable as a behavior change (side-effects-off registries are rejected at the API gates before the liveness check; side-effects-on registries are always activated via the loader), but if a never-activated, side-effects-on registry ever appears, the check silently loosens. Worth a comment or restoring the term for defense in depth.- The fallback consults the global active-registry pointer — the very thing the comment above it (lines 2753–2758) warns can be hijacked by a cron-triggered standalone run installing its own narrow registry. In that window a plugin tool's schedule would fail (returning to the pre-PR symptom, not worse). Strictly better than status quo; just noting the residual edge.
- Inconsistency, out of scope:
sendSessionAttachmentstill hard-rejects all side-effects-off registries including tool snapshots, so plugin tools can schedule turns but still can't send attachments fromexecute(). Fine to leave for a follow-up.
CI is green across all checks on the head.
augusteo
left a comment
There was a problem hiding this comment.
Reviewed exact head f4a2cb0c517992f5ce12ebe23e515ecdf62c0f5e against base f0e3a1f02a3fbebc5798d7a4a1d979f0eccfc411. No findings. The tool-execution snapshot is narrowly scoped and separately keyed; other side-effects-off registries remain guarded. Focused local tests passed: scheduled-turn contract 38/38 and loader runtime-registry 28/28. Exact-head Actions and build-artifacts checks passed. The loader runtime-registry test is outside this PR hosted matrix, so I ran it locally.
…239) * fix(plugins): key scheduleSessionTurn's never-activated fallback on toolDiscovery, 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]> * test(plugins): rename leftover toolExecutionSnapshot job IDs and clarify 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]> * fix(plugins): fall back to the real gateway's cron service for toolDiscovery 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]> * fix(plugins): clear the shared hostServices reference on activation reset 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]> * fix(plugins): don't clear shared hostServices on every real reload 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]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
…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
The browser-handoff plugin's automatic recheck-scheduling (added in #229, and the subject of the whole plugin-registry-retirement-race investigation in #233) was still failing on every single live test after #233 shipped —
[browser-handoff] site=app.buildingconnected.com recheck not scheduled: scheduleSessionTurn returned no job, 100% reproducible, not intermittent.Root-caused live on
arief-openclaw-testwith a series of hand-patched diagnostics (safe, temporary edits to the deployed build, reverted before this PR):registry.ts'sscheduleSessionTurnwiring showed the actual rejection reason:activateGlobalSideEffects is false on this registry.setActivePluginRegistry(the only function that ever sets the global active registry pointer) proved this narrow, 12-plugin registry was never installed as the active registry at all, across two separate live gateway restarts.The actual mechanism: every plugin tool's
execute()handler resolves a fresh, narrow registry scoped to just that one plugin, on every single invocation (createCachedDescriptorPluginToolintools.ts,activate: false, never installed viasetActivePluginRegistry). This is intentional, working-as-designed behavior for ordinary tool calls — butscheduleSessionTurn's liveness check (isLoadedRecordInActiveRegistry) required this specific registry snapshot to be the system's activated one, which it structurally never is. Any plugin tool trying to schedule a future session turn from inside its own execution — not just browser-handoff — was broken by this, deterministically, regardless of concurrency or timing.This means the plugin-registry-retirement-race work in #233 was a real, worthwhile fix for a real (if different) race condition, but it was never going to fix this symptom, because the registry involved never even reaches the code paths #233 touched.
Why This Change Was Made
isLoadedRecordInActiveRegistrynow falls back to checking the real, system-wide active registry by plugin id (newisPluginLoadedInActiveRegistryinruntime.ts) whenever the caller's own registry was never activated at all — exactly the tool-execution-scoped case. Registries that genuinely were installed as the active registry with side effects deliberately off (e.g. the migration-provider registry fromensureStandaloneMigrationProviderRegistryLoaded) keep the original, stricter rejection unchanged — only a never-activated snapshot gets the fallback, so this doesn't loosen any existing intentional behavior.scheduleSessionTurn/unscheduleSessionTurnsByTag's own earlyactivateGlobalSideEffectsgates were narrowed the same precise way.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. For browser-handoff specifically: the automatic resume after a customer signs in should now actually fire on the first attempt, without a manual nudge — the original requirement from the start of this investigation.Evidence
arief-openclaw-test: three rounds of hand-patched, reverted diagnostic logging pinpointed the exact rejection reason and proved the registry was never installed as active, across a fresh gateway restart.scheduleSessionTurnsucceeds when called through a narrow, never-activated registry while the plugin is loaded in a separate, real active registry. Confirmed it fails for the right reason with the fix reverted.cron.addgets called (wrongly) when that specific gate is removed.node scripts/run-vitest.mjs src/plugins/contracts/scheduled-turns.contract.test.ts— 36/36 (2 new).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,commands-diagnostics.test.ts) — 155/155.pnpm tsgo:core— clean.pnpm check:import-cycles— 0 runtime value cycles.oxlint+oxfmt --checkon all changed files — clean.🤖 Generated with Claude Code
Summary by cubic
Fixes
scheduleSessionTurn(and unscheduling by tag) so plugin tools can schedule future session turns from inside their ownexecute()handler: the fresh, per-invocation registry those tools run in was never activated, so the old liveness check always rejected even when the plugin was loaded gateway-wide.toolExecutionScoped/toolExecutionSnapshotmarker set only at the tool-execution call site; other never-activated, side-effects-off registries (migration-provider, tool-discovery scans, CLI-only) keep the stricter rejection.Written for commit f4a2cb0. Summary will update on new commits.