Files
anomalyco_opencode/packages/opencode/test
Kit Langton cb588ab4b9 fix(bus): acquire PubSub subscription eagerly to close /event race
`bus.subscribe(def)` and `bus.subscribeAll()` previously returned a
`Stream` whose underlying `PubSub.subscribe` ran lazily on first pull
(via `Stream.unwrap`). When a Stream was built in one place and consumed
in another — e.g. the `/event` SSE handler, which returns the stream
inside `HttpServerResponse.stream` for the body-pump fiber to consume
later — any publish in the hand-off window was lost.

The `/event` handler's `Stream.concat(server.connected, events)` shape
made this concrete: the events stream's PubSub.subscribe was only run
*after* `server.connected` was emitted and flushed to the socket, so
publishes that landed between the client receiving `server.connected`
and the body-pump fiber pulling from `events` were silently dropped.
SDK consumers (`client.event.subscribe()`, the Slack bot,
`opencode run --attach`) hit this routinely because they typically
subscribe and then trigger something that publishes (e.g.
`sdk.part.update`).

Change the bus interface so subscribe / subscribeAll return
`Effect<Stream, never, Scope>`. The subscription is now acquired
eagerly when the caller yields the effect, lives in the caller's
scope, and is released by the scope's finalizer. Any publish after
`yield*` is buffered into the subscription queue regardless of when
the consumer activates.

Migrated callers:
- /event handler (handlers/event.ts)
- plugin/index.ts
- project/project.ts
- project/vcs.ts
- share/share-next.ts

Regression tests added:
- test/bus/bus-effect.test.ts — 3 unit tests for eager subscribe,
  including the /event-shape Stream.concat pattern.
- test/server/httpapi-event-diagnostics.test.ts — 7 diagnostic
  tests (D1-D7) isolating each variable in the publisher chain. D7
  (no-op AppRuntime warmup) is the smallest regression trigger.
- test/server/httpapi-sdk.test.ts — end-to-end SDK subscription
  through /event during a sync.run-driven publish.
2026-05-16 22:32:55 -04:00
..
2026-05-14 23:34:42 +00:00
2026-05-15 19:48:45 +00:00
2026-05-15 07:36:10 +00:00
2026-05-13 02:08:16 +00:00
2026-05-16 09:20:35 -04:00