Skip to content

fix(plugins): treat per-registry lifecycle, not global "active" pointer identity, as scheduling liveness - #159

Merged
convyusboy merged 2 commits into
boonfrom
ridho/eng-plugin-registry-liveness-check
Aug 27, 2026
Merged

convyusboy merged 2 commits into
boonfrom
ridho/eng-plugin-registry-liveness-check

Conversation

@convyusboy

@convyusboy convyusboy commented Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

This is the actual root cause behind tonight's "browser_handoff's scheduleSessionTurn durable resume silently fails on every call" bug -- confirmed via live log evidence from #156's new diagnostics, on the running canary host:

plugin session turn scheduling failed (pluginId=browser-handoff sessionKey=agent:main:cron:<jobId>:run:<runId>): plugin record is not loaded in the active registry

isLoadedRecordInActiveRegistry() (src/plugins/registry.ts, 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.

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 ensureStandaloneRuntimePluginRegistryLoaded on 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), so setActivePluginRegistry'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 isLoadedRecordInActiveRegistry with the sibling check shouldCommitWorkflowSideEffect in 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/sendSessionAttachment from 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

  • Verified safe against the existing "stale-registry protection" test (scheduled-turns.contract.test.ts): a genuinely retired registry (no longer referenced by any tracked surface, e.g. after setActivePluginRegistry(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 via isRegistryLive, not the active pointer.
  • New regression test added: "still schedules a session turn when an unrelated registry becomes globally active but this plugin's own registry is still live" -- reproduces the exact production bug (channel-pinned registry stays live even after a different registry becomes globally active) and asserts scheduling now succeeds.
  • 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 regressions
  • Local tsgo core-test type-check was still running after several minutes with no result; not blocking on it -- CI's own check-test-types will 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 isLoadedRecordInActiveRegistry to use per-registry lifecycle flags instead of comparing against the global active registry pointer, so scheduleSessionTurn, unscheduleSessionTurnsByTag, and sendSessionAttachment no longer silently fail for cron-triggered or non-default-agent turns.

  • Previously, installing a new registry as the global active pointer (e.g., on a config-drift cache miss) made the old registry appear inactive even if still live, breaking browser-handoff's durable resume.
  • Adds a regression test that releases the pinned channel registry after running, and confirms the existing stale-registry protection still works.

Written for commit 4193bbc. Summary will update on new commits.

Review in cubic

…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

claude Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@gandalfboon gandalfboon Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 on isLoadedRecordInActiveRegistry; only the definition changed, so behavior for a genuinely retired registry is unchanged (isPluginRegistryRetired still short-circuits).
  • retirePluginRegistryIfUnused -> isRegistryLive in runtime.ts tracks active-pointer OR http/channel/sessionExtension pins, so a real teardown (all surfaces released) still flips isPluginRegistryRetired(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 scheduleSessionTurn on A now commits. The finally clause releasing the pin (cubic-review commit) is the right call — without it later tests in the same file would see A artificially live via isRegistryLive.
  • CI: check-test-types, checks-fast-contracts-plugins-a/b, and every Security High (plugin-trust-boundary) shard green. Only outstanding job is checks-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.

@convyusboy
convyusboy merged commit da5c4bc into boon Aug 27, 2026
147 of 148 checks passed
@convyusboy
convyusboy deleted the ridho/eng-plugin-registry-liveness-check branch August 27, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant