Skip to content

fix(core): preserve location scope for plugin event subscriptions and catalog reloads - #57186

Draft
kitlangton wants to merge 4 commits into
devfrom
fix/plugin-host-location-scope
Draft

kitlangton wants to merge 4 commits into
devfrom
fix/plugin-host-location-scope

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Issue for this PR

N/A

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Preserves Location scoping for non-internal plugins (SdkPlugins, InstancePlugins, and package/local plugins) when they subscribe to events or trigger asynchronous catalog reloads:

  1. PluginHost.event.subscribe (packages/core/src/plugin/host.ts:258): Provides Stream.provideService(Location.Service, location) on bus.subscribe(), matching Rpc.client.events.subscribe (packages/core/src/rpc.ts:166). Because Plugin.load (packages/core/src/plugin.ts:68-73) strips Location.Service from the fiber context of non-internal plugins via Effect.updateContext, ctx.event.subscribe() previously saw Location.Service = Option.none() and leaked events from all booted Locations on the server.
  2. Catalog State.create notify hooks (packages/core/src/agent.ts, command.ts, integration.ts, reference.ts, skill.ts, websearch.ts): Captures Effect.serviceOption(Location.Service) at layer construction time and stamps { location } on bus.publish when present, matching Provider (packages/core/src/provider.ts:482) and Model (packages/core/src/model.ts:249). Previously, when a non-internal plugin called ctx.<domain>.reload() or ctx.integration.connection.status(...) asynchronously from a fiber where Location.Service had been stripped by Plugin.load, bus.publish emitted an unlocated (location: undefined) .updated event that clients dropped at packages/client/src/solid/data.ts:1256 (if (!event.location) return).

How did you verify your code works?

cd packages/core && bun test test/plugin/supervisor.test.ts

Added scopes external plugin event subscriptions and async catalog reloads to the plugin's location in packages/core/test/plugin/supervisor.test.ts.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant