flybrain/infra/box/flyshadow-remote.service
acamilo 56a315eda1 shadow: SHADOW-02, the shadow run on a build box
The on-container shadow cost the live fly real time (RTF 0.9998 -> 0.93-0.98,
27 ms/frame on shared CPUs, falling behind every hour). fly-shadow gains:

- relay (release container, as flyshadow.service): streams new saves, the
  trace bytes of this run and the sugar journal over one ssh connection;
  writes the box shadow's verdict back (runId-bound, lagTransitions plus the
  unsynced tail, a relay member) and keeps flysim's consumer heartbeat fresh
  only while connected, the box shadow of this run is alive and the box has
  everything that was on disk a minute ago; exits 3 on a remote divergence.
- ingest (build box, the relay key's forced command): checks the release
  directory and binary hashes against its own, resets the mirror for a new
  run, writes the mirror and reports acks, liveness, verdict, divergence.
- run --run-id-file: the verdict carries runId; a new id exits 4.
- coverage: a no-consumer trace stop while following is a coverage
  divergence (a stop that predates the shadow stays a trace-cap skip); the
  journal is read before the trace directory is listed.

tests/shadow_remote.rs runs a real flysim, the relay, the real ingest binary
and a remote shadow through a restart, a remote shadow death and a sync
stall (coverage divergence relayed back).

infra: fly-shadow-run start runs remote with /etc/fly/shadow-remote.env
(a flyshadow.service drop-in running the relay; --local keeps the old
placement), check also needs relay.json healthy; infra/box/ holds the build
box's flyshadow-remote.service/.path and fly-shadow-remote-setup (release at
the same path, root-owned restrict,command= authorized_keys); 02-base adds
openssh-client. Runbook, lint and a dated legacy-gameboy-v1 section 18
amendment.
2026-10-01 00:45:54 +00:00

55 lines
3 KiB
Desktop File

# infra/box/flyshadow-remote.service — installed on a BUILD BOX, never on the release container,
# by infra/bin/fly-shadow-remote-setup (SHADOW-02).
#
# The shadow run (SHADOW-01, legacy-gameboy-v1 section 18) moved off the release container: there it
# cost the live fly real time (2026-09-30: RTF 0.999 -> 0.93-0.98 with the shadow SCHED_IDLE on the
# page and encoder CPUs, 27 ms of shadow per frame, falling further behind every hour). Here it runs
# the SAME release (installed from the same tarball at the same /opt/fly/releases/<version> path,
# so the verdict's release and binary hashes are the container's), on this box's own cores, at
# normal priority.
#
# Its input is the mirror /srv/fly-shadow-remote, written by `fly-shadow ingest`, the forced
# command of the one key the container's relay (`fly-shadow relay`, flyshadow.service there) holds;
# the relay writes this shadow's verdict back to the container, where `fly-shadow-run check`, its
# guard and CUT-01 read it as before. REPORT-ONLY: it reads the mirror, writes <root>/out and its
# runtime directory, and serves nothing.
#
# The run: `fly-shadow-run start` on the container gives each run an id; the ingest writes it to
# <root>/run-id (after resetting the mirror). A running shadow sees the change within 5 s and exits
# with status 4, and Restart=always starts the new run; a shadow that is down (it diverged: exit 3,
# which is not restarted, so the diverged verdict stays) is started by flyshadow-remote.path.
[Unit]
Description=flyshadow-remote: the session runtime shadowing the live fly from a build box (SHADOW-02, report only)
ConditionPathExists=/opt/fly/current/fly-shadow
ConditionPathExists=/srv/fly-shadow-remote/run-id
[Service]
Type=simple
User=flyshadow
# The live composition's settings, as the relay forwarded them (game, macro mode, accepted
# adapters, pins; never a path or a secret), then this box's own paths: FLY_ROM (the cartridge,
# with the container's ROM_SHA256) and FLY_DATASET (the release's connectome).
EnvironmentFile=-/srv/fly-shadow-remote/live.env
EnvironmentFile=/etc/fly/fly-shadow-remote.env
Environment=FLY_TRACE_DIR=/srv/fly-shadow-remote/trace
Environment=FLY_STATE_HOT=/srv/fly-shadow-remote/hot
Environment=FLY_STATE=/srv/fly-shadow-remote/durable
Environment=FLY_SHADOW_DIR=/srv/fly-shadow-remote/out
Environment=FLY_SHADOW_WORK=/run/flyshadow-remote
RuntimeDirectory=flyshadow-remote
# 3 sweep threads (the SHADOW-01 measurements: 13-15 ms a frame against 16.7 ms of real time).
Environment=FLY_SHADOW_THREADS=3
# No lag back-off: the live fly is on another machine. The spool holds a long catch-up.
ExecStart=/opt/fly/current/fly-shadow run --run-id-file /srv/fly-shadow-remote/run-id --lag-guard-margin 0 --spool-max-mib 4096
Restart=always
RestartSec=2
RestartPreventExitStatus=3
# Dedicated cores (fly-shadow-remote-setup --cpus writes AllowedCPUs= in a drop-in) at a weight
# above anything else on the box: a build must not starve the shadow.
CPUWeight=1000
Nice=-5
MemoryMax=6G
TimeoutStopSec=30
[Install]
WantedBy=multi-user.target