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

host: the firehose, with each commit's proof, and relays told of news

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:host/firehose

What changes

The firehose. com.atproto.sync.subscribeRepos over WebSocket: every event after cursor, then each as it is made; without a cursor, from now. A frame is a DRISL header (op 1, t) and body with its seq; a cursor past the last event is refused with an op -1 frame, FutureCursor, and one that is not a number with 400.

Events, kept with what they report. A new table, event, holds each in the same transaction as the change: a new account's #identity, #account and first #commit, and each write's #commit. A commit event is sync 1.1's: its ops, each with its prev CID for an update or delete; since and prevData from the commit before; and a CAR slice of the commit, the nodes the new tree has that the old lacked, each changed path's covering proof (as the interop commit-proof vectors check them in atproto), and the records written.

Relays told of news. PDS_CRAWLERS names relays sent requestCrawl with the host's hostname after a change: at most every 20 minutes, and the first time after a start, as the prototype and the reference PDS do.

Beside them: atproto::drisl::decode_first reads a value and says how many bytes it took, for a frame's two; Value::into_map; and group_host::time::iso writes times as atproto does, with no date crate. docs/reference/config.md gains PLC_URL, which the repos pull left out, and PDS_CRAWLERS.

Why

A relay, an appview and a member's app follow a group's repo through its host's firehose; without it nothing a group writes is seen.

How it was checked

tests/firehose.rs, over a real WebSocket: the four events of an account and a write in order, their kinds and seqs; the write's op, its since, its prevData, and its CAR, whose commit verifies with the account's key and holds the new root and the record; an update's and a delete's ops followed live; following from now without a cursor; 513 events read through pages of 500; FutureCursor; a bad cursor's 400; a client's message and close; and the relays told once of two changes, one relay answering and one not there. cargo llvm-cov at 100% of lines and functions, clippy clean.

Shortcomings

Stacked on the repos pull. Events are kept forever: no window, so no OutdatedCursor yet. #sync and #info frames are not sent. The firehose has no backpressure past the WebSocket's own.

Approved

This adds subscribeRepos over WebSocket and an event table written in the same transaction as each change. Commit events follow sync 1.1: ops with prev, since, prevData, and a CAR slice. It also adds throttled requestCrawl to the PDS_CRAWLERS relays, plus decode_first, into_map and time::iso.

I read the firehose, store, repo, config, time and drisl changes. I did not read the rest of the 212-file diff, which is mostly the stacked repos pull (lexicons, web, vendored interop data). I did not run anything or read the checks. The code I read is sound:

  • The stream subscribes to wake-ups before reading last_seq, so no event is missed between reading and waiting.
  • A lagged receiver only loses wake-ups, and the database fills the gap.
  • announce runs after the commit, so a stream never wakes for an event that isn't stored.
  • Event rows are inserted in the same transaction as the repo update.

Two small things, neither blocking:

  • A negative cursor (e.g. -5) passes the c > last check and replays everything. Treating it as a 400, like a non-number, would be more consistent.
  • last_seq() and events_after() errors are swallowed with unwrap_or_default(). A DB error at connect time shows up to the client as FutureCursor, and a later one makes the stream wait silently. Logging or closing the socket would make this visible.
crates/group-host/src/firehose.rsline 83Outdated

These lines can no longer be read.

review.knotless.dev

If last_seq() fails, last becomes 0 and any positive cursor is refused as FutureCursor. Also, a negative cursor is accepted here and replays from the start. Consider rejecting c < 0 with the 400, and not hiding the DB error.

crates/group-host/src/firehose.rsline 90Outdated

These lines can no longer be read.

review.knotless.dev

A DB error here gives an empty page, so the loop waits as if there were no news. The client sees nothing wrong. A log line, or closing the socket, would help.

Approved

This is the same pull as before: subscribeRepos over WebSocket, an event table written in the change's transaction, sync 1.1 commit events with proof CARs, and throttled requestCrawl to the PDS_CRAWLERS relays. I looked only at the head's follow loop and the cursor test in crates/group-host/src/firehose.rs and tests/firehose.rs. I did not re-read the rest of the diff or the checks.

My two earlier nits are not addressed, and neither blocks the merge:

  • A negative cursor still passes the c > last check and replays everything. A 400, like the non-numeric case, would be more consistent.
  • last_seq() and events_after() still use unwrap_or_default() in follow. A database error at connect time reaches the client as FutureCursor, and a later one stalls the stream silently. Log it or close the socket.
Merged as 88c28a0