Skip to content

Certify cleanly stopped live recordings: seal, finish, replayed stop and close accounting - #26

Closed
erikwb wants to merge 4 commits into
aurora-silicon:integration/recording-ring-preservationfrom
erikwb:fix/replay-close-accounting
Closed

erikwb wants to merge 4 commits into
aurora-silicon:integration/recording-ring-preservationfrom
erikwb:fix/replay-close-accounting

Conversation

@erikwb

@erikwb erikwb commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Certification of a live recording could not pass: a recording the daemon made and ended with a clean stop was always refused. These four fixes make a clean live run certify. The live daemon's protection decisions don't change.

Found on a J713 running this integration branch (a9daa66) as its speaker protection, with the J713 profile from #10.

What was wrong, and the fixes

  1. The recording's last records could be lost (record: Let a clean stop wait for the last records). The disk worker writes and flushes its queue only once the queue closes, and nothing waited for it: the process could exit after a clean stop with records still queued.
    • New Recorder::finish(timeout) flushes, closes the queue and waits for the worker's result, at most 2 s. Only final_save calls it, after the state is written and the lock is released.
    • Dropping a recorder (a full queue, a failed rotation, in the governing tick) still never waits.
  2. A cleanly stopped ring recording read as cut short (record: Seal a live recording at a clean stop). A ring recording without a Z is treated as truncated, and only the size limit wrote one.
    • final_save now seals with Z and a new END_CLEAN code, and the reader ends there without marking the recording ambiguous.
    • END_FULL and an unsealed ring are still an early end, so a crash or kill leaves the file unsealed. Older readers see END_CLEAN as an early end, which is safe.
  3. The replay never ran the live clean stop (replay: Stop where the live daemon stopped cleanly). The stop's lock transition came out "live only" and its last span was cooled instead of charged.
    • When the recording has the live "stopping" permit, the replay stops there, ticks until released and runs the final save, as main does.
    • The final save's end comes from the daemon's own clock reads, so the replay advances to the live account's end first, within 100 ms.
    • A replayed stop isn't counted as a hand-off.
    • A clean stop while not armed records no permit; such a recording is sealed but still doesn't certify.
  4. Stream closes failed the account check (replay: Account a closing stream as the live daemon did). The live daemon charges a closing stream up to when it's done with it, which its own processing decides: 2–3 ms on the J713. The replay's clock didn't move meanwhile, so it charged a fraction of that and cooled the rest.
    • New Hw::closed_at(from) returns now() live, so nothing changes there. The replay takes the end of the span the live daemon charged from the guard's account_to, within 100 ms.
    • The replay now only ever moves forward to where live charged, so it charges more, never less.
    • read_tail also reads at its recorded time, as read_period does.

Tests

Each fix has a test, and each test fails with its fix reverted:

  • finishing_an_async_recorder_writes_everything;
  • a_clean_stop_seals_a_live_recording;
  • a_cleanly_stopped_live_recording_certifies;
  • a_slow_close_replays_as_the_live_daemon_charged_it, where the fake card gains a close_delay in its closed_at.

The seal and certification tests record through the synchronous ring recorder (Recorder::create). On the fake card a test outruns the async worker, whose full queue drops records. stalled_writer_drops_recording_without_delaying_governing still passes.

cargo test --release:

passed failed ignored
this branch 335 2 1
a9daa66 331 2 1

The same 2 fail on both (j616_ordinary_quiet_programme_has_zero_extra_attenuation, ordinary_quiet_programme_costs_at_most_one_db).

On the J713

A live run with this build as the J713's protection and #10's profile: three silent streams, a chord, short blips, and blip pairs 90–150 ms apart, then a clean stop. Its replay:

guard: 1 unlocks, 0 hand-offs, 0 latches; 0.0 s of playback at the kernel's level
account against the live one: 0.0 ms the live daemon charged not charged here, 0.0 ms it measured cooled here; it ends at 52.262 s, here at 52.262 s
clipping: 0 periods clipped at full scale
ambiguous: 0 intervals, 0.000 s
equivalence with the live run: lock 2 matched, 0 live only, 0 replay only; latch 0 matched, 0 live only, 0 replay only
certification: the recording is complete and the replay matches the live decisions

