Repository navigation
Conversation
omarchy-restart-bluetooth has always summarised itself as "Unblock and
restart the bluetooth service", but it only ran rfkill unblock. That is the
right fix for a radio the user switched off and nothing else, so the menu's
Update > Hardware > Bluetooth action was a no-op for the two ways an adapter
actually goes missing.
A bluetoothd that lost sync with D-Bus adapter state needs the restart the
summary already promised: the shell's panel reads adapter as null and
toggleBluetooth() returns early, so the GUI cannot recover it either.
A controller whose firmware handshake timed out ("Reading Intel version
command failed (-110)") is worse. It leaves an hci device that BlueZ will
not adopt, and no amount of restarting the daemon clears it. Reloading btusb
re-runs the firmware upload, which is the only way back without a reboot.
So escalate: unblock, restart the service, and only if no controller answers
reload btusb. A radio that was merely soft-blocked never reaches the reload.
An adapter that stays dead now says so and exits non-zero instead of
finishing quietly.
Fixes omacom#13078
Fixes omacom#12519
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Automated AI review
Verified: in the single-adapter cases from #13078 and #12519, the escalation behaves as described, based on source reading and sandboxed runs with stubbed commands. The new test passes 7/7 on this head. Run against the previous script, it fails at
Four smaller points remain. A failed restart can still end in successThe status of Impact: for #13078, the desynced daemon may still list a controller. A cancelled or denied password prompt then reports success without the restart that fixes it. This undercuts the PR's aim that the menu action stops claiming success. Suggested change: branch on the restart's exit status, report the failure and exit nonzero before polling or reloading, as The restart now runs on every invocation, including a plain soft blockThe PR description says a soft-blocked radio "never goes further" than Impact: every use of Update > Hardware > Bluetooth now asks for a password and restarts bluetoothd, which briefly drops connected devices. Before this change, the soft-block case needed neither. An unconditional restart may be the intended trade-off: it matches the summary, and gating it on Suggested change: update the description to state that the restart is unconditional, or document the trade-off in the script comment. The "5s" window stretches when bluetoothd is not on the bus
This can happen when no Bluetooth stack is present: the unit's Impact: in those cases the menu terminal shows no further output for about 35 s (measured) to about 125 s (modeled) before the failure message, instead of the 5 s window the PR description states. Suggested change: use an elapsed-time deadline (for example Bash Failure hintDocumentation note: the message suggests Optional test improvement: the "busy module" case never makes Scope note: with two controllers, the reload happens only when neither is listed, so a wedged second USB adapter is not recovered while another controller works, and the script exits 0. A forced Review informationTest scope: pinned head AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments with targeted follow-up questions, Opus 5.5 Medium editorial check. Opt out: To stop receiving these reviews, reply to this comment saying so. |
Review of the first pass found four ways the escalation could still mislead. The restart's exit status was not checked. A password prompt the user cancels leaves a desynced daemon listing its controller, so the script printed that controller and exited 0 while the menu showed Done. That is the exact claim the change set out to remove. Branch on the restart and stop there. bluetooth.service carries ConditionPathIsDirectory=/sys/class/bluetooth, so a machine with no Bluetooth stack takes a clean exit from the restart without ever starting bluetoothd. Waiting for a controller then spent the whole budget on a daemon that was never meant to run, and a btusb reload could not help either. Confirm the daemon is active before polling. wait_for_controller counted polls, not seconds, and bluetoothctl waits indefinitely for bluetoothd, so each poll could spend its whole guard: the five second window became about 35 seconds of silent terminal, and about 125 with btusb loaded. Budget elapsed seconds and shorten the per-poll guard. The failure hint pointed at 'journalctl -b -u bluetooth' for an error that btintel emits through the kernel, where -u cannot match it, and suggested lsusb, which usbutils ships and Omarchy does not install. Point at -k instead. Also drop a comment that justified splitting the modprobe calls with a case that cannot happen: a failed unload leaves btusb loaded, so the reload was always a no-op there. Report the failed unload instead, and cover it with a stub that fails -r, which the previous suite never did. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Thanks — all four held up, and two of them I could confirm on the machine rather than by reading. Pushed in e1c1b1b. Restart status unchecked. The clearest one. Reproduced on real hardware without needing a wedged adapter: run it where sudo has no tty and the first pass printed the healthy controller and exited 0. It now exits 1 with Daemon absent. Added a Elapsed time. Failure hint. Confirmed both halves on a stock install: On the unconditional restart. Keeping it that way and documenting it, rather than gating on On the modprobe comment. You were right that the stated reason could not happen — a failed unload leaves The two-controller scope note I left alone, for the reason you give: a forced reload would drop every Not opting out — this was useful. |
|
I tested your solution and it works on my end. Thanks |
Automated AI review
Follow-up to the earlier review and the author's reply, checked at Verified: all five points from the earlier review are resolved on this head. The two-controller scope note is unchanged, as intended. None of the earlier points turned out wrong. The updated description matches the code: the flow diagram, the ten test names, the failure of the suite against the upstream script, and the mutation control (
The Two small points on the new code, plus two related notes. The restart-failure message can be inaccurateWhen the restart fails, the script prints Impact: on a failed restart, the message can say nothing changed while bluetoothd has been stopped. Suggested change: drop the second sentence, or replace it with the Optional test improvement: the assertion Related open PR: #13101 also adds a Related report, not verified: open issue #11936 (BlueZ 5.87) reports that after Review informationTest scope: pinned head AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check. Opt out: To stop receiving these reviews, reply to this comment saying so. |
A restart systemd started but could not finish has already stopped bluetoothd, so the old message was wrong on exactly the path where the daemon is now down. Point at systemctl status instead, matching the branch below it. The test that named this case could not fail: the sudo stub refuses every call, so no modprobe could ever be logged, and the case listed a controller, so the reload was unreachable anyway. Run it with nothing listed and count sudo instead. A mutant that keeps escalating after the failed restart and only exits 1 at the end passed the old suite 10/10 and now fails here. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Both held up again, and the bt-agent question turned out to be answerable on hardware. Pushed in 48d205c. The restart-failure message. Replaced the second sentence with the The assertion that could not fail. You were right that it was decorative, and for the reason you give — the sudo stub refuses every call, so no The mutant you described — keeps escalating, only exits 1 at the end — passes the previous suite 10/10 and fails this one at #11936 and bt-agent. Ran the check you specified. Your source reading was right and the stale agent does not happen on a clean restart:
#13101. Thanks for spotting it — it is the narrower fix for #13078 alone, opened about 90 minutes after this one. Happy either way if a maintainer prefers that shape; I have not touched the conflict, since resolving it depends on which lands first. Still open: a genuinely wedged AX200. I have no adapter that fails its firmware handshake, so the |
Automated AI review
Outcome: No new defects in
DetailsVerified: sudo refused and a failed restart job both print the neutral message. The PR suite passes 10/10 at Note, new related open PR: #13668 also changes #13101 correction: the previous review said any conflict resolution keeps #13101's unchecked restart lines. That is too strong: a resolver can delete them by hand. Picking this PR's side of both hunks does keep them. The bluetooth service then restarts twice per run, and this PR's suite fails at Suggested change: whichever PR lands second, delete #13101's unchecked restart lines when resolving the conflict, not only the marked hunks; this PR's suite catches a leftover restart. bt-agent: #11936's reporter saw the opposite (same PID, no re-registration), which remains unexplained. Open issue #13247 describes a related outcome of the same sequence. bt-agent's replacement starts 2 s after it exits, and its Optional notes:
Reproducer: sudo count in the denied-restart caseReproducer: the PR description's sudo count for the denied-restart caseStatus: PR description wording only (not a code defect). Reproduced at The PR description says the denied-restart case "asserts exactly one call — it is 1 when the script stops there and 3 when it reaches the reload". With sudo refused on every call (as that test case sets it up), a script that keeps escalating reaches ScriptSave as #!/bin/bash
# Count the sudo calls the PR's denied-restart case sees for the pinned script
# and for a "keeps escalating" mutant of it (the failed restart no longer exits;
# the script exits 1 only at the end). Uses the PR test's own stubs.
# Usage: repro-sudo-count.sh <omarchy checkout at the PR head>
set -euo pipefail
repo=$1
tmp_dir=$(mktemp -d)
trap 'rm -rf "$tmp_dir"' EXIT
mkdir -p "$tmp_dir/bin"
# Stubs copied from test/shell.d/restart-bluetooth-test.sh at 48d205c.
cat >"$tmp_dir/bin/rfkill" <<'STUB'
#!/bin/bash
printf 'rfkill %s\n' "$*" >>"$STUB_CALLS"
STUB
cat >"$tmp_dir/bin/sudo" <<'STUB'
#!/bin/bash
printf 'sudo %s\n' "$*" >>"$STUB_CALLS"
[[ $STUB_SUDO_FAILS == "yes" ]] && exit 1
exec "$@"
STUB
cat >"$tmp_dir/bin/systemctl" <<'STUB'
#!/bin/bash
printf 'systemctl %s\n' "$*" >>"$STUB_CALLS"
if [[ $1 == "is-active" ]]; then
[[ $STUB_DAEMON_ACTIVE == "yes" ]] && exit 0
exit 3
fi
[[ $1 == "restart" && $STUB_CONTROLLER_AFTER == "restart" ]] && touch "$STUB_STATE/controller"
exit 0
STUB
cat >"$tmp_dir/bin/modprobe" <<'STUB'
#!/bin/bash
printf 'modprobe %s\n' "$*" >>"$STUB_CALLS"
[[ $1 == "-r" && $STUB_UNLOAD_FAILS == "yes" ]] && exit 1
[[ $1 == "btusb" && $STUB_CONTROLLER_AFTER == "btusb" ]] && touch "$STUB_STATE/controller"
exit 0
STUB
cat >"$tmp_dir/bin/lsmod" <<'STUB'
#!/bin/bash
[[ $STUB_BTUSB_LOADED == "yes" ]] && echo "btusb 73728 0"
exit 0
STUB
cat >"$tmp_dir/bin/bluetoothctl" <<'STUB'
#!/bin/bash
printf 'bluetoothctl %s\n' "$*" >>"$STUB_CALLS"
if [[ $1 == "list" && -f $STUB_STATE/controller ]]; then
echo "Controller AA:BB:CC:DD:EE:FF omarchy [default]"
fi
exit 0
STUB
chmod +x "$tmp_dir"/bin/*
cp "$repo/bin/omarchy-restart-bluetooth" "$tmp_dir/pinned"
# Mutant: the failed restart sets a flag instead of exiting; exit 1 at the end.
sed -e '/^if ! sudo systemctl restart bluetooth.service; then$/,/^fi$/ s/^ exit 1$/ restart_failed=1/' \
"$tmp_dir/pinned" >"$tmp_dir/mutant"
printf '\nif [[ -n ${restart_failed:-} ]]; then exit 1; fi\n' >>"$tmp_dir/mutant"
chmod +x "$tmp_dir/pinned" "$tmp_dir/mutant"
echo "mutant diff:"
diff "$tmp_dir/pinned" "$tmp_dir/mutant" || true
run() { # script sudo_fails
rm -rf "$tmp_dir/state"; mkdir -p "$tmp_dir/state"; : >"$tmp_dir/calls"
local rc=0
STUB_STATE="$tmp_dir/state" STUB_CALLS="$tmp_dir/calls" STUB_CONTROLLER_AFTER=never \
STUB_BTUSB_LOADED=yes STUB_DAEMON_ACTIVE=yes STUB_SUDO_FAILS="$2" STUB_UNLOAD_FAILS=no \
OMARCHY_BLUETOOTH_RESTART_WAIT=1 OMARCHY_BLUETOOTH_RELOAD_WAIT=1 \
PATH="$tmp_dir/bin:$PATH" "$tmp_dir/$1" >/dev/null 2>&1 || rc=$?
printf '%-7s sudo_fails=%-3s exit=%s sudo_calls=%s: %s\n' "$1" "$2" "$rc" \
"$(grep -c '^sudo ' "$tmp_dir/calls" || true)" "$(grep '^sudo ' "$tmp_dir/calls" | paste -sd ';' -)"
}
run pinned yes
run mutant yes
run pinned no
run mutant noActual output (sandboxed run, all six commands stubbed)The Review informationTest scope: source, merge checks and sandbox tests with privileged commands stubbed, at AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check. Opt out: To stop receiving these reviews, reply to this comment saying so. |
The case only checked the message's prefix, so restoring the old second sentence, which claimed nothing had changed after a restart that may already have stopped bluetoothd, still passed 10/10. Match the full line; that mutant now fails here. The comment on the denied-restart case said escalating would ask for the password twice over. With sudo refused, the refused unload skips the load, so it asks once more, not twice.
[High impact] The PR appears safe to merge, with one non-blocking test gap from the previous review. Findings
SummaryThe PR makes
Reviews (3) · Last reviewed commit: "Print the controller listing that was ch..." · Reviewed by Greptile |
| cat >"$tmp_dir/bin/bluetoothctl" <<'STUB' | ||
| #!/bin/bash | ||
| printf 'bluetoothctl %s\n' "$*" >>"$STUB_CALLS" | ||
| if [[ $1 == "list" && -f $STUB_STATE/controller ]]; then | ||
| echo "Controller AA:BB:CC:DD:EE:FF omarchy [default]" | ||
| fi | ||
| exit 0 | ||
| STUB |
There was a problem hiding this comment.
The new tests never make bluetoothctl stall or check elapsed time. Removing the probe timeout or changing the wait back to a fixed number of polls would still pass these cases, despite breaking the bounded-wait behavior. Add a stalled-command case with an outer timeout and an elapsed-time check.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Every other bluetoothctl call here is guarded, because bluetoothctl waits indefinitely for a bluetoothd that is not on the bus. The status listing after the final probe was not, so a daemon that went away between the two left the menu's floating terminal hanging. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The status block probed for a controller and then listed again. If bluetoothd went away between the two, the second call came back empty with status 0, so the menu reported success with no controller in it. One bounded listing, checked and printed as is, closes the hang and the empty success together. The test now lets bluetoothd answer exactly the probes the script needs and requires the controller in the output, so a listing that hangs, times out or prints nothing all fail it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Codex Medium <noreply@openai.com>
|
Reviewed at What I pushed. The status block at the end checked for a controller and then ran Reproduced on a worker built from the Omarchy ISO, with real systemd, bluetoothd and kernel. The worker has no Bluetooth hardware, so a virtual controller was created through
A virtual controller that never answers setup leaves a zombie Not reproduced: the desync in #13078 itself, and the Tests, on the same worker. On a merge with current Second opinion: Codex Medium reviewed it in two rounds. In the first, it found the empty-listing case above and that the first version of the test only measured elapsed time; both are fixed in what I pushed. It also noted that a working second adapter satisfies the wait, so a wedged AX200 beside it is not reloaded. That is the gate you chose deliberately, because a forced reload drops every Competing fixes: #13101 and #13668 also fix #13078, in the same lines of this script. This one is the oldest and the only one that also covers #12519. Codex Medium, asked separately which should land, chose this one for the same reasons. Choosing between them is the maintainer's call. @codeface-io, could you try this exact commit the next time your AX200 wedges after a cold boot? It is the full head, curl -fsSL https://raw.githubusercontent.com/pedrohfp/omarchy/0971ad020e5c88b773d7c57ca058dad6c27821be/bin/omarchy-restart-bluetooth -o /tmp/omarchy-restart-bluetooth
bash /tmp/omarchy-restart-bluetoothIt should say This is waiting on that confirmation and on the maintainer's choice among the three pull requests. |
|
Compared the PRs for
#13085 is the one to merge: it closes both #13078 and #12519, checks a controller is back, and falls back to reloading |
|
Checked again at Classification is unsettled, so I took the Still owed here: #13101's review handed over one improvement to fold in. Nothing for you to do, @pedrohfp. This is waiting on the maintainer to settle the classification, and on the AX200 confirmation asked for above. |
|
Checked the CI failure recorded against On a disposable worker built from the Omarchy ISO, the current translation checks pass on both current On the unchanged PR head, Codex High checked the run metadata, source and worker results. Opus 5.5 High and muse-wonder via pi, thinking high, reviewed the follow-up and agreed that no CI defect requiring a code change was established; independence between these reviews is not guaranteed. Nothing was pushed and no GitHub job was rerun. This is waiting on the maintainer to decide how to handle the unexplained historical CI failure. The classification disagreement and AX200 confirmation remain as described above. |
Fixes #13078. Fixes #12519.
Problem
omarchy-restart-bluetoothsummarises itself as "Unblock and restart the bluetooth service", but the whole script was:It never restarted anything. That is the correct and complete fix for a radio the user switched off, and it is a no-op for the two ways an adapter actually goes missing:
hci0after a controller bounce).systemctl restart bluetoothrecovers it instantly. The shell panel cannot do it either —adapterisnull, sotoggleBluetooth()returns early — so Update → Hardware → Bluetooth was the user's only route, and it printedUnblocking bluetooth...and exited.8087:0029):Bluetooth: hci0: Reading Intel version command failed (-110). The controller stays inHCI_SETUPand is hidden from bluetoothd. Restarting the daemon cannot clear it; reloadingbtusbre-runs the firmware upload and the controller is back in ~1.4s.What changed
The restart is unconditional. A daemon that lost sync still lists its controller, so there is no reliable way to tell that case from a healthy one before restarting. Every invocation therefore asks for a password and briefly drops connected devices — that is the cost of the action doing what its summary promises.
Notes on the shape:
wait_for_controllerbudgets elapsed seconds, not polls.bluetoothctlwaits indefinitely for bluetoothd, so each probe carries its owntimeout; counting iterations would stretch the 5s window into ~35s of silent terminal when the daemon is absent.systemctl is-activegates the wait. The unit carriesConditionPathIsDirectory=/sys/class/bluetooth, so a machine with no Bluetooth stack takes a clean exit from the restart without ever starting bluetoothd — and abtusbreload cannot help there either.modprobe -rleavesbtusbloaded, so there is nothing to put back; the script reports that rather than running a reload that never came out.# omarchy:requires-sudo=true, matchingomarchy-restart-trackpad, which already doessudo modprobe -r. The menu runs this in a floating terminal, so the prompt has a tty.Verification
test/shell.d/restart-bluetooth-test.shis new. It stubsrfkill/sudo/systemctl/modprobe/lsmod/bluetoothctlonPATHand drives the escalation through its budgets in ~6s:restart bluetooth restarts bluetooth.service, so it pins the reported bug rather than the new code.sudo modprobe -r btusb && sudo modprobe btusbfails the suite, and so do a mutant that keeps escalating after a failed restart and only exits 1 at the end and one that restores the old second sentence of the restart-failure message. The stubs logsudo, so the denied-restart case asserts exactly one call — it is 1 when the script stops there and 2 when it goes on to the reload (the refusedmodprobe -rskips the load).bash test/shell.d/bin-style-test.sh,bash test/shell.d/command-operand-boundaries-test.shomarchy restartstill lists the command with its summary, so the added metadata parses.btusb, Intel controller08:6D:41:D0:57:C9, Bose QC35 on A2DP).bluetooth.servicerestarted cleanly —bluetoothdcame back on a new PID, re-registered every A2DP endpoint, and the headset reconnected on its own ~7s later.journalctl -kshows nothing frombtusb, confirming a controller that answers never reaches the reload.Could not restart bluetooth.serviceon a machine whose controller is perfectly healthy. The first pass printed that controller and exited 0.bt-agentafter the restart (Bluetooth agent stays stale after bluetoothd restarts #11936 asks whether a restart leaves the pairing agent registered but stale). It does not: bluetoothd sendsRelease, the agent'sUnregisterAgentfails withorg.freedesktop.DBus.Error.ServiceUnknown, it exits 1, andRestart=on-failurehas it registered again 2s later on a new PID.