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

zat.dev/stream

jetstream v2 in zig · mirror of https://tangled.org/zat.dev/stream

0
0
62 lines · 3.3 KB Raw History

name: upstream-first description: Port-discipline for stream (zat.dev/stream) and other upstream-ports — check jim's reference implementation and zig idioms BEFORE accepting a cost, writing a fix, or claiming a behavior. Use when debugging, designing, or reviewing anything in a codebase that ports an upstream reference.

upstream-first

stream is a port of bluesky-social/jetstream (jim's Go implementation). The 2026-08-08 incident chain proved the discipline this skill encodes:

  • a "3h restart cost" accepted as fixed was one un-ported continue (header-level watermark skip, upstream spec §3.4)
  • a compaction famine was a documented un-ported prefilter
  • a subscriber wedge came from a structural divergence (sticky cold/hot mode vs upstream's transparent per-read boundary)

Every one was answerable by reading upstream before reasoning from scratch.

the method, in order

  1. Locate the counterpart in the upstream clone first. Local pin: ~/github.com/bluesky-social/jetstream (check git log -1 for the pin; the repo's own pin note lives in the relay-project memory). Grep for the subsystem (internal/subscribe, internal/ingest/orchestrator, segment/, internal/tombstone) and read jim's implementation AND its comments — his comments carry spec citations and invariants (e.g. "rebuild cost must scale with the watermark backlog, not the archive — spec §3.4"; "the hot/cold boundary is transparent to ReadFrom").

  2. Name the divergence. Deliberate divergences are recorded in docs/upstream-*.md in the stream repo. If the behavior you're chasing diverges and is NOT recorded there, you have found either the bug or an undocumented decision — both require a doc update.

  3. Never accept an operational cost as inherent (slow restart, heavy pass, degraded delivery) until you have read how upstream pays the same cost. If upstream doesn't pay it, it's a port gap, not a constraint.

  4. Cite file:line from the clone for any claim about upstream behavior. "Upstream doesn't use X" requires a grep that would have found X — include atmos/dependency names in the grep (go.mod first), not just the obvious suspects. (The "jetstream vendors its own decode" mistake: grepped indigo/go-car, never atmos, concluded wrongly.)

  5. Zig idioms check: before shipping the fix, consult zigman for any language semantics you are less than certain about, and run zig zen as the closing sanity ritual — "favor reading code over writing code" and "incremental improvements" are the two that map to this workflow.

  6. Tests mirror upstream's tests. When upstream has a test pinning the behavior (e.g. TestRebuildLiveTombstones_BoundedByWatermark), mirror its shape and name it in the test comment; strengthen it where zig can (e.g. truncate a fixture so any forbidden read fails loudly) — never invent an API from memory; read the fixture patterns in the same file.

anti-patterns this replaces

  • static-analyzing our port in circles when the reference implementation answers the question in one read
  • accepting "that's just how long it takes" for anything upstream does fast
  • guessing at our own test-fixture APIs instead of reading either our existing tests or upstream's
  • concluding "doesn't exist" from a grep that couldn't have found it