The recording is j713-certified.rec.zst (5.0 MB; decompressed SHA-256 ba4167cc7e539ab1929f2b9ab7962cd3eb458195a6aafb5785ee93e77b10f148), test sounds only. Replay it with --model j713 and #10's j713.conf.

That run also has clean sense data at its stream ends thanks to a kernel fix, aurora-silicon/linux#663. Without it, the J713's right tweeter voltage sense reads full scale for a moment at every stream stop, which shows up here as clipped, ambiguous periods.

The live daemon records through a disk worker thread, which writes and
flushes its queue only once the queue closes. Nothing waited for it:
after a clean stop the daemon returned from main and the process could
end with records still queued or buffered, cutting the recording's last
record and the account spans of the stop.

Add Recorder::finish(): flush, close the queue and wait for the worker,
at most a timeout. The final save calls it, with 2 s. Only the clean
stop waits; dropping a recorder (on a full queue or a failed rotation,
in the governing tick) still never blocks.

Signed-off-by: Erik Bourget <erik@ebourget.net>
A ring recording, the kind the live daemon writes, that ends without a
Z record reads as cut short: replay marks "the recording stopped here"
and refuses to certify it. Only the size limit wrote a Z, so a recording
the daemon ended with a clean stop could never certify.

Seal it: once the final save has written the state, the recorder writes
a Z with a new END_CLEAN code. The reader ends a recording at a clean
seal without marking it, and keeps treating END_FULL and an unsealed
ring as an early end. A crash or kill still leaves the file unsealed.
Older readers see the new code as an early end, which is safe.

Signed-off-by: Erik Bourget <erik@ebourget.net>
At a clean stop the live daemon gives the lock up, waits for the card
to drain, and charges its last span in the final save. The replay ran
the guard only to the end of the live account, so the stop's lock
transition was "live only" and its last span was cooled instead of
charged, and certification failed on every cleanly stopped recording.

When the recording holds the live "stopping" permit, wake there, stop
the replayed guard, tick until it is released, and run the final save,
as the daemon's main loop does. The final save's end comes from the
daemon's own clock reads, which a replay cannot reproduce; advance to
the live account's end first, within 100 ms. A replayed stop gives the
lock up too, but is not counted as a hand-off.

A clean stop while not armed records no "stopping" permit: such a
recording is sealed but still does not certify.

Signed-off-by: Erik Bourget <erik@ebourget.net>
At a stream's end the live daemon reads the tail, places it, and
charges the time after it up to when it is done, which its own
processing decides (about 2 to 3 ms on a J713). The replay's clock does
not move meanwhile, so it charged a fraction of that span and cooled
the rest from its next look: every recording with a stream close
failed the account check.

Add Hw::closed_at(from), the time up to which a closing stream is
charged from where its account had reached. Live it is now(), as
before. The replay takes the end of the span the live daemon charged
from there (its account records it), within 100 ms.
Also read a tail at its recorded time, as read_period does with a
period, and carry the capture position across the difference.

The fake card gains a close_delay: time that passes in closed_at(), as
the daemon's own processing does before it charges a closing stream.

Signed-off-by: Erik Bourget <erik@ebourget.net>
@RyanTheTide

Copy link
Copy Markdown
Contributor

The base branch integration/recording-ring-preservation is in neither main nor v2 (its PR, #25, was closed unmerged), and src/record.rs exists on neither branch. To merge this, it needs retargeting onto v2 with the recording code it depends on.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@erikwb this targets integration/recording-ring-preservation, which was never merged, and v2 has no src/record.rs. Do you plan to port the recorder and these fixes to v2? If not, we will close this and keep the branch for reference.

@erikwb

erikwb commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

No plans to port the recorder to v2, so closing this. The branch stays for reference.

@erikwb erikwb closed this Nov 19, 2026
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.

2 participants