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

zat.dev/zlay

atproto relay in zig · mirror of https://tangled.org/zat.dev/zlay

0
0
126 lines · 6.5 KB Raw History

Isolated zkv relay canary

Endpoint: https://zlay-zkv-canary-9b9110.fly.dev

WebSocket: wss://zlay-zkv-canary-9b9110.fly.dev/xrpc/com.atproto.sync.subscribeRepos

Health: https://zlay-zkv-canary-9b9110.fly.dev/_healthz

The canary runs separately from production with its own fresh PostgreSQL, zkv directory and event files. Historical production index data were not migrated. Neither production ingress nor production storage was changed.

Resources and replay contract

  • One sustained Fly performance vCPU, 2 GiB RAM and a 2 GiB root filesystem.
  • No persistent volume. Root filesystem persistence is enabled as a cache, not a durable storage guarantee; machine deletion removes its contents.
  • Replay is enabled with a 120-second target and a 256 MiB event-file budget. Files rotate after approximately 1,024 events; GC runs every ten seconds. Retention is approximate and best effort, not a guaranteed two-minute minimum.
  • The RAM frame-history ring retains no entries. Cursor playback uses disk.
  • Old cursors receive OutdatedCursor and continue from the retained window.
  • The VM is configured to auto-delete when the relay process exits. A local watchdog stops it at 2026-11-06 09:02:09 UTC (03:02:09 America/Chicago), or if the root filesystem has less than 128 MiB free. It escalates to SIGKILL after fifteen seconds if necessary. The empty Fly app/address reservation can remain after automatic machine deletion; explicit app removal is below.
  • Admin HTTP endpoints are not configured and return 403. PostgreSQL listens only on loopback. Only relay HTTP/WebSocket port 3000 is exposed through TLS; metrics port 3001 is internal.

The root image is Node 24 on Debian bookworm; PostgreSQL and certificates are installed on the VM. The relay is stripped x86_64 Linux ReleaseSafe, built with lalinsky/zio and live stage profiling. RELAY_INDEX_PROFILE=bounded, sixteen frame workers, twenty DB connections and two zio executor threads are explicit. The executable hash, image digest and actual machine settings are recorded in resources.json. The binary was built at a02c35b; later commits change deployment/probe scripts only.

Verification

The original three-minute checking stream received 53,619 events without CBOR errors, reversals or gaps. Recent public replay started at exactly cursor + 1 and continued without gaps. An old cursor received OutdatedCursor, and the oldest retained file had advanced beyond the start of the observation.

An assertion in that probe was invalid: it kept processing buffered frames after requesting a WebSocket close and mutated the map being iterated for index checks. The intended eight-entry sample grew to 292 checks. The one missing membership belonged to a repository whose public status was active=false, status=takendown; its removal was correct. This was not accepted as an index failure or silently discarded. The raw probe is retained.

The corrected probe freezes callbacks and its membership snapshot, prunes inactive accounts, and distinguishes a missing active membership from expected removal. A short follow-up on the same already-warm VM verified:

  • Both Node's built-in WebSocket and pinned ws clients receive public events.
  • 3,971 local live frames and 2,900 public replay frames, with zero decode errors, reversals, gaps or duplicates in those samples.
  • The recent replay starts at cursor + 1.
  • The expired-cursor sample contains only the OutdatedCursor information message before closing, rather than accidentally consuming the backlog.
  • Eight sampled public collection-index reads pass.
  • RAM history remains at zero; retained event payload is 178,019,412 bytes (169.8 MiB), below the event-file budget. Final sampled relay RSS is 740 MiB.

The follow-up deliberately uses an already-expired cursor of 1 and a fifteen- second live window to check the sampler correction without repeating the cold bootstrap. It does not replace the earlier full retention-cycle observation. Raw corrected probe and pre-correction probe retain the separate observations. The normal accept-while-resolving validation policy is unchanged; successful downstream delivery does not imply every event was cryptographically checked.

Public handshake correction

The first public attempt served HTTP health checks and a correct local stream, but Node's built-in WebSocket received HTTP 502 from Fly. The pinned ws client worked. This was reproduced by adding ordinary request headers to ws: it worked directly, but failed through the proxy. The websocket server's default handshake budget was 1 KiB, before Fly added forwarded headers.

The canary's relay config now explicitly permits 8 KiB and 64 header entries. After that change, both clients work through Fly, and an approximately 1.2 KiB client request also upgrades successfully through the proxy. An approximately 9.3 KiB request still fails, confirming that the limit remains bounded. The header probe records the inputs used to reproduce this. No websocket dependency, zkv core or production configuration was changed.

The first setup also discovered that Fly refuses to reconfigure auto-destroy machines. Startup now waits for successful initialization in the original machine config, so activation does not require a machine update. Failed setup apps were deleted. The smaller-handshake VM was replaced under the retained canary URL; its metadata are archived alongside the final run.

Operation and removal

Inspect without changing the service:

fly status -a zlay-zkv-canary-9b9110
fly logs -a zlay-zkv-canary-9b9110 --no-tail

Remove the entire canary, including its app/address reservation:

fly apps destroy zlay-zkv-canary-9b9110 --yes

Changing /opt/canary/expires-at over Fly SSH changes the watchdog deadline; zero disables expiry. Do not extend the canary indefinitely without checking PostgreSQL/index disk growth. The 256 MiB budget applies to replay files, not all working state. This canary establishes an isolated usable service, not a production cutover, historical index completeness, restart-durability guarantee or maximum capacity qualification.

Offline disk comparison

The matched-input storage experiment measures both adapters on two million memberships, including growth, duplicate writes, churn, maintenance headroom and SIGKILL recovery. zkv retained 1.77 times the index disk of RocksDB in that workload. These measurements isolate the index from replay and PostgreSQL.