Skip to content

Start each boot from evidence, not at the coils' limit (macOS-like start) - #28

Merged
RyanTheTide merged 3 commits into
fu-speakerguardd-rcfrom
feat/evidence-start
Oct 31, 2026
Merged

RyanTheTide merged 3 commits into
fu-speakerguardd-rcfrom
feat/evidence-start

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Draft, for the independent safety review before anything merges. Based on #27 (0.1.13-rc.1). The same change for the deployed Neo line is #29, and that is what was tested on the Neo.

Problem

Every boot started latched at the coils' hard limit, with the magnet bounded independently at 135 C. On the Neo the card stayed at the kernel safe level (or at its minimum) until about 33 s, then took the lock 12 dB down and released over about eight minutes (reports/neo-audio-quiet-20261031). macOS starts its model at the chassis ambient and plays at full level straight away.

Change

boot_resume = evidence is the new default. The first start of a boot (no state under /run, a record path given) starts every model node from the hottest a past can have left it, assuming only that every owner kept the coil at or under its hard limit T. The owners are this daemon, the kernel's safe level and another OS's own protection, which on these machines enforces the same hard limit from the same tuning.

  • Coil: T, then at least this boot's uptime at the card's safe level, for any time from there on.
  • Magnet: M* = (ta + r T) / (1 + r) with r = Rm / Rc. On the Neo that is 84.5 C, where the latched start assumed 135 C. From a saved magnet it rises toward M* no faster than the exact envelope allows.
  • A record under /var/lib/speakerguardd (a clean stop's, or a checkpoint written every 10 s from a thread off the protection loop) narrows the magnet by how long another owner can have had since. That time comes from an RTC that agreed with a synchronized system clock when the record was written and agrees with the system clock now.
  • Chassis sensors (SMC hwmon "Ambient" and "Chassis") can only raise a start.
  • A record of this very boot, latched, idle and --persist '' keep their existing behaviour. The unit gains no StateDirectory (DEFAULT_PREEXEC_FAILURE); the daemon makes the directory itself.

Every model starts this way: legacy, asahi, and unified FF and V/I.

Safety argument

  1. Magnet bound. In the two-node model, put Y = tau_m M - r tau_c C and eliminate P. Then Y' = ta + r (1 - e) C - (1 + r) Y / tau_m, with e = (1 + r) tau_c / tau_m (0.056 on the Neo; every profile needs e < 1, or the code falls back to the independent bound). While C <= T, Y relaxes toward Y* at least as fast as the formula says, whatever the power did. So M = (Y + r tau_c C) / tau_m <= (Y + r tau_c T) / tau_m, which at Y* is exactly M*. No sequence of bursts can pump the magnet past it. A randomized test drives the daemon's own discrete model with 300 adversarial programmes that hold the coil at its limit, and the magnet stays within 0.05 K of the bound. The code adds 1 K.
  2. Start. The coil is at T and the magnet at that bound when the last owner stopped. After that the card held its safe level: no daemon has unlocked it this boot, because the /run state is written before any unlock, a record from this boot latches, and the speakersafetyd flag latches. The two-node system is monotone, so the bound over all of [uptime, infinity) at the safe level's full-scale square-wave power covers the true state at every time this start can happen. A test checks every protected past against the start.
  3. Clocks. A clock can only make the start less narrow, never cooler. Cooling credit is the uptime alone. The RTC interval only limits how long another owner had to warm a cold saved magnet, and a fast or forward-jumping clock makes the start hotter. A backward jump, an RTC/system-clock disagreement at either end, or a record written unsynchronized gives no interval, which means the M* start.
  4. After the start, nothing changes. Hard limits, the latch at T, the floor, the onset reserve, the queue and reach rules, the kernel lease and the safe level on exit are all as in Reconcile main and the unified 0.1.13-rc.2 candidate; retain strict listening gates #27. A test plays 10 minutes of full-scale square wave from the no-record start, with truth stepped beside it from the worst protected past, and both stay under the limit.
  5. Assumption to review. Another OS must keep its coil under T. That is the same trust the whole design puts in Apple's constants. The latched start's independent 135 C magnet is reachable only if some past owner broke the hard limit.

Results

Path Host model, first lock
no record (M* start) 7.6 dB idle (onset reserve), releasing as the magnet cools
quick clean reboot 5.6 to 5.8 dB
latched, before 20 dB until 28 s, 10.7 dB at 60 s

On this RC the onset reserve (the full-dose FF reserve against the working limit) holds 4.0 dB even with cold speakers at idle. That is the existing failing ordinary_quiet_programme_costs_at_most_one_db gate, and it is now the main thing between the Neo and macOS-like loudness on 0.1.13. This PR does not change it. Pointing the reserve at the hard limit instead gained only 0.7 dB and reopened retained continuous counterexamples, so that was dropped.

Neo hardware results on the 0.1.12 line are in #29 and reports/neo-audio-quiet-20261031/MACOS-LIKE.md.

Tests

Buildbox, release: 384 passed, 2 failed, 3 ignored. The 2 failures are the two unchanged listening assertions that also fail on #27 (369 / 2 / 1 there). The 15 new tests are in src/boot.rs and src/guard/evidence_tests.rs. The tests that pin the latched or idle policies now name it explicitly.

🤖 Generated with Claude Code

Every boot started latched at the hard limit with an independent hot
magnet. On the Neo that held the card 20 dB down until about 33 s and
then released 12 dB over about eight minutes. macOS starts its model at
the chassis ambient and plays at full level at once.

boot_resume = evidence, the new default, starts the first run of a boot
(no state under /run, a record path given) from the hottest any past can
have left the speakers if every owner kept the coil at or under its hard
limit: this daemon, the kernel's safe level, or another OS's own
protection with the same limit. With the two-node model the magnet is
then bounded by M* = (ta + r T) / (1 + r), r = Rm/Rc, the magnet of a coil
held at its limit for ever (84.5 C on the Neo, where the latched start
assumed 135 C), and approaches it from a saved magnet no faster than the
exact envelope allows (boot.rs has the derivation). The coil starts at
the limit, and both nodes cool for at least this boot's uptime at the
card's safe level, any time from there on included. Every model (legacy,
asahi, unified FF and V/I) starts this way.

