Skip to content

refactor(core): use Latch for plugin supervisor ready gate - #43569

Merged
kitlangton merged 1 commit into
v2from
latch-supervisor
Aug 20, 2026
Merged

refactor(core): use Latch for plugin supervisor ready gate#43569
kitlangton merged 1 commit into
v2from
latch-supervisor

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What

The plugin supervisor's flush readiness signal is a hand-rolled reusable gate: a Deferred<void> in a mutable ready.current box, recreated via an isDone check on every update and re-awaited through Effect.suspend. Effect's Latch is exactly this primitive — a valueless, never-failing gate that can close and reopen — so this replaces the machinery with one Latch.

How

packages/core/src/plugin/supervisor.ts:

  • ready is now yield* Latch.make() (starts closed, like the fresh deferred).
  • Each observed update runs ready.close (idempotent) instead of isDone + recreate; the mutable box disappears.
  • Activation catching up to the latest generation runs ready.open instead of Deferred.succeed.
  • flush is ready.await directly — no Effect.suspend needed 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 full bun run test suite (1892 pass / 0 fail).

@kitlangton
kitlangton merged commit b453c20 into v2 Aug 20, 2026
10 checks passed
@kitlangton
kitlangton deleted the latch-supervisor branch August 20, 2026 15:37
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