Skip to content

[skip-tag:sdk] feat(sdk/engine): StreamRouter for multi-sink delta fan-out (2/4)#75

Merged
lIang70 merged 2 commits into
mainfrom
feat/sdk-stream-router
May 8, 2026
Merged

[skip-tag:sdk] feat(sdk/engine): StreamRouter for multi-sink delta fan-out (2/4)#75
lIang70 merged 2 commits into
mainfrom
feat/sdk-stream-router

Conversation

@lIang70

@lIang70 lIang70 commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Part 2 of 4 in the v0.2.x additive SDK batch. Tagging suppressed via
[skip-tag:sdk]; cumulative sdk/v0.2.9 tag will be cut on PR 4/4.

Introduces a centralized stream-delta fan-out mechanism so multiple consumers
(SSE, WebSocket, log forwarders, custom telemetry) can share one subscription
to SubjectStreamDelta events without each rolling their own subscriber.

Surface

  • StreamSink interface — single OnDelta(ctx, env, delta) method.
  • StreamSinkFunc — function adapter for stateless sinks.
  • StreamRouter — bus-agnostic fan-out:
    • NewStreamRouter(bus, opts...) *StreamRouter
    • Attach(name, sink) error / Detach(name)
    • Close() — drains and detaches all sinks.
    • Auto-teardown on SubjectRunEnd (configurable via option).
    • Per-sink error isolation: a panicking/erroring sink is logged but does
      not affect peers.

Test plan

  • go vet ./engine/...
  • go test ./engine/... -count=1
  • New test file sdk/engine/stream_sink_test.go covers:
    • Multi-sink fan-out preserves order and delivers to all attached sinks.
    • One sink returning an error does not stop other sinks.
    • SubjectRunEnd triggers auto-teardown.
    • Attach after Close returns an error.

Release notes

Additive; no breaking changes. Tag deferred to PR 4/4.

Made with Cursor

- StreamSink interface + StreamSinkFunc adapter for stream-delta consumers
  (SSE, WebSocket, log forwarders, etc.).
- StreamRouter fans out an event.Bus subscription on SubjectStreamDelta to
  any number of attached sinks with per-sink error isolation.
- Auto-teardown on SubjectRunEnd; explicit Close() drains and detaches sinks.
- Attach-after-Close is rejected; sink errors are logged via the configured
  logger but do not propagate to peer sinks.

Additive only.

Co-authored-by: Cursor <cursoragent@cursor.com>
@lIang70
lIang70 merged commit d3f6a23 into main May 8, 2026
17 checks passed
@lIang70
lIang70 deleted the feat/sdk-stream-router branch May 8, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant