Skip to content

Deploy tool: safe mode counts each start from its first moments - #340

Merged
robertnisipeanu merged 1 commit into
mainfrom
power-loss-safe-updates
Nov 19, 2026
Merged

robertnisipeanu merged 1 commit into
mainfrom
power-loss-safe-updates

Conversation

@robertnisipeanu

@robertnisipeanu robertnisipeanu commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

The deploy tool's safe mode counts every start of the head unit as failed from its first moments, so a head unit that keeps restarting soon after it starts ends up with our tools' units off, whatever ends each start, and the start after the third failed one already runs without them.

Why. Safe mode decided at the shutdown (var-opt-ro.service) whether a start failed, and counted only crash restarts within 2 minutes of the start. On an iDrive 7 test unit:

  • A program not on the crash handler's list that crashes 30 s into every start: the crash handler restarts the head unit about a minute and a half later, 118–144 s into each start. None of those starts counted, and the head unit restarted every 2–2½ minutes with no end (5 cycles watched).
  • A start that ends with no orderly shutdown (a power cut, a reset, a hang that is reset) runs no var-opt-ro.service and was never counted either.
  • An HMI that crashes 30 s into every start was caught, after 4 starts (the controller gate's and the page template's own guards took themselves out after 2).

What changes

  • safe_mode.sh start runs first at each start (the guard's ExecStartPre) and writes the start as failed (<before> <boot id> <before + 1>), on disk before it returns. What follows decides: a start up 5 minutes clears the count; the shutdown mark counts a restart recmgr or crashhandler asked for within 5 minutes; a shutdown without a restart record neither counts nor clears within 5 minutes and clears after; a restart our tools asked for clears. A start that ends with no mark keeps its count.
  • Three failed starts in a row turn safe mode on: at the third one's shutdown mark, or, when it ended without one, at the next start's first step.
  • Every tool unit that is off in safe mode gets After=mgu-deploy-safe-mode.service in its limits drop-in, so the flag that step writes holds in the same start: the controller gate's guard (no preload), the page template units, the renderers. On the test unit the step took about 0.25 s, and the template and gate units started right after it.
  • The guard's unit marks an orderly stop of the system (systemctl reboot, poweroff), which runs no var-opt-ro.service, as a shutdown without a restart record (ExecStop, Conflicts=shutdown.target).
  • boot (start, then the crash statistics baseline) stays for the guard unit an earlier deploy tool laid; the new unit runs start in ExecStartPre and the statistics read in ExecStart, so our units wait only for the count.
  • An install cut short between moving a tool's version folder aside (<version>.old-<pid>) and putting the new one in place gets the folder back where current points, at the deploy tool's next changing run. The aside was deleted as a stale file, which left current pointing at nothing.

Safe mode keeps the provisioning fallback and app-privacy's MainApp patch: they list the Store, whose Leave safe mode ends it, and MainApp failing does not restart the head unit (the app manager's supervisor starts it again).

AI: Claude Code, Claude Opus 5.5

Tested:

  • deploy/test/run.sh (Docker, unit code on Node 8.16.2): 1457 of 1462 pass. The 5 others are timing checks of the app manager bounce (testBounceGuard, testIdleWait, testInplace) that failed under host load; run again on their own they pass, 53 of 53, on this branch and on main alike.
  • iDrive 7 test unit, firmware P18_23w44.2-1-3, with the Store set as published on 2026-11-08 updated by Update all, the controller gate 1.2.1, the GPU renderer 2.1.19, Warm-Up and Maps on cluster 0.10.11:
    • The crash-handler loop above with this branch's deploy tool: three failed starts (118 s, 92 s, 132 s), then the fourth start ran in safe mode with the gate's guard, the page template units and the renderers skipped, no gate library in the HMI, the HMI up for good and root SSH answering.
    • systemctl reboot marked normal; no ordering cycles at any start.
    • Power cut (every head-unit process killed at once, as the unit's reset does) at 8 points of Update all from the 2026-11-08 set with the published tools: during app-privacy's MainApp patch, right after the deploy tool's own install, during mgu-render's unit and drop-in step, during its page-template step, during mgu-uplink's restart, during the updater's own install, 3 s after its handover to its new version, and inside the Store's in-place update by the app manager. Every next start came up with the HMI and root SSH, with no restart in the 3 minutes after, and Update all again finished. Where the cut left mgu-render's units half laid, the updater installed it again by itself at the next start.
    • With this branch's deploy tool installed first, the cut during app-privacy's patch: the next start counted it as one failed start (no safe mode), and the rest as above. The other cut points follow in a comment.
  • Not tested on a car.

Human review: No person reviewed this diff before it was opened.

Screenshots: n/a

🤖 Generated with Claude Code

Safe mode turns our tools' units off after three failed starts of the
head unit in a row, whatever ends each start, and the start after the
third already runs without them.

- safe_mode.sh's first step, at the very start of each start, counts the
  start as failed until it stays up 5 minutes or shuts down in order. A
  start that ends with no orderly shutdown at all (a power cut, a reset,
  a hang that is reset) counts, and so does a crash restart up to 5
  minutes in: the crash handler restarts the head unit about a minute and
  a half after a crash, so a program crashing early in every start ends
  each start some 2 to 3 minutes in.
- When the third failed start ends without a shutdown mark, the next
  start's first step writes the flag. Every tool unit that is off in safe
  mode starts after that step (its limits drop-in orders it after
  mgu-deploy-safe-mode.service).
- An orderly stop of the system (systemctl reboot or poweroff), which runs
  no var-opt-ro.service, counts as a shutdown without a restart record:
  the guard's unit marks it from its ExecStop.
- The count and the flag are on disk before the first step returns.
- An install cut short between moving a tool's version folder aside and
  putting the new one in place gets the folder back, where current points,
  at the deploy tool's next changing run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@robertnisipeanu
robertnisipeanu merged commit 31221fc into main Nov 19, 2026
1 check passed
@robertnisipeanu
robertnisipeanu deleted the power-loss-safe-updates branch November 19, 2026 12:40
@robertnisipeanu

Copy link
Copy Markdown
Owner Author

Released as mgu-deploy 0.8.26. The rest of the power-cut runs on the iDrive 7 test unit:

  • The same Update all with this branch's deploy tool installed first, cut at the same points: during app-privacy's patch, mgu-render's unit step, its page-template step, mgu-uplink's restart, the updater's own install, 3 s after its handover, and inside the Store's in-place update. Each next start came up with the HMI and root SSH, with no restart in the 3 minutes after. The cut counted as one failed start, no safe mode, and the count went back to zero once the start had been up 5 minutes. Update all again finished.
  • The whole unit losing power (writes not yet on disk lost) 40 s into three starts in a row: each start's count was on disk (1, 2, 3), and the fourth start ran in safe mode from its first step: the controller gate's guard, the page template units and the renderers skipped, no gate library in the HMI, the updater running, the HMI up and root SSH answering.
  • The whole unit losing power inside the Store's in-place update by the app manager, published tools: the next start kept the Store's earlier version, registered, and Update all again updated it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant