Repository navigation
fix(plugins): treat per-registry lifecycle, not global "active" pointer identity, as scheduling liveness - #159
Conversation
…er identity, as scheduling liveness isLoadedRecordInActiveRegistry() (gating scheduleSessionTurn, unscheduleSessionTurnsByTag, and sendSessionAttachment) required getActivePluginRegistry() === <the plugin's own captured registry> -- exact object identity against a single, global, process-wide "active registry" pointer. Root-caused via live log evidence from PR #156's new diagnostics ("plugin record is not loaded in the active registry"): a cron-triggered or non-default-agent agent turn can legitimately install its OWN plugin registry as the global "active" pointer on a cache miss in ensureStandaloneRuntimePluginRegistryLoaded (e.g. after config drift, or scoping to a different agentId's workspace). That does NOT mean an already-loaded bundled plugin's own registry was torn down -- it's still referenced by other tracked surfaces (the real channel/http-route pins), so setActivePluginRegistry's own retirement logic (retirePluginRegistryIfUnused) correctly leaves it live. But the identity check above treated "not currently the global active pointer" as equivalent to "retired", so browser-handoff's scheduleSessionTurn-based durable resume (built to fix "agent forgets everything") silently no-op'd on every single call from a cron-triggered turn -- which is exactly how it always runs. Fixes it by aligning with the sibling check shouldCommitWorkflowSideEffect in the same closure, which already correctly uses per-registry lifecycle flags (isPluginRegistryActivated / isPluginRegistryRetired) instead of global pointer identity, and is unaffected by this exact class of bug. Verified safe against the existing "stale-registry protection" test: a genuinely retired registry (no longer referenced by any tracked surface) is still correctly rejected, since retirement tracks actual usage via isRegistryLive, not the active pointer.
|
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 2 files
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
…egression test so the registry doesn't stay artificially live for later tests
There was a problem hiding this comment.
Approving. Correct fix, matches the sibling shouldCommitWorkflowSideEffect in the same closure — the identity check on the global active-pointer was strictly stronger than the semantic liveness signal for no defensible reason, and cron-triggered turns installing their own registry as the global active pointer via ensureStandaloneRuntimePluginRegistryLoaded was exactly the case that made browser-handoff's durable resume silently no-op.
Verified against the PR HEAD (4193bbcf):
- The three call sites —
sendSessionAttachment,scheduleSessionTurn,unscheduleSessionTurnsByTag— all still gate onisLoadedRecordInActiveRegistry; only the definition changed, so behavior for a genuinely retired registry is unchanged (isPluginRegistryRetiredstill short-circuits). retirePluginRegistryIfUnused->isRegistryLiveinruntime.tstracks active-pointer OR http/channel/sessionExtension pins, so a real teardown (all surfaces released) still flipsisPluginRegistryRetired(registry)to true and the guard rejects — the "stale-registry protection" contract holds.- Regression test reproduces the exact production case: pin registry-A as channel -> install empty registry-B as global active -> A stays live via the channel pin, so
scheduleSessionTurnon A now commits. Thefinallyclause releasing the pin (cubic-review commit) is the right call — without it later tests in the same file would see A artificially live viaisRegistryLive. - CI:
check-test-types,checks-fast-contracts-plugins-a/b, and everySecurity High (plugin-trust-boundary)shard green. Only outstanding job ischecks-node-core-tooling, unrelated to this diff. - Cubic marked its issues addressed; no other review threads open.
One nit, non-blocking: the new isLoadedRecordInActiveRegistry and shouldCommitWorkflowSideEffect now share the tail !isPluginRegistryRetired(registry) && isPluginRegistryActivated(registry) && isLoadedRecordInRegistry() — worth extracting to a named local (isPluginRegistryLiveForRecord?) so the next change doesn't drift the two apart again. Ship this as-is; leave that for a follow-up if you want it.
Ship it.
What Problem This Solves
This is the actual root cause behind tonight's "browser_handoff's
scheduleSessionTurndurable resume silently fails on every call" bug -- confirmed via live log evidence from #156's new diagnostics, on the running canary host:isLoadedRecordInActiveRegistry()(src/plugins/registry.ts, gatingscheduleSessionTurn,unscheduleSessionTurnsByTag, andsendSessionAttachment) requiredgetActivePluginRegistry() === <the plugin's own captured registry>-- exact object identity against a single, global, process-wide "active registry" pointer.Why This Change Was Made
A cron-triggered or non-default-agent agent turn can legitimately install its OWN plugin registry as the global "active" pointer, via
ensureStandaloneRuntimePluginRegistryLoadedon a cache miss (config drift, or scoping to a different agentId's workspace) -- this is normal, expected behavior, not a torn-down plugin. But that does NOT mean an already-loaded bundled plugin's own registry stopped being live: it's still referenced by other tracked surfaces (the real channel/http-route pins from gateway startup), sosetActivePluginRegistry's own retirement logic (retirePluginRegistryIfUnused->isRegistryLive) correctly leaves it live.The identity check above conflated "not currently the global active pointer" with "retired". Since
browser_handoff's durable-resume recheck (scheduleSessionTurn) always runs from a cron-triggered turn by design, it silently no-op'd on every single call -- the exact feature built to fix "agent forgets everything" (ENG-17466) was itself broken from day one, just never caught because nothing logged the failure (#156 fixed that half, and its new logging is what caught this).The fix aligns
isLoadedRecordInActiveRegistrywith the sibling checkshouldCommitWorkflowSideEffectin the same closure (registry.ts~2759), which already correctly uses per-registry lifecycle flags (isPluginRegistryActivated/isPluginRegistryRetired) instead of global pointer identity, and was never affected by this bug class.User Impact
Any bundled plugin using
scheduleSessionTurn/unscheduleSessionTurnsByTag/sendSessionAttachmentfrom a cron-triggered or non-default-agent context will now correctly commit instead of silently no-op'ing. Currently the only such plugin is browser-handoff. No behavior change for the main-session, non-cron path (which rarely hit this particular cache-miss condition).Evidence
scheduled-turns.contract.test.ts): a genuinely retired registry (no longer referenced by any tracked surface, e.g. aftersetActivePluginRegistry(createEmptyPluginRegistry())with nothing else pinning the old one) is still correctly rejected -- confirmed the full existing test suite passes unchanged, since retirement tracks actual cross-surface usage viaisRegistryLive, not the active pointer.node scripts/run-vitest.mjs src/plugins/contracts/scheduled-turns.contract.test.ts-- 26/26 passed (25 existing + 1 new)node scripts/run-vitest.mjs src/plugins/runtime.test.ts src/plugins/runtime.channel-pin.test.ts src/plugins/runtime-live-state-guardrails.test.ts src/plugins/registry.control-ui.test.ts src/plugins/registry.runtime-config.test.ts src/plugins/registry.channel-guard.test.ts-- 42/42 passed, no regressionstsgocore-test type-check was still running after several minutes with no result; not blocking on it -- CI's owncheck-test-typeswill independently verify types, matching how fix(plugins): log why a durable session-turn schedule/unschedule silently no-ops #156's real type error was caught and fixed via that same CI gate.This is a core plugin-registry liveness change (owner-boundary/architecture-sensitive per repo conventions) -- not merging without a real review/approval.
Summary by cubic
Fixes
isLoadedRecordInActiveRegistryto use per-registry lifecycle flags instead of comparing against the global active registry pointer, soscheduleSessionTurn,unscheduleSessionTurnsByTag, andsendSessionAttachmentno longer silently fail for cron-triggered or non-default-agent turns.browser-handoff's durable resume.Written for commit 4193bbc. Summary will update on new commits.