Repository navigation
fix(core): subscribe before debouncing config plugin updates - #46874
Merged
Merged
Conversation
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.
Why
Stream.debounceforks its upstream pull onto a child fiber viatransformPull, so a pipeline that debounces a bus or PubSub stream opens the underlying subscription one fiber hop afterEffect.forkScoped({ startImmediately: true })returns. PubSub does not buffer for future subscribers, so anything published in that hop is dropped. #46843 fixed this ininstruction.ts,skill.ts, andtool/mcp.tsby subscribing eagerly and debouncing the already-open subscription;config/plugin/agent.tsandconfig/plugin/command.tsstill debounced a lazy subscription.Those two sites also had a second hop hiding underneath: they fan in
config.changes()andctx.event.subscribe()withStream.merge, andChannel.mergeforks each side with a scheduled (non-immediate)forkIn. Applying the reference pattern on top of the merged stream therefore still left both subscriptions one hop late (verified: the new test kept failing with that shape). The fix runs each source on its ownstartImmediatelyfiber instead of throughmerge.What Changes
packages/core/src/config/plugin/agent.ts: replaceStream.merge(...).pipe(Stream.debounce, runForEach(reload))with an eagerPubSub.sliding<void>(1)feed.config.changes()(filtered to agent sources) andctx.event.subscribe()(filtered toconfig.updated) each runStream.runForEach(notify)forked withstartImmediately: true, so both subscriptions open synchronously. The sliding subscription is thenStream.fromSubscription(...).pipe(Stream.debounce("100 millis"), Stream.runForEach(() => reload)). Same 100 ms window, same single serialized reload feed.packages/core/src/config/plugin/command.ts: identical restructuring for command sources.packages/core/test/config/agent.test.ts,packages/core/test/config/command.test.ts: new caserebuilds on a config update published immediately after startup. It starts the plugin with no directory entries (so startup has no filesystem hop that could mask a late subscription), publishesconfig.updatedthrough the realBusin the same fiber step, and requires one reload.Verification
From
packages/core:bun typecheck: clean.condition never became true after 100 advancesinadvance), both for the originalmerge+debounceshape and for the intermediate "eagerrunForEachon the merged stream" shape.bun run test test/config/agent.test.ts test/config/command.test.ts --rerun-each 10: 260 pass, 0 fail.bun run test(full core suite): 3996 pass, 39 skip, 0 fail.