refactor(core): use Latch for plugin supervisor ready gate - #43569
Open
kitlangton wants to merge 1 commit into
Open
refactor(core): use Latch for plugin supervisor ready gate#43569kitlangton wants to merge 1 commit into
kitlangton wants to merge 1 commit into
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.
What
The plugin supervisor's
flushreadiness signal is a hand-rolled reusable gate: aDeferred<void>in a mutableready.currentbox, recreated via anisDonecheck on every update and re-awaited throughEffect.suspend. Effect'sLatchis exactly this primitive — a valueless, never-failing gate that can close and reopen — so this replaces the machinery with oneLatch.How
packages/core/src/plugin/supervisor.ts:readyis nowyield* Latch.make()(starts closed, like the fresh deferred).ready.close(idempotent) instead ofisDone+ recreate; the mutable box disappears.ready.openinstead ofDeferred.succeed.flushisready.awaitdirectly — noEffect.suspendneeded since there is no longer a swapped reference to re-read.Behavior is unchanged: updates close the gate before the burst coalesces (same "make accepted work visible to flush" point in the stream), and only an activation that has caught up to the last observed generation opens it.
Found by a repo-wide audit of
Deferred<void>-as-gate patterns; sibling PRs convert the other pure-gate sites.Testing
packages/core:bun typecheck,bun test test/plugin.test.ts test/plugin-hooks.test.ts test/session-runner.test.ts(172 pass), and the fullbun run testsuite (1892 pass / 0 fail).