Skip to content

provision: compile and wire the built-in microphone as the default input, apart from the speakers - #283

Merged
RyanTheTide merged 5 commits into
mainfrom
feat/mic-provision
Nov 28, 2026
Merged

RyanTheTide merged 5 commits into
mainfrom
feat/mic-provision

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

What: Wires the built-in microphone chain (#276, #277, #280) into speakerguardd v2's provisioning and session files. On a provisioned Mac whose microphone design compiles whole, the default input becomes the processed "Built-in Microphone" (the sgv2_mic plugin on the Mac's own tuning), and the raw array stays listed below it.

  • Provisioning (speakerguardd-provision run): a microphone step after the speaker steps, with its own blob, binding, record and graph directory.
    • It compiles the same bundle with mic-compile (never --allow-partial) into /var/lib/speakerguardd/mic.bin, bound in mic.bind to the board, the unit, the bundle digest, the compiler and the blob version the plugin takes. Any change compiles again, so a blob of an older version is never kept.
    • It writes the session files only when the blob's header names this board, the array's rate and microphone count and the plugin's version, carries no partial flag, and the packaged plugin runs it with health 0. Then the blob is published as /run/speakerguardd/mic.bin and the graph is written to /run/speakerguardd-graph/mic/.
    • Anything else removes the blob and the files and records why in mic.json (pass, absent or refused).
    • A Mac without a microphone array (Mac mini, Mac Studio) has no such step.
  • Session files (generated by gen.py, checked in per fixture with an array, written at runtime from the live device tree and card):
    • sgv2-mic-<m>.conf: the array's PCM as our own ALSA source (hw:CARD=<card>,DEV=<n>, "Microphone Array (raw channels)", priority 100) and the filter-chain that publishes "Built-in Microphone" (priority 2005, the value asahi-audio gives its microphone filter, so its headset rules still sit above it).
    • 61-sgv2-mic-<m>.conf: disables WirePlumber's own node for that PCM.
    • The seat user's graph unit links both files or neither.
  • With asahi-audio: its microphone filter is attached to WirePlumber's own node for the array (a node.software-dsp rule on api.alsa.path = "hw:<card>,<n>"). With that node disabled the filter is not created, and our node's path matches none of its rules. Without our files nothing is linked and its filter is exactly as today. The runtime generator in asahi-audio#30 matches the same path form, so it is covered the same way.
  • Where the array comes from: the device tree's AOP audio node that lists the array's stream (wiring.read_mic_dt, recorded in each fixture as mic), plus the audio block's compatible for the driver's fixed card suffix, PCM, channel count and rate (MIC_TRANSPORTS, like TRANSPORTS for the speakers). On a running Mac the PCM is found by its id on that card. No board list.
  • Self-check: speakerguardd-selfcheck mic gives the microphone verdict (header checks, then one silent block through the packaged plugin in a process of its own). verify reports it in a mic field beside the speakers' result, never as a step.

Failure modes:

case microphone verdict "Built-in Microphone" speakers
design compiles whole, plugin health 0 pass sgv2's processed source; raw array listed below it unchanged
compiler refuses, or the design would need a partial blob refused asahi-audio's filter, as before unchanged
blob for another board, rate, microphone count or version refused (after one fresh compile) asahi-audio's filter unchanged
packaged plugin missing or refuses the blob (health 1) refused asahi-audio's filter unchanged
no bundle, or not this Mac's refused asahi-audio's filter their own result
array in the device tree, no capture PCM on its card absent asahi-audio's filter unchanged
no array (Mac mini, Mac Studio) no step, nothing written n/a unchanged
speaker provisioning fails its own (can still pass) by the microphone verdict fail closed, as before
not the seat user, or a boot without provisioning n/a asahi-audio's filter as before
one of the two files or the published blob missing or different at session start n/a asahi-audio's filter (neither file is linked) unchanged
microphone goes from pass to refused while the seat user's session runs refused session restarted once onto asahi-audio's filter brief audio restart
files linked, filter-chain fails to load in PipeWire pass none; the raw array becomes the default input unchanged

Tested:

  • At 98bc160, x86 host, python3 -I: gen.py --check clean; test_wiring.py 116 pass (1 skipped as on main), test_session.py 61, test_provision.py 141 (29 new), test_verify.py 23 (1 new); packaging/upgrade/tests 82; tools/check-clean.sh clean.
  • New provisioning tests cover: microphone success (blob, binding, published copy, both files equal to the generator's); a refusal leaves every speaker file byte-identical; a design that would need --allow-partial is refused and the flag is never passed; a stale blob version compiles again; a bound blob is kept and each bound field recompiles; boards without an array run no step; no PCM is absent; a speaker failure does not stop the microphone; an exception in the microphone step does not change the exit status; a session links both files or neither.
  • Speaker path unchanged: no file under crates/, packaging/systemd, parity.json, gate.json, the session helper, the gate, or any sgv2-<m>.conf / 60-sgv2-<m>.conf differs from main. One test runs provisioning with and without a microphone node and compares the speaker blob, provision.bind, provision.json, speakerguardd.conf, the raw-PCM rules and the graph digest: identical.
  • Real plugin, x86 release build of this tree, with a blob from the real compiler (3 microphones, 48 kHz, version 2), device tree faked in a private mount namespace:
    • speakerguardd-selfcheck mic → pass, health 0, latency 1439 frames.
    • Other board, 44.1 kHz, the 2-channel variant, a garbage blob → health 1.
    • No plugin variant for the count → refused.
  • PipeWire 1.6.7, private instance on the build host with the generated sgv2-mic-j316.conf and the real plugin: the filter-chain loads and sgv2.mic.j316 appears as Audio/Source "Built-in Microphone", priority 2005. With no such card the raw node is not created and PipeWire still starts (nofail). All 16 generated files parse with spa-json-dump.
  • Fixture mic entries come from the kernel's device trees at aurora-silicon/linux main (deb2df2), compiled and read with wiring.read_mic_dtb: arrays on J293, J313, J316s, J413, J493, J616s, J700, J815; none on J274, J375c, J473, J474s, J475c.

Risk: two-way · on Macs where the microphone design compiles whole, the default input changes from asahi-audio's microphone filter to sgv2's processed source at the next session start. A plain revert (or removing mic.bin) returns asahi-audio's filter at the next session start. The speaker path is not changed.

Not yet:

  • No hardware row yet. A capture-only row on an M1 Pro (J316s) follows before merge: default source, raw source, a 20 s recording, restore. Do not merge before it.
  • Not proven on hardware: the PCM id lookup on the lab kernels, the two WirePlumber match forms for the array's node, and the PCM being free when the session's PipeWire creates the raw node.
  • The lid's "Internal Mic" jack state is not carried to our source (closed lid: listed but silent).
  • A microphone card that never registers costs provisioning its card wait (20 s) on that boot.
  • Designs the compiler still refuses (the blend unit of the newer Airs and the MacBook Neo) keep asahi-audio's filter until they are carried.

Each fixture now records its device tree's microphone array ("mic": the
enabled AOP audio node that lists the array's stream in dma-names, or
null on a Mac without one), read by wiring.read_mic_dt from the kernel's
device trees. wiring.describe_mic gives the array's card, capture PCM,
channel count and rate from that node and the audio block's compatible
(MIC_TRANSPORTS, the drivers' fixed layouts, like TRANSPORTS for the
speakers).

gen.py emits two files for every machine with an array:

- pipewire/sgv2-mic-<m>.conf: the array's PCM as an ALSA source of our
  own (hw:CARD=<card>,DEV=<n>, raw channels, priority 100) and a
  filter-chain around the sgv2_mic plugin that publishes the processed
  channel as "Built-in Microphone" (priority 2005, the priority
  asahi-audio gives its microphone filter).
- wireplumber/61-sgv2-mic-<m>.conf: WirePlumber's own node for that PCM
  is disabled. asahi-audio attaches its microphone filter to that node,
  so with both files linked there is one processed source, and without
  them asahi-audio's filter is unchanged.

wiring.py also gains the blob header reader (magic, lengths, CRC, the
bound board, rate, microphone count, version, partial flag) and a host
for the plugin's microphone variant that runs one silent block and
returns its health and latency outputs. Provisioning uses both.

The speaker files, the wiring derivation and its hash are unchanged.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…peakers

speakerguardd-provision run now has a microphone step after the speaker
steps. On a Mac whose device tree has a microphone array it compiles the
same bundle's microphone chain (mic-compile, never --allow-partial) into
/var/lib/speakerguardd/mic.bin, bound in mic.bind to the board, the
unit, the bundle's digest, the compiler and the blob version the plugin
takes; any change, or a blob whose header is not this Mac's, compiles
again, so a blob of an older version is never kept.

Only when the blob's header names this board, the array's rate and
microphone count and the plugin's version, carries no partial flag, and
the packaged plugin runs it with health 0 is the blob published
(/run/speakerguardd/mic.bin) and the microphone graph written to
/run/speakerguardd-graph/mic. The seat user's graph unit links both of
its files or neither. Anything else (a refusal, a partial design, no
microphone PCM, a plugin that refuses the blob) removes the blob and the
files, records why in mic.json (pass, absent or refused), and leaves the
distribution's microphone graph in use. A Mac without an array has no
such step.

The step runs after the speakers' records are written, keeps its own
blob, binding, record and graph directory, and cannot change the
speakers' result or the exit status. The speaker graph's digest, its
clearing and the sleep hook do not see the microphone files.

speakerguardd-selfcheck gains `mic`, the microphone's verdict (the
header checks and one silent block through the packaged plugin, in a
process of its own). `verify` reports it beside the speakers' result,
never as one of its steps.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide
RyanTheTide marked this pull request as ready for review November 27, 2026 19:47
@RyanTheTide
RyanTheTide requested review from a team as code owners November 27, 2026 19:47
@github-actions github-actions Bot added door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Merge readiness at f9086259: not ready yet

Check Detail
CI at head running running: policy, policy, pr-text / pr-text, Clean-publish check, selftest, Rust (ubuntu-24.04)
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok comment at f9086259
Conflicts ok none
PR text ok Risk: two-way · on Macs where the microphone design compiles whole, the default input changes from asahi-audio's microphone filter to sgv2's processed source at the next session start. A plain revert (or removing mic.bin) returns asahi-audio's filter at the next session start. The speaker path is not changed.

Areas: none matched in CODEOWNERS

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

graph-user installs the microphone links independently. If either filename is occupied by a user file or one symlink creation fails, the other link can still be installed, despite the stated both-or-neither contract. A lone WirePlumber rule can change the input graph without its processed source. Preflight the pair and roll back app-owned partial links on failure while preserving user files and speaker state. Add collision and second-link failure tests, then provide the live fallback row.

Review: graph-user linked the two microphone files independently, so a
file of the user's at one name, or a link that failed, could leave one
of them linked. A WirePlumber rule alone leaves no microphone; the
PipeWire file alone, two.

Check both names first; if either is taken by something that is not our
link, link neither and remove whichever half of ours is there. If making
the second link fails, remove the first. Only our own links are ever
removed: the user's files, the speaker graph and the raw rules stay as
they are.

New tests: a user file at either name leaves neither link and the file
untouched (and both come back once it is gone); a failing second link
removes the first. The speaker state is unchanged in both.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at 98bc160 addressed in 4edafdf. graph-user now links the microphone pair both-or-neither:

  • both names are preflighted first. If either is taken by anything that is not our link, neither is linked and any half of ours already there is removed;
  • if making the second link fails, the first is removed;
  • only our own links are ever removed. The user's files, the speaker graph and the raw rules are untouched.

