~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/jetstream

jetstream client · mirror of https://tangled.org/zat.dev/jetstream

0
0
main
85 lines · 5.4 KB Raw History
# upstream client review

Source comparison begun September 6, updated September 20, 2026. The SDK's
reference pin is [`289b032` / v0.2.0](https://github.com/bluesky-social/jetstream/tree/289b032).
The later comparison used [`58c4d7f`](https://github.com/bluesky-social/jetstream/tree/58c4d7f7a9130e53b40348ad3d1f7aafed0e4843).
This records specific findings and checks, not exhaustive semantic parity.
For current consumer behavior, read [client.md](client.md) and
[failover.md](failover.md).

## live failover: correction to the earlier review

The official Go client binds one host. Multi-host failover is our extension,
so matching upstream's single-host replay behavior did not validate it.
The earlier review accepted the archive-based failover rationale without
checking whether the server already offered the required primitive.

Both checked server revisions accept Unix-microsecond timestamps on the live
endpoint. Our old path instead fetched `listSegments`, mapped witnessed time
to a sequence, and entered archive replay. An anchor-fetch failure continued
the subscription loop on the new host with stale cursor variables: null
variables restarted at the tip; sequence variables belonged to the old host.

The v0.1.5 fix sends `last_time_us - failover_rewind_us` directly as the
new host's live cursor. It makes no archive requests. A caller-supplied
timestamp transfers unchanged before first delivery; a caller-supplied
sequence cannot transfer without a witnessed-time anchor.

The wire cursor must remain separate from the sequence deduplication floor.
Upstream `runLiveOnly` seeds `dedupFloor` from `LiveCursor`, whose documented
input is a sequence. Passing a timestamp through that SDK method suppresses
normal sequence events even though the server accepts timestamps. Local
commit `7b93c13` copied this assumption. `LiveClient` now seeds deduplication
only from sequence cursors and learns the new host's sequences on delivery.

Evidence: upstream `client.go`, `client_core.go`, `options.go`, `live.go`,
`internal/subscribe/cursor.go`; local `src/client.zig`, `src/live.zig`, and
`src/loopback_test.zig`. Local baseline before this change: `b173d13`.

## earlier findings and disposition

| Area | Finding and resulting behavior |
|---|---|
| Archive pagination | The original client fetched one plan page. It now follows pages through the first pinned sealed tip and rejects non-advancing plans. |
| Filters | Archive exact-only matching and missing live DID/collection checks were corrected. Namespace wildcards and DID-level markers follow the upstream matcher contract. |
| Archive errors | Recoverable download/decode errors reach `onError`; accepting continues on the same archive. Plan, cancellation, and allocation failures remain terminal. |
| Authentication | The v0.1.1 live bearer-auth parity claim was incorrect. Credentials now apply only to archive requests; dictionary and WebSocket requests are public. |
| Compression | Dictionary-zstd now defaults on. Rejected dictionaries are refreshed or delivery falls back to uncompressed frames. See [compression-review.md](compression-review.md). |
| Retry policy | Three-attempt downloads, bounded delays, jitter, and server retry hints were aligned with upstream and Atmos. Signed reset parsing was addressed through ZAT 0.5.2 / ZTTP 0.1.2. |
| Record representation | Raw archive records remain available without map decoding. Callback-borrowed lifetimes differ from Go batch lifetimes. |

The initial archive pagination and wildcard omissions originated in the
August 7 archive client, carried here in `6832774`. The unified-client
pagination and live-filter gaps entered in `90f7068` (August 15).
`d215db5` introduced the incorrect live authentication behavior on August 17.
Archive errors stopped triggering cross-host rotation in `e01e1867`
(August 19); later work added recoverable same-host error callbacks.

## verification and limits

The September 20 suite passes **73/73 tests in Debug and ReleaseFast**;
`zig build` compiles the examples. Test execution takes about six seconds,
separate from compilation. The timestamp failover regressions failed before
the fix; the dead-primary initial timestamp case also failed before its fix.

Real loopback HTTP/WebSocket tests cover:

- no archive requests during live failover, with archive access denied;
- smaller sequences on the fallback, timestamp preservation across refused
  connections, and inclusive-boundary deduplication on reconnect;
- caller-supplied timestamp transfer and refusal to transfer an unanchored
  sequence;
- retention clamping with `OutdatedCursor` before retained events, and fatal
  `CursorTooOld` for rejected live sequences;
- explicit archive replay followed by live failover, plus existing archive
  pagination, filtering, authentication, and error cases.

New subscription scenarios have a ten-second deadline. These fixtures prove
client behavior against controlled protocol responses; they do not prove
identical host coverage or lossless cross-host delivery. A bounded live smoke
checks production connectivity separately. On September 20, both fresh-tail
and `--rewind` smokes against `stream.waow.tech` delivered ten events after
rotation from a refused local primary, in about 2.4 seconds each, under
external 30-second deadlines. The same timestamp smoke delivered ten events
from `jetstream.us-east.bsky.network` in 1.3 seconds. The README usage example compiled as a
separate consumer. No whole-archive drain is part of this verification.