1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
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