New tests: a user file at either name leaves neither link and the file intact (both come back once it is gone), and a failing second link removes the first. The speaker state is unchanged in both. Results: test_provision 143 OK, test_wiring / test_verify / test_session OK, gen.py --check and check-clean OK.

Live row: still pending a decision (it needs a whole-tree bind of the speaker stack, or the package; see the lane notes).

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The pair is now preflighted before installation, and a failed creation removes matching app-owned links while preserving user files. The added fixtures cover collisions in both positions and the second-link failure while checking speaker state. Code approved. Hosted checks and the live fallback row remain pending.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

T6000 / J316s (M1 Pro), 4edafdf, PASS: capture-only row, nothing played.

Setup: Fedora 45, 7.3.0-aurora-fleet89, Enforcing. speakerguardd-v2 RPM built from this head with fedora-aurora's speakerguardd-v2.spec (0.62), installed over 0.53 by RPM upgrade, reboot. Restored to 0.53 afterwards.

  • Provisioning: mic pass, blob 3ac4c768 compiled from the Mac's own bundle (AID9): 3 mics, 48 kHz, latency 1439, blob v2, whole (no partial). speakerguardd-selfcheck mic: pass, plugin health 0. The PCM id lookup found the HPAI capture PCM (AppleJ316HPAI dev 0).
  • Session: default source = sgv2.mic.j316 "Built-in Microphone" (priority 2005, 1 ch 48k). Raw node sgv2.mic.raw.j316 "Microphone Array (raw channels)" (priority 100, 3 ch 48k) is listed. asahi-audio's j316-mic filter is not created. WirePlumber logs "ALSA node alsa_input.platform-sound.RawMics disabled". The headset mic stays at 2000.
  • WirePlumber match forms, each alone: api.alsa.path only disables the node and sgv2 stays default; alsa.id+alsa.device only does the same. Both together: the same.
  • PCM free: the raw node opened the PCM (3 ch FLOAT_LE 48000) with no busy error.
  • 20 s capture from the default source: 1 ch, 48000 Hz, 19.95 s, RMS -49.0 dBFS, peak -31.4 dBFS, 0 clipped, 0 xruns (pw-top ERR 0 on the raw, filter-in and source nodes). The raw node with an AUX0-2 map has 3 live channels at RMS -72.9 dBFS each.
  • Fallback: with the published blob removed and the session restarted, both mic links are removed and the default goes back to asahi-audio's effect_output.j316-mic. The WirePlumber RawMics node comes back, and a 20 s capture on it works (-36.7 dBFS RMS, 0 clipped). Putting the blob back makes sgv2 the default again.
  • Speakers: with mic pass, fallback and pass again, every speaker file is byte-identical (params.bin, provision.bind, provision.json, speakerguardd.conf, /run params, selfcheck.bind, graph state) and so are the amp volume/gain/switch controls. Across the package change, params.bin is identical to the 0.53 one (20e3dd77, recompiled to the same bytes). Protection was ready on every boot, NRestarts 0.
  • 0 AVCs (ausearch --input-logs), 0 failed units (system and user), 0 kernel audio warnings.
  • Package revert: on 0.53 the mic files and links are gone and asahi-audio's filter is the default again. Speaker blob, bind and graph files match the starting state, rpm -V is clean, and the default boot entry is unchanged with no next_entry.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

@aurora-silicon/core @aurora-silicon/omarchy-mac @DjDeveloperr: merge notice. App approval (adversarial) at 4edafdff, CI green, and the J316s (M1 Pro) row at the head is posted above: sgv2 processed mic is the default, the raw node opens the PCM, both WirePlumber match forms were tested separately, the 20 s capture had 0 xruns and 0 clipped samples, speaker state was byte-identical through pass/fallback/pass, 0 AVCs, and removing the blob brings back asahi-audio's filter. It merges after 07:44Z unless someone posts a blocking finding. Revert: git revert -m1 <merge> (the default input returns to asahi-audio's filter at the next session start).

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
The microphone tests need every fixture to say whether its Mac has an
array. The J873g (Mac mini, M6) fixture came in with #285 after this
branch was cut, so it had no "mic" key and test_wiring failed once
main was merged in.

Its AOP audio node at linux#3434 (23235970) lists dma-names
"cout cin spkr" with no microphone stream, and read_mic_dtb() on that
compiled t8152-j873g.dtb returns None. So "mic" is null, as on the
other desktop Macs.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merge-train note: #283 merged with current main fails test_wiring. Fixed on the branch, re-review needed.

Once #285 (J873g fixture) landed on main at 17:03, test_wiring.py failed at Microphones.test_shipped_files_are_the_fixtures_with_an_array ('mic' not found ... : j873). The new microphone test needs every fixture to carry "mic", and j873.json came in after this branch was cut. Each side passes on its own. Only the merge result fails.

