Repository navigation
feat(plugin-gateway): add RegisterAsDispatchListener - #245
Merged
Merged
Conversation
…dispatch listeners Add a decorator that runs a dispatch listener on the workers while the gateway client forwards its dispatches, and on the gateway client otherwise. forwardGatewayDispatches marks the client through the new optional GatewayDispatchEmitterLike#markDispatchesForwarded (ref-counted, undone by the stop function). The decorator checks the flag on every emit, so the order forwarding and the pieces load in does not matter. Gateway-only events are rejected by the types and throw at decoration time. Refs #244
|
Architecture Data flow ReviewNothing flagged · reviewed Tip Set 🪧 More tips
Thanks for using PR Lens! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the full diff of the single commit, plus the surrounding RegisterAsGatewayListener, EventGatewayListener (once wrapper) and the GatewayClient emit sites.
RegisterAsDispatchListener— wraps_listeneroutside theoncewrapper and readsemitter.forwardsDispatcheson every emit, so load order doesn't matter and an idleoncelistener isn't spent.GatewayClient#forwardsDispatches/markDispatchesForwarded()— ref-counted flag with an idempotent undo function.forwardGatewayDispatches— marks the emitter through the optionalmarkDispatchesForwardedand unmarks in the stop function; emitters without it behave as before.GatewayOnlyEventName/DispatchEventName/gatewayOnlyEvents— the gateway-only set matches the non-dispatch emit sites inGatewayClient(shardResume,shardClose,shardError,cacheError,clientReady,dispatch, plusshardReady/cacheSweep), andrawis correctly left out sincereplayDispatchemits it.- Tests, READMEs, changesets — decorator behaviour, broker marking, and an end-to-end gateway/worker test; limits (#243,
eventsfiltering, at-least-once) are documented.
claude-sonnet-5-5 | 𝕏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

🔗 Linked issue
Resolves #244
🧭 Context
With
@wolfstar/plugin-broker, the gateway process forwards every dispatch and still emits it to its own listeners, while workers replay the same dispatch on theirs. A bot that loads the same pieces in both processes handles each dispatch twice, and every bot has to work out by itself, usually from environment variables, which listeners to switch off.📚 Description
Adds
RegisterAsDispatchListenerto@wolfstar/plugin-gateway. It takes the same arguments asRegisterAsGatewayListenerand runs the listener on one process only: the workers while the gateway client forwards its dispatches, the gateway client itself otherwise (so it is harmless on a bot without a broker).forwardGatewayDispatchesmarks the client as forwarding through a new optionalGatewayDispatchEmitterLike#markDispatchesForwarded, whichGatewayClientimplements as a ref-countedforwardsDispatchesflag undone by the stop function. The decorator reads the flag on every emit rather than at load time: forwarding usually starts afterclient.load(), and checking per emit also copes withstop(). Its wrapper sits outside theoncewrapper, so an idleoncelistener is not spent.Departures from the Pullfrog plan:
Listenerbinds_listenerwhen the piece loads and nothing else gates it, so wrapping_listeneris the mechanism (asoncealready does), not togglingenabled.GatewayOnlyEventNameunion with a matching runtime set, instead of a test that derives the set fromGatewayEventMap. A test checks that the set only holds real events and excludesraw. Whether every other event is reachable from a handler can't be checked mechanically, so that part is left out.EventGatewayListeneris not changed to default to this, as the plan recommended; that stays a separate issue.Known limits, documented in both READMEs: the
guildDeleteemitted byREADYreconciliation is not forwarded (#243), and witheventsset onforwardGatewayDispatches, a listener of an event built from a dispatch left out runs nowhere. Delivery is at-least-once, so listeners should be idempotent.Key changes
plugin-gateway:RegisterAsDispatchListener,GatewayClient#forwardsDispatchesandmarkDispatchesForwarded(), and theDispatchEventName,GatewayOnlyEventNameandgatewayOnlyEventsexports. Gateway-only events (clientReady,shardReady,shardResume,shardClose,shardError,dispatch,cacheError,cacheSweep) are rejected by the types and throw at decoration time.plugin-broker:forwardGatewayDispatchesmarks the emitter while it forwards and unmarks on stop. Emitters without the method behave as before.once, gateway-only events), the broker marking, and an end-to-end gateway/worker test where only the worker's listener runs and the gateway's returns once forwarding stops.Type of Change
Pre-flight Checklist
pnpm changeset(orpnpm changeset add --emptyif no release is needed). See .changeset/README.md.Verification:
pnpm lint,pnpm build,pnpm typecheckandpnpm test(121 files, 1708 tests) pass locally.