Skip to content

Skip the carrying restart hold after a clean idle exit - #263

Open
pjeweb wants to merge 234 commits into
osb/integrationfrom
osb/pr/carrying-hold-over-marker
Open

pjeweb wants to merge 234 commits into
osb/integrationfrom
osb/pr/carrying-hold-over-marker

Conversation

@pjeweb

@pjeweb pjeweb commented Nov 25, 2026

Copy link
Copy Markdown

This lets an idle box admit SSH and power actions right after a clean backend restart. Today every restart within a boot (a package install, a service restart) takes the two-minute carrying startup hold, so system.sshStart, reboot and power-off answer stream_liveness_unknown for two minutes even when nothing streams and no client traffic flows. Support enables SSH right after an install, so that wait lands exactly when it hurts.

What it adds:

  • Every backend start bumps a per-boot generation in /run/ceralive/carrying-generation.
  • The termination handler's first step, before any teardown, records that generation in /run/ceralive/carrying-idle-exit, but only when the box's whole stream liveness is idle (no stream, no unconfirmed session, no carrying evidence, no startup window of its own).
  • A restart skips the hold only when that record names the generation it replaces and the OTA streaming marker is absent. Everything else keeps the hold, as before.
  • The stream_liveness_unknown refusal now says which part is still being checked: client traffic (try again in a few minutes), or the box's own stream (try again, and use Stop Stream if it keeps refusing). Translated in all ten catalogs.

How: the hold stands in for client evidence an earlier process lost with its memory, so skipping it needs positive evidence that nothing was lost. I tried two weaker signals first and dropped both. A missing marker isn't enough, because a marker write can fail while protection holds. A record kept up to date during the run isn't enough either, because its removal can fail just as protection starts. A record written once at a clean idle exit and tied to that process's generation can't outlive it. So a crash or kill, an exit while anything is protected, a failed write, a damaged record, or a backend from before this change (the first upgrade to it) all keep the hold. The first start of a boot is unchanged.

Details and validation
  • carrying-runtime.ts: createCarryingRestartEvidence (generation bump past any recorded exit, idle-exit record, atomic writes), recordCarryingIdleExit, restartNeedsCarryingHold. initCarrying() reads the claim, the evidence and the marker before its own first publication.
  • shutdown.ts / main.ts: recordIdleExit runs once, first, and a failure there never blocks the shutdown. It reads getStreamLiveness(), the same value admission uses.
  • disruptive-action-refusal.ts: the text is chosen from the box's own session (getOwnStreamLiveness()). Stop Stream is offered only when that part is unconfirmed, so a phone-only power-off that waived the carrying window still names the right blocker.
  • Unchanged: an unreachable engine beside a stream's marker stays unknown; live and unknown streams keep their refusals; the phone-only power-off waiver is untouched.
  • Tests: carrying-restart-hold.test.ts replays restarts against real files in a scratch /run/ceralive, in production order (session at import, then carrying init, then reconciliation opening the latch). Cases: idle clean exit (admitted after the first sample and reconciliation), chained restarts, a crash after an earlier idle exit, an exit while a phone is carried, an exit beside a running engine session with no marker, an exit during the process's own first sample, a stream marker with an unreachable engine (still unknown after the hold), a read-only /run, damaged and lost records, and an unexaminable marker. carrying-restart-production.test.ts runs the real initCarrying(), tickCarrying(), getDisruptiveActionDecision(), refusal notice and exit record. carrying-idle-exit-shutdown.test.ts checks that the record is taken first and only once. With the old rule restored, 9 cases fail; with a marker-only rule, 7 fail.
  • On a device running the current build, an idle restart refused sshStart from 6 s to 117 s and accepted it at 127 s with no stream cycle, which is the hold on its own.
  • Docs: docs/CARRYING.md. Generated: support log vocabulary (one new error line) and the remote-status inventory hashes.