A record under /var/lib/speakerguardd, a clean stop's or a checkpoint
written off the protection loop every 10 s while running, narrows the
magnet by how long another owner can have had since, measured by an RTC
that agreed with a synchronized system clock when written and agrees
with the system clock now. Clocks that went back or disagree give no
narrowing, and no clock ever adds cooling credit beyond the uptime.
Chassis sensors (SMC hwmon) only raise a start. A record of this very
boot, latched, idle and --persist '' keep their existing behaviour. The
unit adds no StateDirectory: the daemon makes the directory itself.

Unit tests cover every start path: no record, a quick clean reboot, a hot
record and long gaps, a running checkpoint, clocks that went back or
disagree, corrupt, foreign and same-boot records, chassis sensors, the
latched opt-out, the magnet bound against random programmes on the
discrete model, and full scale from the worst protected past. Tests that
pin the latched or idle policies name it explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent safety review: changes required before merge. The full findings are on #29. The same code has the same hole here.

C1 (same as #29). invalidate falls back to removing the /run state when the write fails, and the /var/lib checkpoint is best-effort. A crash and restart within the same boot can then find neither file and take the evidence start with the full uptime credit. With the counterexample review_crash_restart_without_run_state_is_not_a_first_start on this head, the restart starts 33 K under the crashed model (coil 74.7 against 107.3 C). In that 60 s programme the truth stayed at 119 C thanks to the RC onset reserve, but the start invariant fails and the test fails. The fix is the same as on #29: no unlock unless the /run state was written, plus a never-removed /run boot marker that blocks the evidence start.

C2 (this PR only). The protected-past rule must hold for every model the daemon runs. On V/I profiles, each model (asahi, unified FF, V/I) starts at its own M*, which needs that model's coil to stay at or under T under the past drive. Past owners govern a different model: speakersafetyd governs the asahi model and macOS spp3 governs its OL model. The constants differ a lot. For example, the j413/j613/j713 rows have Rc 104.9 against 32.1 and Rm 129.5 to 200 against 20. So "the owner kept its coil under T" does not bound the other models. Do one of two things:

  • show a cross-model bound, or
  • default evidence only on profiles where the daemon and every other owner share one model (J700 lsm2 static, and atsp single-model machines once confirmed), and keep latched as the default elsewhere.

Every profile has e < 1. I checked all 34 conf/apple files, and the largest e is 0.146.

Two required items from the 2026-10-31 safety review.

C1. The evidence start took a missing /run state as proof that no
daemon had unlocked the card this boot. `invalidate` counted a removed
/run state as invalidated when the write failed, and the record under
/var/lib is best-effort, so a crash and restart in the same boot could
find neither file and credit the whole uptime as time at the safe level.
The review's counterexample restarted 33 K under the crashed model.

- With a record for the next boot configured, the run unlocks only once
  its /run state is written. A removal no longer counts.
- Before the first unlock of a boot, the run writes a marker next to the
  /run state (/run/speakerguardd/unlocked) with the boot id, durably,
  and never removes it. A start that finds this boot's marker, or one it
  cannot read, starts latched. If the marker cannot be written the lock
  is not taken.
- A macaudio override of the safe level (please_blow_up_my_speakers not
  0) also refuses the evidence start. speakersafetyd's flag already
  latches every start.

C2. The protected-past bound holds for the model a past owner governed.
speakersafetyd governs the asahi model and macOS on the V/I machines its
own, with constants up to three times apart, so neither bounds the
other models this daemon runs. `boot_resume = evidence` now takes effect
only where every owner governs one model (no V/I sense, the legacy
governor, no guard: the Neo). Anywhere else it starts latched and keeps
no evidence checkpoints.

Also a chassis sensor hotter than the model's ambient is now the ambient
of every bound (legacy, asahi, unified FF and V/I), not only a floor,
and boot.rs documents the two accepted residuals (an RTC set back by
another OS, and macOS's cold model start).

The review's counterexample is kept as a regression test (its first run
now unlocks normally; after the crash its /run state is lost and the
restart starts latched from the marker). New tests cover the literal
premise (both writes fail: never unlocks), the marker's write and
refusal cases, a marker that cannot be written, the override check, the
chassis ambient, one_model over every profile, and a V/I machine
starting latched under the evidence default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Safety review fixes are in ad14cbd. Please re-review. C1 is the same fix as #29 (2137581), and C2 is new here.

C1 (required).

  1. With a record for the next boot configured, invalidate unlocks only once save_now has written the /run state. The state_remove fallback no longer counts.
  2. Before the first unlock of a boot, the run durably writes /run/speakerguardd/unlocked with the boot id, and never removes it. If it cannot be written, the lock is not taken. A start that finds this boot's marker, or a marker it cannot read, or any marker when the boot id is unknown, starts latched. The unit already has RuntimeDirectoryPreserve=yes, so the marker survives restarts.
  3. review_crash_restart_without_run_state_is_not_a_first_start is kept as a regression test. The first run unlocks, plays a minute at full scale and crashes, then its /run state is deleted and the /var/lib record is blocked. The restart starts latched from the marker (coil 202.9 / magnet 136.2 against the crashed 107.3 / 77.0), and the truth peaks at 100.9 C. The literal premise (both writes fail) can no longer unlock and has its own test.

C2 (required). I took the restricted option. one_model(cfg) holds only with no V/I sense controls, the legacy governor and no guard. Of the 35 profiles that is only j700, and a test checks every file in conf/apple. Elsewhere boot_resume = evidence (still the parsed default) takes effect as latched: the start is latched, no evidence checkpoints are written, and the journal says why. The check runs on the final configuration, so --governor unified or --guard asahi on the Neo also turns it off. There is a test with j413 under the evidence default.

Recommended items.

  • R3: a chassis sensor hotter than the model's ambient is now the ambient of every bound (legacy, asahi, unified FF and V/I) and of the tail. The saved coil's lower bound in Y0 stays the model's own ambient.
  • R4: /sys/module/snd_soc_macaudio/parameters/please_blow_up_my_speakers refuses the evidence start if it cannot be read or reads anything but 0 or N. speakersafetyd's flag already latches every start here, and Neo 0.1.12 line: start each boot from evidence (tested on the Neo) #29 now checks it as well.
  • R5: boot.rs documents the first-start rule, the one-model rule and the two residuals (an RTC set back by another OS, and macOS's cold model start).

Tests. Buildbox, release: 394 passed, 2 failed, 3 ignored (384 before, plus 10 new). The 2 failures are the same unchanged listening gates that fail on #27 (ordinary_quiet_programme_costs_at_most_one_db and j616_ordinary_quiet_programme_has_zero_extra_attenuation).

🤖 Generated with Claude Code

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent safety re-review, round 2: APPROVE (at ad14cbd). The same two non-blocking notes as on #29 apply: the marker sits inside the RuntimeDirectory, and binaries should be swapped only across a reboot.

  • C1: the same fix as #29, verified the same way.
  • C2 is fixed. one_model is true for j700 only across all 35 profiles. Every other profile downgrades evidence to latched and spawns no checkpointer (a_vi_machine_starts_latched_under_evidence).
  • The chassis-ambient change is correct in assume_evidence for both the model and the engine: the saved coil's lower bound stays the model's ambient, so a sensor can only raise the start.

Suite on the buildbox (release), with my randomized crash/restart hunt appended: 395 passed, 2 failed, 3 ignored. The 2 failures are the pre-existing RC listening gates (ordinary_quiet_programme_costs_at_most_one_db and j616_ordinary_quiet_programme_has_zero_extra_attenuation), which also fail on #27. All the evidence, C1 and C2 tests and the hunt pass.

Round 2 of the safety review approved the evidence start with a
non-blocking note. The marker lived in /run/speakerguardd, so
`systemctl clean --what=runtime` or removing that directory took it
along with the state. It now sits beside the directory, at
/run/speakerguardd.unlocked (`boot::marker_path`). Nothing in the unit
manages that path, and the daemon still never removes it.

The README, the unit comment and boot.rs also say to replace the binary
only across a reboot (the review's second note). An older build without
the marker that ran earlier in the same boot can look like no daemon at
all.

New test: after an unlock and a crash, the whole runtime directory is
removed, and the next start of the boot still latches from the marker.
The test helper also clears a stale marker beside a reused directory.

Buildbox, release: 395 passed, 2 failed, 3 ignored. The 2 failures are
the unchanged listening gates that also fail on #27.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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