runbook, flybus and tour: the feed over the bus in production
This commit is contained in:
parent
6612f9ae9c
commit
5ca3488c1f
4 changed files with 166 additions and 5 deletions
|
|
@ -136,7 +136,8 @@ publish. Pacing uses absolute deadlines at 1.0x by default; it never skips frame
|
|||
audio (binjgb's unipolar u8 converted and DC-blocked), and a 17,407-byte spike bitset.
|
||||
flysim serves it itself by default; with `FLY_FEED_VIA=bus` it publishes each snapshot on an
|
||||
embedded flybus router and the `fly-edge` process serves the same bytes
|
||||
(`docs/design/flybus.md`, "Feed over the bus").
|
||||
(`docs/design/flybus.md`, "Feed over the bus"; on a container `fly-feed bus|direct` switches, runbook
|
||||
"Feed over the bus").
|
||||
- Control API (`docs/control-api.md`): loopback HTTP :7401. `POST /stimulate` (sugar: a timed PAM
|
||||
pulse, rate-limited server side), `POST /reward` (present, disabled by config), `POST /chat`
|
||||
(sanitized, deny-listed, ring of 12), `/status`, `/checkpoint`, `/pause`, `/resume`,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
# flybus: the communications bus
|
||||
|
||||
Status: **crate landed; the feed rides it behind `FLY_FEED_VIA=bus`, off by default**.
|
||||
Written 2026-09-22, amended 2026-09-23 (EDGE-01, below). Index only; the
|
||||
Status: **crate landed; the feed rides it behind `FLY_FEED_VIA=bus`, off by default; EDGE-02
|
||||
(2026-10-01) made it switchable in production with one command, `fly-feed bus|direct`**.
|
||||
Written 2026-09-22, amended 2026-09-23 (EDGE-01) and 2026-10-01 (EDGE-02, below). Index only; the
|
||||
authority for the API and the wire format is the crate's own
|
||||
[README](../../services/flysim/crates/flybus/README.md), and the audit of the crate against
|
||||
the draft is the [conformance report](session-framework/bus-conformance.md).
|
||||
|
|
@ -188,3 +189,45 @@ Accepted for now and written down rather than fixed:
|
|||
escalates. Switch back to `direct` first (the unit header's way back), then roll back.
|
||||
- **Old fixtures.** `cold-open`, `steady` and `big-moment` predate `game.scene` and cannot be a
|
||||
Rust `FeedHeader`, so fixture parity covers `macros`, `shop`, `center` and `bigpad`.
|
||||
|
||||
### Amendment 2026-10-01: the feed in production (EDGE-02)
|
||||
|
||||
- **The session runtime needed nothing.** `flysim-session` serves its listeners through
|
||||
`flysim::serve`, the same function `flysim` does, so `FLY_FEED_VIA=bus` works on it as it was
|
||||
written for legacy. It is now a test, not an inference: `fly-legacy-session/tests/feed_bus.rs`
|
||||
runs the real `flysim-session` binary (toy connectome, the real cartridge) twice from copies of
|
||||
one store, direct and bus, records both feeds over a WebSocket and requires every frame in
|
||||
common to be identical (header minus the wall-clock fields, frame, audio and spike bytes), then
|
||||
stops the binary and starts a new one under the same edge, which must unbind, reconnect and
|
||||
serve. In the session runtime the router and publisher (`flysim-bus`, two threads) inherit the
|
||||
host mask of `place_workers` (PERF-02), so they run on the host CPU with the listeners, never on
|
||||
a pinned sweep CPU.
|
||||
- **One switch.** `FLY_FEED_VIA` in `fly.env` decides everything: `flyedge.service` has an
|
||||
`ExecCondition=` on it (skipped, not failed, in direct mode) and no `[Install]`;
|
||||
`flysim.service` has `Wants=flyedge.service`, so every start of flysim, including the stop and
|
||||
start of `fly-loop-reset` that `Requires=` alone left without an edge, brings the edge up in bus
|
||||
mode. Checked on systemd 257 with the repo's own units: crash, restart and stop/start of flysim
|
||||
all end with the edge serving; direct mode never starts it. `infra/bin/fly-feed bus|direct`
|
||||
rewrites the line, restarts flysim, waits for a new invocation, the edge's `/healthz` and the
|
||||
page on the feed (frames moving), and rolls itself back (to `direct`) when that does not happen
|
||||
or when it is interrupted. It works on either runtime and survives `fly-runtime` changes.
|
||||
- **Edge health.** `/healthz` is 503 unless the edge is subscribed **and** has taken a snapshot off
|
||||
the bus within 15 s (`fly_edge_snapshot_age_seconds`): a loop publishes at least the 2 Hz idle
|
||||
header, so silence means a wedged subscription, which `Subscription::next` alone would never
|
||||
report.
|
||||
- **Watchdog.** `feed_via` follows the *running* flysim's environment (a deploy that rewrote
|
||||
fly.env but has not restarted flysim is not an outage). New check 2a judges the edge only while
|
||||
flysim answers: second failed pass restarts it, third adds the page and the encoder, fourth
|
||||
switches the feed back to flysim (`fly-feed direct --no-wait`, sudoers for exactly that line).
|
||||
Check 2 in bus mode leaves a silent edge to 2a instead of restarting a page with nothing to
|
||||
connect to.
|
||||
- **Deploy.** `05-deploy.sh` installs `fly-feed`, refuses a release without `fly-edge` while the
|
||||
env file or the container says `bus` (before `current` moves; `fly-feed direct` needs no
|
||||
binary), and warns when the container's `FLY_FEED_VIA` differs from the env file's. flysim and
|
||||
the edge both follow fly.env at their next start, so a disagreement never leaves the stage with
|
||||
no feed.
|
||||
- **Known limits, revisited.** *Feed counters off the container*: the edge's `/metrics` now listens
|
||||
on `0.0.0.0:9102` like flysim's `:9101`; a dashboard adds it as a second target (the watchdog
|
||||
stays on loopback). *Rollback while in bus mode*: refused by the deploy and one command by
|
||||
`fly-feed direct`. *Store quota per router* and *old fixtures*: unchanged, accepted as written.
|
||||
|
||||
|
|
|
|||
|
|
@ -519,6 +519,118 @@ pct exec $CTID -- /opt/fly/bin/fly-runtime legacy # the one-command rollback
|
|||
cannot be enabled). It is for a rehearsal or a soak on a container whose `flysim.service` is
|
||||
stopped, not for switching the stream.
|
||||
|
||||
## Feed over the bus (EDGE-02)
|
||||
|
||||
`ws://127.0.0.1:7400/feed` is served either by `flysim` itself (`direct`, how every release before
|
||||
EDGE-01 did it, and the default) or by `fly-edge` from flysim's embedded feed bus (`bus`,
|
||||
`docs/design/flybus.md` "Feed over the bus"). The WebSocket contract is the same bytes either way
|
||||
(`docs/feed-protocol.md`); nothing about the fly, the readout or the compatibility string changes,
|
||||
on either runtime (`flysim` or `flysim-session`, `fly-runtime`). The stage, the bridge and the
|
||||
capture never see the difference.
|
||||
|
||||
**One switch, one line.** `FLY_FEED_VIA` in `/etc/fly/fly.env` (written by every deploy from the
|
||||
env file's `FLY_FEED_VIA`, default `direct`). flysim reads it, `flyedge.service` runs only when it
|
||||
says `bus` (`ExecCondition=`; in direct mode the unit starts as "skipped", inactive and not
|
||||
failed), and `flysim.service` has `Wants=flyedge.service`, so **every** start of flysim brings the
|
||||
edge up in bus mode, whoever starts it: a reboot, the unstick rule's restart, `fly-loop-reset`'s
|
||||
stop and start, `fly-reset-to-milestone`, a crash-restart. There is nothing to enable or start by
|
||||
hand, and flysim and the edge cannot disagree.
|
||||
|
||||
```
|
||||
pct exec $CTID -- /opt/fly/bin/fly-feed status # configured / running / the edge and its counters
|
||||
pct exec $CTID -- /opt/fly/bin/fly-feed bus # switch (restarts flysim; rolls itself back if unhealthy)
|
||||
pct exec $CTID -- /opt/fly/bin/fly-feed direct # the way back
|
||||
```
|
||||
|
||||
### The live procedure
|
||||
|
||||
Preconditions: the release has `fly-edge` (v0.7.6 and later; `ls /opt/fly/current/fly-edge`),
|
||||
`fly-feed` is installed (`/opt/fly/bin/fly-feed`, converged by the deploy), the container is
|
||||
claimed in the host log as for any host work, and `fly-feed status` says `configured: direct`,
|
||||
`running: direct`. Pick a moment you would also pick for the unstick rule's restart: **the switch
|
||||
restarts flysim**, so the stream shows the stage's reconnect screen for about a minute (the
|
||||
restore, the warm-up and the page's reconnect; the rehearsal measured it, below), and the run
|
||||
continues from the last checkpoint. It counts as one start against `flysim.service`'s start limit
|
||||
(3 in 10 minutes on the session runtime), two if it rolls back: do not switch within ten minutes
|
||||
of two other restarts.
|
||||
|
||||
```
|
||||
# 1. Before: the baseline to compare with (keep the output).
|
||||
pct exec $CTID -- /opt/fly/bin/fly-feed status
|
||||
pct exec $CTID -- sh -c 'curl -s 127.0.0.1:9101/metrics | grep -E "^fly_(realtime_factor|lag_seconds|feed_clients|frames_sent_total) "'
|
||||
pct exec $CTID -- fly-cpu-confine status # PERF-02: the sim's cpus are the sim's
|
||||
# 2. Switch. Blocks until the page is on the feed again (FLY_FEED_HEALTH_TIMEOUT, 300 s) and prints
|
||||
# "healthy (bus): the page is on the feed and frames are moving", exit 0.
|
||||
pct exec $CTID -- /opt/fly/bin/fly-feed bus
|
||||
# 3. Make it permanent for the next deploy: FLY_FEED_VIA=bus in the operator's env file for this
|
||||
# container. (A deploy that finds fly.env and the env file disagreeing warns loudly and writes the
|
||||
# env file's value; flysim applies it at its next restart.)
|
||||
# 4. Look at it (below) for a few minutes, then at the end of the first hour and the first day.
|
||||
pct exec $CTID -- /opt/fly/bin/fly-feed status
|
||||
```
|
||||
|
||||
What `fly-feed bus` does, in order: refuses unless the release has `fly-edge`, takes
|
||||
`/run/fly/feed.lock`, rewrites the one `FLY_FEED_VIA` line (every other line, the mode and the owner
|
||||
kept), restarts `flysim.service` (`--no-block`, then waits for a **new** invocation's `/healthz`),
|
||||
waits for the edge's `/healthz` (subscribed to the bus, a snapshot within 15 s) and, while
|
||||
`flystage.service` is active, for the page: `fly_feed_clients >= 1` on the edge's counters with
|
||||
`fly_frames_sent_total` advancing. Anything short of that within the timeout puts `FLY_FEED_VIA`
|
||||
back to `direct`, restarts flysim again, checks it the same way and exits 1 (`--no-rollback`
|
||||
leaves the failed switch in place for the operator; an interrupted switch, ssh dropped or INT, TERM
|
||||
or HUP, rolls back too). Every switch is in the journal (`journalctl -t fly-feed`) and
|
||||
`/var/lib/fly/feed.log`.
|
||||
|
||||
### What to watch
|
||||
|
||||
| Where | Healthy in bus mode | Wrong looks like |
|
||||
| --- | --- | --- |
|
||||
| `fly-feed status` | `configured: bus`, `running: bus`, `edge healthz: ok`, snapshot age under a second, `bus lost` and `bind failures` not growing | `running` differs from `configured` (a deploy wrote a new value; the next flysim start applies it); `edge healthz: NOT OK` |
|
||||
| edge `:9102/metrics` (loopback for the watchdog; the same address answers on the container's network for the dashboard) | `fly_edge_bus_connected 1`, `fly_edge_snapshot_age_seconds` under 1, `fly_feed_clients 1` (the page; the bridge or a test adds more), `fly_frames_sent_total` rising about 30 a second, `fly_edge_decode_failures_total 0`, `fly_edge_bind_failures_total 0` | `bus_connected 0` (flysim down, or restarting), `bind_failures_total` rising (something else holds :7400: a flysim still in direct mode, a stale process), `decode_failures_total` rising (a mismatched flysim and fly-edge: deploy one release) |
|
||||
| flysim `:9101/metrics` | `fly_bus_published_total` rising at the snapshot rate, `fly_bus_publish_failures_total` flat 0; `fly_feed_clients` and `fly_frames_sent_total` read **0 here in bus mode** (the counters belong to the edge) | publish failures rising: the store is full or the edge's seat is stuck; read `journalctl -u flysim -g "feed bus"` |
|
||||
| `fly_realtime_factor`, `fly_lag_seconds` | the same as the baseline from step 1, within the usual noise: the publisher is one 6% thread on the host CPU, and the websocket writes it replaces were on that CPU in direct mode | a drop that persists for the hour: switch back (`fly-feed direct`) and compare |
|
||||
| `ps -L -o pid,psr,comm -p $(pidof fly-edge)` / `grep Cpus_allowed_list /proc/$(pidof fly-edge)/status` | the page CPUs (`flyedge.service.d/cpuset.conf`, written by the deploy), never the sim's | an edge on the sim's CPUs: the cpuset drop-in is missing; re-run the deploy |
|
||||
| `ls -R /run/fly/bus/store | wc -l`, `du -sk /run/fly/bus` | a few files, under 1 MB, flat for days (the router keeps one retained snapshot and what the edge is still reading) | growth: report it, restart flysim, switch back |
|
||||
| `journalctl -u flyedge -u flysim -g "bus|feed|edge"`, `journalctl -t fly-watchdog -g flyedge` | `serving the feed from the bus` once per flysim start | `the feed bus went away` outside a flysim restart; a watchdog line `flyedge: ... failures` |
|
||||
| the stream | the page is up, frames moving | the page on its reconnect screen: `fly-feed status`; if the edge is down `systemctl status flyedge`; `fly-feed direct` is the one-command answer |
|
||||
|
||||
The watchdog follows the **running** mode (the running flysim's own environment, so a deploy that
|
||||
changed `FLY_FEED_VIA` but has not restarted flysim is not an outage). Check 2 reads the feed
|
||||
counters from the edge in bus mode; a new check 2a judges the edge itself, only while flysim answers
|
||||
`/healthz` (a down flysim is check 1's): active and `/healthz` 200, one failed pass let go, then
|
||||
the second pass restarts `flyedge`, the third restarts the page and the encoder as well, and the
|
||||
fourth **puts the feed back on flysim** (`fly-feed direct --no-wait`, granted in sudoers with exactly
|
||||
those arguments): one more flysim restart, and `FLY_FEED_VIA=direct` stays until an operator
|
||||
switches again (put it in the env file too). Check 2 in bus mode leaves a silent edge to 2a rather
|
||||
than restarting a page that has nothing to connect to, and its chain ends with the edge and the
|
||||
encoder.
|
||||
|
||||
### Rolling back
|
||||
|
||||
- `fly-feed direct`: writes `direct`, restarts flysim, waits until the page is on flysim's own
|
||||
feed, stops a lingering edge. It needs nothing from the release (it works on one without
|
||||
`fly-edge`), and it is the way back if anything above looks wrong. It restarts flysim again, so
|
||||
count it against the start limit.
|
||||
- Automatic: a switch that does not become healthy (above), the watchdog's fourth failed pass, and
|
||||
`fly-runtime fallback` (to legacy) all leave `FLY_FEED_VIA` alone: the setting is the same on both
|
||||
runtimes.
|
||||
- A deploy of a release **without** `fly-edge` is refused (before `/opt/fly/current` moves) while
|
||||
the env file says `bus` or the container is in bus mode: `fly-feed direct` and set
|
||||
`FLY_FEED_VIA=direct` in the env file first, then roll back or deploy.
|
||||
- A reboot keeps whatever `fly.env` says.
|
||||
|
||||
### Notes
|
||||
|
||||
- **Dashboards.** In bus mode flysim's `:9101` reports `fly_feed_clients` and
|
||||
`fly_frames_sent_total` as 0. Scrape the edge's `:9102` too (same names, plus the `fly_edge_*`
|
||||
series); the metrics address is on every interface, as `:9101` is, and exposes nothing but
|
||||
counters.
|
||||
- **CPUs.** `flyedge.service` is confined to the page CPUs by the deploy's drop-in; the router and
|
||||
the publisher run inside flysim, on its `flysim-bus` runtime (two threads on the host CPU, with
|
||||
the listeners, not on a pinned sweep CPU).
|
||||
- **The store** is `/run/fly/bus` (tmpfs, `fly` 0700, 32 MiB cap, in practice under 0.5 MB). A
|
||||
reboot empties it; a crashed flysim's directory is removed by the next one.
|
||||
- **Control (`:7401`)** stays in flysim and is not part of this switch.
|
||||
|
||||
## Shadow run (SHADOW-01)
|
||||
|
||||
The session runtime, run beside the live fly as the gate for the automatic cutover (CUT-01). The
|
||||
|
|
|
|||
9
infra/env/example.env
vendored
9
infra/env/example.env
vendored
|
|
@ -321,8 +321,13 @@ FLY_MACRO_MODE=raw
|
|||
# Who serves ws://127.0.0.1:7400/feed (docs/design/flybus.md, "Feed over the
|
||||
# bus"). direct: flysim binds it, as always. bus: flysim publishes every
|
||||
# snapshot on its embedded feed bus (/run/fly/bus) and flyedge.service serves
|
||||
# the same bytes; enable that unit by hand (its header has the steps).
|
||||
# Watchdog check 2 follows this setting to the edge's counters by itself.
|
||||
# the same bytes. This line (written into fly.env by every deploy) is the only
|
||||
# switch: flysim.service wants the edge, which starts only in bus mode.
|
||||
# On a live container switch with `fly-feed bus` / `fly-feed direct` (restarts
|
||||
# flysim, checks the page is back, rolls back by itself) and put the same value
|
||||
# here afterwards, or the next deploy warns that it writes the old one back.
|
||||
# Watchdog check 2 follows the running mode to the edge's counters by itself.
|
||||
# Runbook: "Feed over the bus".
|
||||
FLY_FEED_VIA=direct
|
||||
# How long a macro leaves a target alone after a walk to it aborted "blocked" or
|
||||
# "timeout" (macros.md section 12.1). Session state, so a restart offers every
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue