infra: fly-runtime session --bus; shadow of the bus topology

fly-runtime session --bus (session-bus) writes FLY_SESSION_TRANSPORT=bus
into the runtime drop-in and needs the release's fly-session worker;
session --local takes it out; a flag-less session (05-deploy's refresh)
keeps it. status prints the transport. 05-deploy refuses a release
without fly-session while the drop-in says bus.

fly-shadow-run start --bus runs the shadow's session on the bus
(FLY_SHADOW_MODE=bus/process, forwarded to a remote box by the relay);
check --bus requires a verdict that ran it. start refuses while the live
fly runs the session runtime, which writes no trace to follow. Runbook
and lint cover both.
This commit is contained in:
acamilo 2026-10-01 23:57:34 +00:00
parent 673eec54d5
commit 8b6d69e13c
5 changed files with 226 additions and 10 deletions

View file

@ -408,6 +408,11 @@ The 'current' symlink has NOT been moved; the running release is untouched."
if ct_exec "$CTID" -- test -f /etc/systemd/system/flysim.service.d/10-runtime.conf; then if ct_exec "$CTID" -- test -f /etc/systemd/system/flysim.service.d/10-runtime.conf; then
ct_exec "$CTID" -- test -x "${release_path}/flysim-session" \ ct_exec "$CTID" -- test -x "${release_path}/flysim-session" \
|| die "05-deploy: REFUSING to deploy release ${version}: flysim.service runs the session runtime (fly-runtime session) and this release has no flysim-session. Run \`fly-runtime legacy\` in the container first, or deploy a release that ships it. The 'current' symlink has NOT been moved." || die "05-deploy: REFUSING to deploy release ${version}: flysim.service runs the session runtime (fly-runtime session) and this release has no flysim-session. Run \`fly-runtime legacy\` in the container first, or deploy a release that ships it. The 'current' symlink has NOT been moved."
# BUS-01: on the bus transport flysim-session starts its participants from fly-session.
if ct_exec "$CTID" -- grep -qx 'Environment=FLY_SESSION_TRANSPORT=bus' /etc/systemd/system/flysim.service.d/10-runtime.conf; then
ct_exec "$CTID" -- test -x "${release_path}/fly-session" \
|| die "05-deploy: REFUSING to deploy release ${version}: flysim.service runs the session runtime on the bus (fly-runtime session --bus) and this release has no fly-session worker. Run \`fly-runtime session --local\` in the container first. The 'current' symlink has NOT been moved."
fi
session_compat="$(ct_exec "$CTID" -- env \ session_compat="$(ct_exec "$CTID" -- env \
"FLY_GAME=${GAME}" \ "FLY_GAME=${GAME}" \
"FLY_DATASET=${release_path}/data/fafb-v783" \ "FLY_DATASET=${release_path}/data/fafb-v783" \

View file

@ -3,8 +3,10 @@
# session runtime (`flysim-session`, SERVE-01). # session runtime (`flysim-session`, SERVE-01).
# #
# Usage (INSIDE the container, as root): # Usage (INSIDE the container, as root):
# fly-runtime status print `legacy` or `session`, and what flysim.service runs # fly-runtime status print `legacy` or `session` (and the session's transport), and
# fly-runtime session [--no-restart] [--no-fallback] [--no-probation] # what flysim.service runs
# fly-runtime session [--local|--bus] [--no-restart] [--no-fallback] [--no-probation]
# fly-runtime session-bus [...] the same as `session --bus`
# fly-runtime legacy [--no-restart] # fly-runtime legacy [--no-restart]
# fly-runtime fallback [reason] (run by fly-runtime-fallback.service, see below; idempotent) # fly-runtime fallback [reason] (run by fly-runtime-fallback.service, see below; idempotent)
# #
@ -12,6 +14,19 @@
# the one-command rollback (port decisions, 2026-09-23). Neither migrates any data: both # the one-command rollback (port decisions, 2026-09-23). Neither migrates any data: both
# binaries read and write the same FLYSIM01 stores, event log, sugar journal and chat sidecar. # binaries read and write the same FLYSIM01 stores, event log, sugar journal and chat sidecar.
# #
# The session's transport (BUS-01). `--local` (the default for a first switch) runs the session's
# participants in flysim-session's own process over the local lane. `--bus` runs them on the flybus
# router over Unix sockets: flysim-session (the router, the coordinator, the listeners) starts the
# agent and the world as child processes of the same unit (`fly-session legacy-agent`,
# `fly-session legacy-environment`, from the same release), in flysim.slice, on flysim's cpuset.
# The drop-in then carries `Environment=FLY_SESSION_TRANSPORT=bus`. Without either flag `session`
# keeps the transport the drop-in already has, so 05-deploy's `session --no-restart` refresh never
# changes it; `session --local` is the way back from the bus. Results, traces, checkpoints and the
# compatibility string are the same in both: only where the participants run changes. A switch onto
# the bus needs a shadow that ran the bus (`fly-shadow-run check --bus`), which the coordinator runs
# before this command, as for the first cutover. Everything below applies to both transports: one
# unit, OnFailure= falls back to LEGACY, the probation judges the session runtime either way.
#
# How the switch works. flysim.service stays the fly's one unit name, and the runtime it runs # How the switch works. flysim.service stays the fly's one unit name, and the runtime it runs
# is chosen by one drop-in, ${DROPIN}: # is chosen by one drop-in, ${DROPIN}:
# #
@ -91,6 +106,7 @@ RUNTIME_LOG="$FLY_RUNTIME_LOG"
FELLBACK_FILE="$FLY_RUNTIME_FELLBACK" FELLBACK_FILE="$FLY_RUNTIME_FELLBACK"
FALLBACK_UNIT=fly-runtime-fallback.service FALLBACK_UNIT=fly-runtime-fallback.service
SESSION_BIN="${FLY_RELEASE_DIR}/flysim-session" SESSION_BIN="${FLY_RELEASE_DIR}/flysim-session"
WORKER_BIN="${FLY_RELEASE_DIR}/fly-session"
LEGACY_BIN="${FLY_RELEASE_DIR}/flysim" LEGACY_BIN="${FLY_RELEASE_DIR}/flysim"
SESSION_DIR=/run/fly/session SESSION_DIR=/run/fly/session
SHADOW_RUN_BIN="${FLY_SHADOW_RUN_BIN:-$(dirname "$(readlink -f "$0")")/fly-shadow-run}" SHADOW_RUN_BIN="${FLY_SHADOW_RUN_BIN:-$(dirname "$(readlink -f "$0")")/fly-shadow-run}"
@ -120,7 +136,7 @@ stop_shadow() {
} }
usage() { usage() {
echo "usage: fly-runtime status | session [--no-restart] [--no-fallback] [--no-probation] | legacy [--no-restart] | fallback [reason]" >&2 echo "usage: fly-runtime status | session [--local|--bus] [--no-restart] [--no-fallback] [--no-probation] | session-bus [...] | legacy [--no-restart] | fallback [reason]" >&2
exit 2 exit 2
} }
@ -128,6 +144,20 @@ current() {
if [ -f "$DROPIN" ]; then echo session; else echo legacy; fi if [ -f "$DROPIN" ]; then echo session; else echo legacy; fi
} }
# The session's transport the drop-in selects: `bus` or `local` (also with no drop-in).
current_transport() {
if [ -f "$DROPIN" ] && grep -qx 'Environment=FLY_SESSION_TRANSPORT=bus' "$DROPIN"; then
echo bus
else
echo local
fi
}
# `legacy`, `session` or `session-bus`, for the runtime log.
current_label() {
if [ "$(current)" = session ] && [ "$(current_transport)" = bus ]; then echo session-bus; else current; fi
}
record() { record() {
local line local line
line="$(date -u '+%Y-%m-%dT%H:%M:%SZ') $*" line="$(date -u '+%Y-%m-%dT%H:%M:%SZ') $*"
@ -176,6 +206,12 @@ ExecStart=${SESSION_BIN}
Environment=FLY_SESSION_DIR=${SESSION_DIR} Environment=FLY_SESSION_DIR=${SESSION_DIR}
Environment=MALLOC_ARENA_MAX=2 Environment=MALLOC_ARENA_MAX=2
EOF EOF
if [ "$transport" = bus ]; then
cat >>"$tmp" <<EOF
# BUS-01: the participants are child processes on the session router's Unix sockets.
Environment=FLY_SESSION_TRANSPORT=bus
EOF
fi
chmod 0644 "$tmp" chmod 0644 "$tmp"
mv -f "$tmp" "$DROPIN" mv -f "$tmp" "$DROPIN"
} }
@ -339,26 +375,33 @@ command="$1"; shift
restart=1 restart=1
fallback=1 fallback=1
probe=1 probe=1
transport=""
fallback_reason="" fallback_reason=""
if [ "$command" = fallback ]; then fallback_reason="$*"; set --; fi if [ "$command" = fallback ]; then fallback_reason="$*"; set --; fi
if [ "$command" = session-bus ]; then command=session; transport=bus; fi
for arg in "$@"; do for arg in "$@"; do
case "$arg" in case "$arg" in
--no-restart) restart=0 ;; --no-restart) restart=0 ;;
--no-fallback) fallback=0 ;; --no-fallback) fallback=0 ;;
--no-probation) probe=0 ;; --no-probation) probe=0 ;;
--bus) [ "$command" = session ] || usage; transport=bus ;;
--local) [ "$command" = session ] || usage; transport=local ;;
*) usage ;; *) usage ;;
esac esac
done done
# No flag: keep the drop-in's transport (05-deploy's refresh); local for a first switch.
[ -n "$transport" ] || transport="$(current_transport)"
case "$command" in case "$command" in
status) status)
current current
if [ "$(current)" = session ]; then echo " transport: $(current_transport)"; fi
if [ -f "$FELLBACK_FILE" ]; then echo " fell back to legacy: $(cat "$FELLBACK_FILE")"; fi if [ -f "$FELLBACK_FILE" ]; then echo " fell back to legacy: $(cat "$FELLBACK_FILE")"; fi
if [ -x "$PROBATION_BIN" ]; then "$PROBATION_BIN" status 2>/dev/null | sed 's/^/ /' || true; fi if [ -x "$PROBATION_BIN" ]; then "$PROBATION_BIN" status 2>/dev/null | sed 's/^/ /' || true; fi
systemctl show -p ExecStart --value "$FLY_SERVICE" 2>/dev/null | sed -n 's/.*path=\([^ ;]*\).*/ flysim.service runs \1/p' || true systemctl show -p ExecStart --value "$FLY_SERVICE" 2>/dev/null | sed -n 's/.*path=\([^ ;]*\).*/ flysim.service runs \1/p' || true
exit 0 exit 0
;; ;;
session|legacy) ;; session|session-bus|legacy) ;;
fallback) fallback)
[ "$(id -u)" -eq 0 ] || die "run as root" [ "$(id -u)" -eq 0 ] || die "run as root"
do_fallback "${fallback_reason:-flysim.service failed on the session runtime (OnFailure=)}" do_fallback "${fallback_reason:-flysim.service failed on the session runtime (OnFailure=)}"
@ -372,6 +415,9 @@ esac
if [ "$command" = session ]; then if [ "$command" = session ]; then
[ -x "$SESSION_BIN" ] || die "this release has no ${SESSION_BIN}; the session runtime ships from SERVE-01 on" [ -x "$SESSION_BIN" ] || die "this release has no ${SESSION_BIN}; the session runtime ships from SERVE-01 on"
[ -x "$LEGACY_BIN" ] || die "no ${LEGACY_BIN}" [ -x "$LEGACY_BIN" ] || die "no ${LEGACY_BIN}"
if [ "$transport" = bus ] && [ ! -x "$WORKER_BIN" ]; then
die "this release has no ${WORKER_BIN}: the bus transport starts its participants from it"
fi
legacy_compat="$(compat_of "$LEGACY_BIN")" legacy_compat="$(compat_of "$LEGACY_BIN")"
session_compat="$(compat_of "$SESSION_BIN")" session_compat="$(compat_of "$SESSION_BIN")"
[ -n "$session_compat" ] || die "${SESSION_BIN} --print-compatibility printed nothing (see its stderr); not switching" [ -n "$session_compat" ] || die "${SESSION_BIN} --print-compatibility printed nothing (see its stderr); not switching"
@ -381,7 +427,7 @@ if [ "$command" = session ]; then
flysim-session: ${session_compat}" flysim-session: ${session_compat}"
fi fi
take_lock || die "another fly-runtime holds ${FLY_RUNTIME_LOCK}; not switching" take_lock || die "another fly-runtime holds ${FLY_RUNTIME_LOCK}; not switching"
before="$(current)" before="$(current_label)"
if [ -f "$DROPIN" ]; then if [ -f "$DROPIN" ]; then
prev_dropin="$(mktemp "${DROPIN}.prev.XXXXXX")" prev_dropin="$(mktemp "${DROPIN}.prev.XXXXXX")"
cp -f "$DROPIN" "$prev_dropin" cp -f "$DROPIN" "$prev_dropin"
@ -390,7 +436,7 @@ if [ "$command" = session ]; then
switching=1 switching=1
rm -f "$FELLBACK_FILE" rm -f "$FELLBACK_FILE"
write_dropin write_dropin
record "session (was ${before}); compatibility ${session_compat}" record "$(current_label) (was ${before}); compatibility ${session_compat}"
if [ "$restart" -ne 1 ]; then if [ "$restart" -ne 1 ]; then
systemctl daemon-reload systemctl daemon-reload
switching=0 switching=0
@ -438,7 +484,7 @@ fi
# legacy # legacy
take_lock || die "another fly-runtime holds ${FLY_RUNTIME_LOCK}; not switching" take_lock || die "another fly-runtime holds ${FLY_RUNTIME_LOCK}; not switching"
before="$(current)" before="$(current_label)"
switch_target=legacy switch_target=legacy
switching=1 switching=1
rm -f "$DROPIN" rm -f "$DROPIN"

View file

@ -12,7 +12,8 @@
# restart; --restart-flysim restarts it now), remove trace and spool # restart; --restart-flysim restarts it now), remove trace and spool
# fly-shadow-run status the verdict in one screen # fly-shadow-run status the verdict in one screen
# fly-shadow-run check CUT-01's hook: exit 0 only if the verdict allows the automatic cutover # fly-shadow-run check CUT-01's hook: exit 0 only if the verdict allows the automatic cutover
# into the release /opt/fly/current points to, onto flysim-session # into the release /opt/fly/current points to, onto flysim-session.
# --bus also requires that the shadow ran the bus topology (BUS-01)
# fly-shadow-run guard (flyshadow-guard.timer, every 60 s) stop everything and restart flysim # fly-shadow-run guard (flyshadow-guard.timer, every 60 s) stop everything and restart flysim
# without the trace if the live fly pays for the shadow # without the trace if the live fly pays for the shadow
# fly-shadow-run simulate BASELINE.jsonl CHECKS.jsonl the guard's rule over recorded samples # fly-shadow-run simulate BASELINE.jsonl CHECKS.jsonl the guard's rule over recorded samples
@ -53,6 +54,17 @@
# ActiveState inactive or failed (systemctl show), never activating: the shadow's 10-s crash-restart # ActiveState inactive or failed (systemctl show), never activating: the shadow's 10-s crash-restart
# delay must not switch the guard off. `check` also requires the guard timer active and baseline.json. # delay must not switch the guard off. `check` also requires the guard timer active and baseline.json.
# #
# THE BUS TOPOLOGY (BUS-01). `start --bus` runs the shadow's session the way `fly-runtime
# session --bus` runs the live one: the router, the coordinator and the task in the shadow's own
# process, the agent and the world as child processes (`fly-session legacy-agent`,
# `fly-session legacy-environment`, from the same release) on the router's Unix sockets. It sets
# FLY_SHADOW_MODE=bus/process in flyshadow.service's drop-in (mode.conf); a remote relay forwards it
# to the box (live.env), whose shadow reads it. The verdict records the topology
# (candidate.executionMode "process", candidate.transport "bus"), and `check --bus` refuses any
# verdict that did not run it. The live fly must run the LEGACY runtime while a shadow runs: only
# the legacy loop writes the trace (FLY_TRACE_DIR) the shadow follows, so `start` refuses while
# flysim.service runs the session runtime (fly-runtime status: session).
#
# REMOTE (SHADOW-02). With /etc/fly/shadow-remote.env present (the operator's private file: # REMOTE (SHADOW-02). With /etc/fly/shadow-remote.env present (the operator's private file:
# FLY_SHADOW_REMOTE=<user>@<box>, FLY_SHADOW_REMOTE_KEY, FLY_SHADOW_REMOTE_KNOWN_HOSTS, optional # FLY_SHADOW_REMOTE=<user>@<box>, FLY_SHADOW_REMOTE_KEY, FLY_SHADOW_REMOTE_KNOWN_HOSTS, optional
# FLY_SHADOW_REMOTE_PORT), `start` gives flyshadow.service a drop-in (remote.conf) that runs # FLY_SHADOW_REMOTE_PORT), `start` gives flyshadow.service a drop-in (remote.conf) that runs
@ -85,6 +97,8 @@ DROPIN="$DROPIN_DIR/shadow-trace.conf"
REMOTE_ENV="${FLY_SHADOW_REMOTE_ENV:-/etc/fly/shadow-remote.env}" REMOTE_ENV="${FLY_SHADOW_REMOTE_ENV:-/etc/fly/shadow-remote.env}"
REMOTE_DROPIN_DIR="${FLY_SHADOW_REMOTE_DROPIN_DIR:-/etc/systemd/system/flyshadow.service.d}" REMOTE_DROPIN_DIR="${FLY_SHADOW_REMOTE_DROPIN_DIR:-/etc/systemd/system/flyshadow.service.d}"
REMOTE_DROPIN="$REMOTE_DROPIN_DIR/remote.conf" REMOTE_DROPIN="$REMOTE_DROPIN_DIR/remote.conf"
MODE_DROPIN="$REMOTE_DROPIN_DIR/mode.conf"
RUNTIME_DROPIN="${FLY_RUNTIME_DROPIN:-$DROPIN_DIR/10-runtime.conf}"
# How long start waits for the first heartbeat (remote: at least 300 s, because the box's shadow # How long start waits for the first heartbeat (remote: at least 300 s, because the box's shadow
# restarts for the new run and the ingest hashes the release first). # restarts for the new run and the ingest hashes the release first).
HEARTBEAT_WAIT="${FLY_SHADOW_HEARTBEAT_WAIT_SECONDS:-60}" HEARTBEAT_WAIT="${FLY_SHADOW_HEARTBEAT_WAIT_SECONDS:-60}"
@ -275,14 +289,21 @@ check_remote() {
start() { start() {
need_root need_root
local mode=remote local mode=remote arm=""
for arg in "$@"; do for arg in "$@"; do
case "$arg" in case "$arg" in
--local) mode=local ;; --local) mode=local ;;
--bus) arm=bus/process ;;
*) die "start: unknown option $arg" ;; *) die "start: unknown option $arg" ;;
esac esac
done done
[ -x "$BIN" ] || die "$BIN is missing: this release predates SHADOW-01" [ -x "$BIN" ] || die "$BIN is missing: this release predates SHADOW-01"
# Only the legacy loop writes the trace the shadow follows (FLY_TRACE_DIR); the session runtime
# ignores it, and every process it ran would be a coverage divergence.
[ ! -f "$RUNTIME_DROPIN" ] || die "flysim.service runs the session runtime, which writes no trace for a shadow to follow. Switch the live fly to legacy for the shadow window first (fly-runtime legacy), then start the shadow"
if [ -n "$arm" ]; then
[ -x "$(dirname "$(readlink -f "$BIN")")/fly-session" ] || die "the bus topology needs fly-session beside $BIN"
fi
systemctl is-active --quiet flyshadow.service && die "flyshadow.service is already running" systemctl is-active --quiet flyshadow.service && die "flyshadow.service is already running"
if [ "$mode" = remote ]; then if [ "$mode" = remote ]; then
[ -f "$REMOTE_ENV" ] || die "no $REMOTE_ENV: the shadow runs on a build box (SHADOW-02; runbook). Pass --local to run it on this container instead, at the live fly's expense" [ -f "$REMOTE_ENV" ] || die "no $REMOTE_ENV: the shadow runs on a build box (SHADOW-02; runbook). Pass --local to run it on this container instead, at the live fly's expense"
@ -311,6 +332,17 @@ start() {
chown fly:fly "$SHADOW_DIR/baseline.json" "$samples" "$SHADOW_DIR/guard-state.json" chown fly:fly "$SHADOW_DIR/baseline.json" "$samples" "$SHADOW_DIR/guard-state.json"
log "baseline: $base" log "baseline: $base"
mkdir -p "$DROPIN_DIR" "$REMOTE_DROPIN_DIR" mkdir -p "$DROPIN_DIR" "$REMOTE_DROPIN_DIR"
if [ -n "$arm" ]; then
cat > "$MODE_DROPIN" <<EOF
# written by fly-shadow-run start --bus (BUS-01); removed by fly-shadow-run stop and by its guard.
# The shadow's session runs the bus topology; a remote relay forwards this to the box.
[Service]
Environment=FLY_SHADOW_MODE=$arm
EOF
log "the shadow runs the bus topology ($arm)"
else
rm -f "$MODE_DROPIN"
fi
if [ "$mode" = remote ]; then if [ "$mode" = remote ]; then
local run_id local run_id
run_id="$(date +%s%3N)" run_id="$(date +%s%3N)"
@ -360,7 +392,7 @@ EOF
stop_all() { stop_all() {
systemctl stop flyshadow-guard.timer 2>/dev/null || true systemctl stop flyshadow-guard.timer 2>/dev/null || true
systemctl stop flyshadow.service 2>/dev/null || true systemctl stop flyshadow.service 2>/dev/null || true
rm -f "$DROPIN" "$REMOTE_DROPIN" rm -f "$DROPIN" "$REMOTE_DROPIN" "$MODE_DROPIN"
systemctl daemon-reload systemctl daemon-reload
log "stopped the shadow: $1" log "stopped the shadow: $1"
} }
@ -476,6 +508,16 @@ PY
} }
check() { check() {
# `--bus` (BUS-01): the cutover goes onto the bus topology, so the shadow must have run it.
local -a pass=()
local arg
for arg in "$@"; do
case "$arg" in
--bus) pass+=(--require-arm bus/process) ;;
*) pass+=("$arg") ;;
esac
done
set -- "${pass[@]}"
# A tripped guard, a shadow that is not running, or a run that no guard watched never allows a # A tripped guard, a shadow that is not running, or a run that no guard watched never allows a
# cutover, whatever the verdict file says: the guard timer must be active and its baseline # cutover, whatever the verdict file says: the guard timer must be active and its baseline
# present (G1-a). # present (G1-a).

