Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/decisions/ADR-004-streaming-sse-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Three SSE parsing approaches were evaluated:

## Decision

**Use an inline SSE parser module, matching the pattern established by anthropic-sdk-python and openai-python.**
**Use an inline SSE parser module.**

### Evidence

Both reference SDKs (anthropic-sdk-python, openai-python) initially adopted httpx-sse, then replaced it with inline parsers (~100 lines each). Their reasons apply to us:
Of the three approaches listed above, manual line-by-line parsing (option 3) was eliminated early: it scatters SSE logic across every method, making reconnection and event routing untestable in isolation. The choice reduces to httpx-sse (option 1) vs an inline parser (option 2):

| Factor | httpx-sse | Inline parser |
|---|---|---|
Expand Down Expand Up @@ -174,15 +174,15 @@ def drain(self, session: str, *, after_event_id: str | None = None) -> list[Chan

- Zero new runtime dependencies (inline parser, no httpx-sse).
- Full control over reconnection, which is critical for Trigger.dev's `Last-Event-ID` resume pattern.
- Matches the established pattern from both reference SDKs (anthropic, openai).
- Full control over SSE event routing, enabling Trigger.dev-specific control records and typed event dispatch.
- Reuses existing retry infrastructure (`_retry.py`) for reconnection backoff.
- Reuses existing httpx2 client for connection pooling.
- Clear module separation: wire format (`_streaming.py`) vs transport (`_channels.py`).

### Negative

- ~100 lines of SSE parsing code to maintain. Mitigated by the SSE spec being stable (W3C, unchanged since 2015).
- Reconnection logic adds complexity beyond what reference SDKs implement. Justified by Trigger.dev's explicit support for `Last-Event-ID` resume.
- Reconnection logic adds complexity beyond a basic SSE client. Justified by Trigger.dev's explicit support for `Last-Event-ID` resume.

### Neutral

Expand Down