The train gates router admin probes and credential checks on the modem-control capability (canManageModems) instead of isRealDevice. Upstream's new USB router removal tests pass the old port.
Upstream's netdev lifetime reads presence, ifindex and the sysfs node itself, and a new MAC on the same index without a node witness is a new netdev. The first-sight fixture gains an opt-in indexed mode in which ip addr, the sysfs index and the node agree, used by the train's index cases; upstream's own cases keep the plain fixture. The realistic box gives each link the MAC of its device instead of its place in the scan. The IPv6 consumer cases start from fresh netdev lifetimes, and the periodic scan case waits for the scan after the one that retires the predecessor.
Upstream's uplink-health runtime compares each probe's sample with the name's netdev lifetime and forgets a retired name's published state. The train runs the same rounds in its runtime core, so the core takes the lifetime, the retirement subscription and the published-state hook through optional ports; the production adapter wires them to netdev-lifetime.
…their interfaces

Upstream's netdev lifetime retires a name when it leaves the snapshot, and the train holds a retired USB name for fresh identity. The CLAT one-bond-entry cases published their empty snapshot after resetting the scan state, so wwan0's hold and retired lifetime reached the next file in the same process. The resets now follow the empty snapshot.
…story

A retirement listener now receives the witness of the lifetime that ended, so a different live netdev under the name gets the replacement hold whether the poll, the monitor or a USB scan saw it first; a scan-first replacement of a non-USB name no longer reaches the identity deadline without positive evidence. A name whose USB descriptor was the only evidence at its first publication keeps its USB history, so its return after removal is held too. A MAC change on the same netdev is judged against the MAC that was published, so a superseded poll cannot swallow the local ingress token change. Tests cover each case, and the continuity case reads neither ip nor the sysfs index.
A retired USB Wi-Fi radio has no wireless sysfs left, so the retirement could not tell it from a USB modem and held it for a USB anchor that a radio without a serial or udev path never gets. A held name that is published again with wireless kernel evidence now leaves the hold: a Wi-Fi radio keeps its own lifetime. The unused sysfs ifindex reader is removed; netdev-lifetime reads the index.
The observer that saw a different netdev under a name now says so when it retires the name, and the retirement listener applies the replacement hold from that decision instead of a later read that can be unreadable or lack the evidence that showed the change. This covers a USB scan whose own first read was the only witness of the old netdev. A sample without a MAC no longer clears the published MAC, so the next MAC change still retires the local ingress token. Wireless sysfs releases a held radio only when the witness read on both sides of the lookup matches the netdev the publication validated.
… every observer

A partial witness counts as continuity not proven, never as no change. Two witnesses that share no kernel index or node are a different netdev, so a disjoint reading retires the lifetime instead of merging into it. A hold is released by wireless sysfs, a non-USB bus read or a scan anchor only when the reads around it positively continue the recorded netdev; only a name with no sysfs witness at all falls back to its presence epoch.

A change a poll sample saw is kept for the next completed sample, tied to the lifetime that sample read. A superseded sample observes nothing, and an observation whose lifetime was retired meanwhile is dropped, so an old poll cannot retire the successor a newer poll already published. A scan whose first read already differs from the recorded netdev retires it.

A confirmed replacement holds every name, Wi-Fi included, and a removed name last seen on USB is held whichever observer retired it, a monitor removal of a witness-less row too, without a name-only wireless lookup. A radio keeps its own lifetime when its successor is published with wireless evidence whose reads before and after the lookup continue the validated witness and each other, and the final read is compared with the recorded witness directly. A non-USB bus read releases a hold only when the witnesses read around it continue the row the poll sampled and the live netdev, so a successor a later scan recorded cannot vouch for an earlier read. A poll brackets every name with a row from before the address listing, so the listed index and a node read after the name changed cannot be fused into one witness.

The realistic box and the router removal fixture report the same sysfs index as ip, as a real host does.
…ght with the train

The launch-timeout Stop is handed to the independent-connection rollback of
the same attempt, so an attempt sends one Stop. After a lost control
connection, a session this process launched and retired is Stopped as its
own when fresh evidence shows it still streaming, so an armed marker
relaunches it; a restarted process still leaves it protected. The reload
check closes before the engine stop again. Start stays disabled while the
stream state is not confirmed, as upstream's preflight decides; the
unconfirmed-stream tests follow that. Upstream's hotspot switch tests use
the train's "Join Wi-Fi" label, the independent rollback Stop is expected
on its own connection, and the router-dongle copy test whose keys upstream
replaced is removed.
…rt to the band's Stop

The record that lets this process Stop a session it retired after losing the
control connection is written only for a generation this process admitted
a launch for, survives a Start refused as busy, and ends on an admitted Start
or a confirmed idle engine. The engine seam and session-boundary notes
describe that exception. While the stream state is not confirmed, the Start
bar says to stop the stream above first; Start stays disabled. The network
listing test mocks the train's streaming flag.
…with the train

Upstream's recovery snapshot test answers the train's switch-target
question for a legacy status socket, and its live engine restart harness
starts from a protected session, as the train's adoption rule decides at
boot. The install banner rests on the measured dock as upstream places it,
so the train's own offset above the dock and its two tests go.
…Settings

The record that lets this process Stop the session it retired after losing
the control connection now ends with the one-shot restoration window, so a
later heartbeat that finds a session streaming leaves it protected until an
explicit Stop. The schema-skew record is forgotten only when the engine
connection is lost. The Settings snapshots show the train's view with
upstream's row text: the Wi-Fi sign-in card first and device stats last.
The Stop the window guards runs only after the retirement, so a sender that
exits only at the kill timeout no longer uses up the window before the first
heal or restoration poll. The window runs on the monotonic clock.
A backend restart within a boot (a package install, a service restart)
took the two-minute carrying startup hold unconditionally. With the
engine idle and no client traffic, SSH and every power action answered
stream_liveness_unknown for two minutes after each restart, although the
earlier process had nothing to protect.

The earlier process publishes every protection it holds in the OTA
streaming marker, which /run/ceralive keeps across a restart: its stream
keeps the file, and so does its carrying. The hold now stands in only for
that: a restart takes it when the marker is present or cannot be
examined, and skips it when the marker is absent. The first start of a
boot still never takes it.

A refusal for unknown liveness now says the box is still checking, to
try again in a few minutes, and to use Stop Stream on the Live page if
it keeps refusing, instead of asking to wait for traffic to go idle.
…change

Only the reviewed source hash of carrying-runtime.ts changes; the published carrying fields are the same.
An absent OTA streaming marker is not evidence that the earlier process
held nothing: a marker write can fail while protection still holds, and a
crash between the sibling write and the rename leaves no marker.

Each process now writes /run/ceralive/carrying-idle only after it has
published confirmed idle and released its carrying marker, and withdraws
it before it publishes any protection. A restart skips the hold only when
that record exists and the marker is absent; a failed write, a crash
between the steps, an unexaminable marker or a backend from before the
record keeps it.

The unknown-liveness refusal now has two texts: client traffic still
being checked says to try again in a few minutes, and an unconfirmed
stream of the box's own also offers Stop Stream. Docs, the support log
vocabulary and the remote-status inventory follow.
A record kept current while the process runs cannot be trusted: on a
read-only or full /run its withdrawal can fail while protection starts,
and a crash then leaves stale idle evidence. A stream whose marker writes
failed also left the record standing beside no marker.

Every start now bumps a per-boot generation past any recorded exit, and
the termination handler's first step, before any teardown, writes that
generation to the idle-exit record only when the box's whole stream
liveness is idle. A restart waives the hold only when the record names
the generation it replaces and no marker is left. A crash, an exit while
anything was protected, a failed write, a damaged record or an older
backend all keep the hold, and nothing has to be withdrawn in time.

The unknown-liveness refusal now picks its text from the box's own
session, which is what admission sees whether or not it waived the
carrying startup hold for a phone-only power-off.
@pjeweb pjeweb added the fork-only Downstream-specific change; this change is not intended for upstream. label Nov 25, 2026
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8df913fb-0666-47cd-87d3-ba33bdaca642

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@pjeweb pjeweb added the in review In review or waiting for fixes; no train decision yet. label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork-only Downstream-specific change; this change is not intended for upstream. in review In review or waiting for fixes; no train decision yet.

Development

Successfully merging this pull request may close these issues.

1 participant