View file

@ -518,6 +518,26 @@ pct exec $CTID -- /opt/fly/bin/fly-runtime legacy # the one-command rollback
(flysim's limits, cpuset and environment; `Conflicts=flysim.service`; no `[Install]`, so it (flysim's limits, cpuset and environment; `Conflicts=flysim.service`; no `[Install]`, so it
cannot be enabled). It is for a rehearsal or a soak on a container whose `flysim.service` is cannot be enabled). It is for a rehearsal or a soak on a container whose `flysim.service` is
stopped, not for switching the stream. stopped, not for switching the stream.
- **The session on the bus (BUS-01).** `fly-runtime session --bus` (or `session-bus`) runs the
session's participants on the flybus router over Unix sockets: `flysim-session` (the router, the
coordinator, the listeners) starts `fly-session legacy-agent` and `fly-session legacy-environment`
as children of the same unit, in `flysim.slice`, on flysim's CPUs. The drop-in gains
`Environment=FLY_SESSION_TRANSPORT=bus`; `fly-runtime status` prints `session` and then
` transport: bus`. `fly-runtime session` without a flag (05-deploy's refresh) keeps the transport
the drop-in has; `fly-runtime session --local` goes back to the in-process lane, and
`fly-runtime legacy` to legacy. The fallback, the probation, the watchdog and the unstick rule's
restart are the same on either transport: one unit, restarted as a whole, children included
(`ps -o pid,args --ppid $(systemctl show -p MainPID --value flysim)` lists them). A deploy
refuses a release without `fly-session` while the drop-in says `bus`. **Before switching onto the
bus, run a shadow of it** (Shadow run below): with the live fly on legacy (`fly-runtime legacy`),
`fly-shadow-run start --bus`, three hours, then `fly-shadow-run check --bus && fly-runtime
session --bus`. Watch `fly_frame_work_mean_ms` and `fly_frame_work_p99_ms` on `/metrics` (the
loop's compute time per frame, without its pacing sleep, over the last 3,600 frames; the budget
at real time is 16.74 ms): they show the headroom that a realtime factor of 1.0 hides.
- **Per-frame compute time, both runtimes.** `/metrics` exports `fly_frame_work_mean_ms`,
`fly_frame_work_p99_ms`, `fly_frame_work_max_ms` and `fly_frame_work_frames` for the legacy loop
and the session runtime alike: everything one running iteration does except the pacing sleep.
Headroom is `1 - mean / 16.74` at real time.
## Shadow run (SHADOW-01) ## Shadow run (SHADOW-01)
@ -533,6 +553,12 @@ pct exec <ctid> -- /opt/fly/bin/fly-shadow-run check # CUT-01's hook: exit 0
pct exec <ctid> -- /opt/fly/bin/fly-shadow-run stop --restart-flysim # shadow, guard and trace off pct exec <ctid> -- /opt/fly/bin/fly-shadow-run stop --restart-flysim # shadow, guard and trace off
``` ```
- **A shadow of the bus topology (BUS-01).** `start --bus` runs the box's shadow session with its
agent and world as child processes on its router's sockets (`FLY_SHADOW_MODE=bus/process`, which
the relay forwards); `check --bus` also requires that the verdict ran that topology
(`candidate.transport` `bus`, `executionMode` `process`). The live fly must be on the legacy
runtime for any shadow: only the legacy loop writes the trace, and `start` refuses otherwise.
- **Where it runs (SHADOW-02).** On a build box, not on the release container: there it cost the - **Where it runs (SHADOW-02).** On a build box, not on the release container: there it cost the
live fly real time (2026-09-30: the realtime factor fell from 0.9998 to 0.93-0.98 and came back live fly real time (2026-09-30: the realtime factor fell from 0.9998 to 0.93-0.98 and came back
to 0.999-1.0 the moment the shadow stopped), and at about 27 ms a frame on shared CPUs it fell to 0.999-1.0 the moment the shadow stopped), and at about 27 ms a frame on shared CPUs it fell

View file

@ -735,7 +735,60 @@ rs_start "no remote file (the shadow runs on a build box; --local to override)"
rs_start "a remote file without its key" "FLY_SHADOW_REMOTE=user@box rs_start "a remote file without its key" "FLY_SHADOW_REMOTE=user@box
FLY_SHADOW_REMOTE_KEY=$cs_tmp/missing-key FLY_SHADOW_REMOTE_KEY=$cs_tmp/missing-key
FLY_SHADOW_REMOTE_KNOWN_HOSTS=$cs_tmp/missing-known" FLY_SHADOW_REMOTE_KNOWN_HOSTS=$cs_tmp/missing-known"
# BUS-01: only the legacy loop writes the trace, so `start` refuses while flysim.service runs the
# session runtime; `--bus` needs the release's fly-session worker beside fly-shadow.
bs_start() { # name, expect (refuse|proceed), runtime drop-in (yes|no), worker (yes|no), args...
local name="$1" expect="$2" rt="$3" worker="$4" rc=0 out
shift 4
: > "$cs_tmp/systemctl.log"
rm -f "$cs_tmp/10-runtime.conf" "$cs_tmp/fly-session"
[ "$rt" = yes ] && printf '[Service]\nExecStart=/opt/fly/current/flysim-session\n' > "$cs_tmp/10-runtime.conf"
[ "$worker" = yes ] && { printf '#!/bin/sh\nexit 0\n' > "$cs_tmp/fly-session"; chmod +x "$cs_tmp/fly-session"; }
out="$(PATH="$cs_tmp/bin:$PATH" CS_DIR="$cs_tmp" CS_SHADOW_CPUS="0 2" CS_SIM_CPUS="1 3" \
FLY_SHADOW_DIR="$cs_tmp/shadow" FLY_SHADOW_BIN="$cs_tmp/fly-shadow" \
FLY_SHADOW_CPUSET_DROPIN="$cs_tmp/dropin.conf" FLY_SHADOW_REMOTE_ENV="$cs_tmp/no-remote.env" \
FLY_SHADOW_REMOTE_DROPIN_DIR="$cs_tmp/flyshadow.d" FLY_RUNTIME_DROPIN="$cs_tmp/10-runtime.conf" \
FLY_SHADOW_BASELINE_SECONDS=30 FLY_METRICS_URL=http://127.0.0.1:1 \
"$INFRA_DIR/bin/fly-shadow-run" start "$@" 2>&1)" || rc=$?
case "$expect" in
refuse)
if [ "$rc" -ne 0 ] && ! grep -qE '^(start|restart|daemon-reload)' "$cs_tmp/systemctl.log" \
&& [ ! -e "$cs_tmp/flyshadow.d/mode.conf" ]; then
pass "fly-shadow-run start refuses, $name: ${out#fly-shadow-run: }"
else
fail "fly-shadow-run start must refuse and start nothing, $name (rc=$rc): $out"
fi ;;
proceed)
if echo "$out" | grep -q 'stub install reached'; then
pass "fly-shadow-run start proceeds, $name"
else
fail "fly-shadow-run start must proceed, $name (rc=$rc): $out"
fi ;;
esac
}
bs_start "the live fly on the session runtime (no trace to follow)" refuse yes yes --local
bs_start "--bus without fly-session in the release" refuse no no --local --bus
bs_start "--bus with fly-session, live on legacy" proceed no yes --local --bus
rm -rf "$cs_tmp" rm -rf "$cs_tmp"
# BUS-01: `check --bus` asks fly-shadow for a verdict that ran the bus topology.
if command -v python3 >/dev/null 2>&1; then
cb_tmp="$(mktemp -d "${TMPDIR:-/tmp}/fly-lint-checkbus.XXXXXX")"
mkdir -p "$cb_tmp/bin" "$cb_tmp/shadow"
printf '#!/bin/sh\ncase "$1" in is-active) exit 0 ;; esac\nexit 0\n' > "$cb_tmp/bin/systemctl"
printf '#!/bin/sh\necho "$*" > "%s/args"\n' "$cb_tmp" > "$cb_tmp/fly-shadow"
chmod +x "$cb_tmp/bin/systemctl" "$cb_tmp/fly-shadow"
printf '{"rtfMean":1,"rtfSd":0,"lagRate":0,"samples":60,"margin":0.05}\n' > "$cb_tmp/shadow/baseline.json"
printf '{"status":"pass"}\n' > "$cb_tmp/shadow/verdict.json"
PATH="$cb_tmp/bin:$PATH" FLY_SHADOW_DIR="$cb_tmp/shadow" FLY_SHADOW_BIN="$cb_tmp/fly-shadow" \
FLY_SHADOW_REMOTE_DROPIN_DIR="$cb_tmp/none.d" FLY_ENV_FILE="$cb_tmp/none.env" \
"$INFRA_DIR/bin/fly-shadow-run" check --bus >/dev/null 2>&1 || true
if grep -q -- '--binary flysim-session --require-arm bus/process$' "$cb_tmp/args" 2>/dev/null; then
pass "fly-shadow-run check --bus requires a verdict that ran bus/process (fly-shadow check --require-arm)"
else
fail "fly-shadow-run check --bus must pass --require-arm bus/process to fly-shadow check ($(cat "$cb_tmp/args" 2>/dev/null))"
fi
rm -rf "$cb_tmp"
fi
# SHADOW-02: `check` in remote mode also needs the relay healthy now (relay.json under a minute # SHADOW-02: `check` in remote mode also needs the relay healthy now (relay.json under a minute
# old), of this run (the drop-in's id, the verdict's too), without coverageLost (review B1: flysim # old), of this run (the drop-in's id, the verdict's too), without coverageLost (review B1: flysim
# stopped its trace for want of a consumer) and with a live trace written in the last 90 s. # stopped its trace for want of a consumer) and with a live trace written in the last 90 s.
@ -1005,6 +1058,50 @@ if fly_runtime && [ ! -f "$rt_dropin" ]; then
else else
fail "fly-runtime legacy must remove the drop-in and succeed" fail "fly-runtime legacy must remove the drop-in and succeed"
fi fi
# BUS-01: the bus transport. `session-bus` (= `session --bus`) adds FLY_SESSION_TRANSPORT=bus to
# the drop-in and needs the release's fly-session worker; a flag-less `session` (05-deploy's
# refresh) keeps the transport; `session --local` is the way back; status says which.
rt_status() { env RT_DIR="$rt_dir" PATH="$rt_dir/bin:$PATH" FLY_SYSTEMD_DIR="$rt_dir/systemd" bash "$INFRA_DIR/bin/fly-runtime" status 2>/dev/null; }
RT_ARGS=(session-bus)
if ! fly_runtime && [ ! -f "$rt_dropin" ]; then
pass "fly-runtime session-bus refuses a release without the fly-session worker"
else
fail "fly-runtime session-bus must refuse without \$FLY_RELEASE_DIR/fly-session and write nothing"
fi
printf '#!/usr/bin/env bash\nexit 0\n' > "$rt_dir/release/fly-session"
chmod +x "$rt_dir/release/fly-session"
if fly_runtime && grep -qx 'Environment=FLY_SESSION_TRANSPORT=bus' "$rt_dropin" \
&& grep -qx "ExecStart=$rt_dir/release/flysim-session" "$rt_dropin" \
&& grep -qx 'OnFailure=fly-runtime-fallback.service' "$rt_dropin" \
&& [ "$(rt_status | head -n1)" = session ] \
&& rt_status | grep -qx ' transport: bus' \
&& tail -n1 "$rt_dir/runtime.log" | grep -q 'session-bus (was legacy)'; then
pass "fly-runtime session-bus: the drop-in adds FLY_SESSION_TRANSPORT=bus (fallback and probation unchanged); status: session, transport bus"
else
fail "fly-runtime session-bus: drop-in/status/log wrong ($(tr '\n' ' ' < "$rt_dropin" 2>/dev/null); $(tail -n1 "$rt_dir/runtime.log"))"
fi
RT_ARGS=(session --no-restart)
if fly_runtime && grep -qx 'Environment=FLY_SESSION_TRANSPORT=bus' "$rt_dropin"; then
pass "fly-runtime session --no-restart (05-deploy's refresh) keeps the bus transport"
else
fail "fly-runtime session --no-restart must keep the drop-in's transport"
fi
RT_ARGS=(session --local)
if fly_runtime && [ -f "$rt_dropin" ] && ! grep -q 'FLY_SESSION_TRANSPORT' "$rt_dropin" \
&& rt_status | grep -qx ' transport: local' \
&& tail -n1 "$rt_dir/runtime.log" | grep -q 'session (was session-bus)'; then
pass "fly-runtime session --local takes the session off the bus (status: transport local)"
else
fail "fly-runtime session --local must drop FLY_SESSION_TRANSPORT from the drop-in"
fi
RT_ARGS=(legacy --bus)
if ! fly_runtime && [ -f "$rt_dropin" ]; then
pass "fly-runtime legacy --bus is refused (usage)"
else
fail "fly-runtime legacy --bus must be refused"
fi
rm -f "$rt_dir/release/fly-session"
RT_ARGS=(legacy); fly_runtime || fail "fly-runtime legacy after the bus tests failed"
RT_ARGS=(session) RT_ARGS=(session)
if ! fly_runtime RT_COMPAT_FLYSIM_SESSION=other && [ ! -f "$rt_dropin" ]; then if ! fly_runtime RT_COMPAT_FLYSIM_SESSION=other && [ ! -f "$rt_dropin" ]; then
pass "fly-runtime session refuses when the two compatibility strings differ" pass "fly-runtime session refuses when the two compatibility strings differ"