Pushed, no force:

  • 6526880b merges main into feat/mic-provision, with no conflicts.
  • f9086259 adds "mic": null to packaging/session/fixtures/j873.json. Evidence: the J873g AOP audio node at linux#3434 head 23235970 (t8152-j873g.dtb compiled from it) has dma-names = "cout cin spkr", which has no microphone stream, and wiring.read_mic_dtb() on that DTB returns None.
Tested at f908625 (buildbox)
  • gen.py --check OK
  • test_wiring.py 116 run, OK (1 skipped)
  • test_session.py, test_provision.py, test_verify.py OK
  • packaging/upgrade/tests: 82 run, OK (1 skipped)
  • agent-policy.sh pr (merge ref): clean

The push dismissed the approval at 4edafdf. Re-review is needed at f908625. The delta is the main merge plus one fixture line. The J316s row at 4edafdf still covers the microphone code, because the delta only touches the j873 fixture and main's own changes.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at f908625 once required checks pass.

Checked: The forward merge brings in the J873g fixture and the only following commit adds mic: null. I traced J873g's exact DTS include: its enabled T8152 AOP audio lists cout, cin and spkr. The runtime microphone transport requires hpai, so the null fixture matches the device tree and keeps J873g out of the generated microphone graphs. The merge train reports exact wiring, session, provision, verify and upgrade suites passing.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Nov 28, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merge at f9086259 under the 6-point --admin rule

  1. App review: aurora-silicon-review (REVIEW6) re-APPROVED at f9086259 after the main merge and the j873 fixture fix. REVIEW6 also approved the code at 4edafdf.

  2. CI: hosted jobs at this head are still in the org Actions backlog. Run locally on a merge with current main f9727c48:

    • gen.py --check, test_wiring, test_session, test_provision, test_verify: all OK
    • packaging/upgrade/tests: OK (1 skipped)
    • aidgate/test_attest: OK
    • agent-policy.sh pr: clean
    • canonical pr-text.sh: OK

    The merge's Rust tree (crates/, Cargo.toml, Cargo.lock) is byte-identical to main, so the hosted Rust jobs would test main's own Rust. Also local: cargo fmt --check and clippy -D warnings OK on the merge. At 4edafdf, hosted Rust, Session and Clean-publish were all green.

  3. Hardware row: J316s microphone row PASS at 4edafdf (traces/audio/20261128-sgd283-j316s-mic-row). The delta since then is main plus one fixture line, j873.json "mic": null, verified against the linux#3434 DT.

  4. Not applicable (speakerguardd packaging/session).

  5. No open blocking review. The earlier App change request at 98bc160 is superseded.

  6. Code owners pinged at 06:41Z, more than an hour ago.

Revert: git revert -m1 <merge sha> (posted after the merge).

@RyanTheTide
RyanTheTide merged commit d9608fd into main Nov 28, 2026
12 of 13 checks passed
@RyanTheTide
RyanTheTide deleted the feat/mic-provision branch November 28, 2026 09:52
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merged as d9608fd. Revert: git revert -m1 d9608fde70.

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

Labels

door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant