Repository navigation
Conversation
The unit's `-c NoInputNoOutput` does not auto-accept on its own. For
JustWorks pairing bluez calls the agent's RequestAuthorization, and
bluez-tools' bt-agent implements that by prompting
Authorize this device pairing (yes/no)?
on stdin regardless of the capability it was started with. Under systemd
stdin is /dev/null, so nothing ever answers and every pairing times out.
Because this is the only pairing agent Omarchy ships (the Quickshell shell
registers none, and first-run/enable-user-units.sh enables this unit), no
BLE peripheral that needs JustWorks authorization can pair on a stock
install. The device is left trusted-but-unbonded, which then reconnects and
drops roughly once per second, filling the journal with
read_pnpid_cb() Error reading PNP_ID value: Request attribute has
encountered an unlikely error
hog-lib.c:info_read_cb() HID Information read failed: ...
Those ATT errors are insufficient-authentication surfacing: HID-over-GATT
needs an encrypted link, which needs a bond that never formed.
Piping `yes` into the agent is what makes it actually auto-accept, which is
what the unit already claims to do in its Description and comment.
Verified on Omarchy 4.0.1 with a Logitech M850 L (BLE HID): pairing failed
in a loop for minutes, then completed immediately with stdin fed. Only
stdin differed between the two attempts.
This is the root cause behind the failing first pair in omacom#7879; that issue
covers the aftermath (trusting an unbonded device and never retrying).
There was a problem hiding this comment.
Pull request overview
Feeds affirmative stdin responses to bt-agent so JustWorks Bluetooth pairing can complete under systemd.
Changes:
- Documents why capability selection alone does not authorize pairing.
- Pipes
yesinto the pairing agent.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Suppressed comments (1)
default/systemd/user/bt-agent.service:22
- This makes the global agent authorize every
RequestAuthorization, but the stated pairing-window guard does not exist:shell/plugins/panels/bluetooth/Panel.qml:512-515only starts discovery, and no repository code changes BlueZ'sPairableproperty. If the adapter remains pairable, an unsolicited device can therefore be accepted even when the panel is closed. Scope auto-acceptance to the explicitly requested device/pair operation, or explicitly bound and restore the adapter's pairable state.
ExecStart=/bin/sh -c 'yes | /usr/bin/bt-agent -c NoInputNoOutput'
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| # Safe because the adapter is only `pairable: true` when the user explicitly | ||
| # opens the omarchy bluetoothPanel and starts scanning; outside that window | ||
| # bluez refuses inbound pair attempts at a lower layer. | ||
| ExecStart=/bin/sh -c 'yes | /usr/bin/bt-agent -c NoInputNoOutput' |
The review is right: the safety rationale the unit carried was not true. Nothing in the tree ever set BlueZ's `Pairable` property - the only match for it in the repo was that comment - and bluez defaults it on, so the adapter sat permanently pairable (omacom#7889). Confirmed on a running install with the panel closed: `Pairable: yes`. That made the previous commit a regression rather than just a fix. The broken agent at least failed closed, never accepting anything; feeding it `yes` makes it accept every JustWorks RequestAuthorization, and on a permanently pairable adapter that is an unsolicited pair with no user action - a bonded HID keyboard being the worst case. So make the guard real instead of merely claiming it: - omarchy-bluetooth-device opens the window only around an explicit `pair`, and closes it from an EXIT trap, so it is restored on every path out including a `timeout` expiry or a signal. Because the trap is unconditional, every invocation converges the adapter to non-pairable whatever the action, which also fixes omacom#7889. - bt-agent gains an ExecStartPost that clears it once at login, covering a session where that script has not run yet. - The unit comment now describes the guard that exists rather than one that did not. Tests: five new assertions in bluetooth-test.sh cover that pair opens the window, opens it BEFORE attempting to pair, and closes it afterwards; and that connect never opens it yet still closes it. bluetooth-test.sh and systemd-test.sh pass. config-test.sh fails identically with and without this change - it needs an omarchy-pkgs checkout this environment lacks.
|
Good catch on the pairable state — the review is right, and I've pushed a fix in 4c8b11f. I verified the claim rather than taking it on faith, and it holds three ways:
So the rationale the unit carried was aspirational, and that made my first commit a regression rather than just a fix: the broken agent at least failed closed and never accepted anything, whereas piping Rather than document the hole, the new commit makes the guard real:
I went with bounding the adapter state rather than your first suggestion of scoping acceptance to the requested device, because Tests: five new assertions in |
The ExecStartPost added in the previous commit did not work. Testing it on a live adapter rather than trusting its exit status: Starting Bluetooth pairing agent (auto-accept)... timeout[...]: Changing pairable off succeeded sh[...]: Agent registered sh[...]: Default agent requested Started Bluetooth pairing agent (auto-accept). ExecStartPost runs as soon as ExecStart is SPAWNED, which is before bt-agent has registered with bluez, and registering the default agent leaves the adapter pairable. So the clear landed first and was undone a moment later: the command reported success, the journal looked right, and `Pairable` read true afterwards anyway. Measured with busctl rather than bluetoothctl, to be sure the probe was not itself the cause: adapter set pairable, unit started from inactive, property still true five seconds later. With the delay, it goes false and stays false across repeated reads. A fixed settle is unlovely, but bt-agent offers no readiness signal - it is not Type=notify - so there is nothing better to wait on. The systemd-test assertion guards the delay specifically, because losing it fails silently in the worst way: the unit still starts, the journal still says "succeeded", and the adapter quietly stays open to anyone in radio range.
|
Correction to my previous comment: the The journal shows the race:
I measured with A fixed sleep is unlovely, but The new One unrelated observation while testing, not addressed here since it predates this PR: |
…evice omarchy-bluetooth-device opened the window around `pair`, trusted the device unconditionally, and closed the window from the EXIT trap once `connect` returned. Both returns can precede the bond. Some peripherals ignore a host-initiated pair and bond only through their own security request once connected, so `pair` times out and the handshake happens during `connect`; and `connect` returns at once with InProgress when BlueZ is already connecting a device it knows - which a device trusted a line earlier is. Seen with a Keychron K3: the window closed mid-handshake, the kernel finished a non-bondable pairing, BlueZ reported `Paired: yes, Bonded: no`, and the keyboard was gone again at its next disconnect. The unconditional trust then made it worse: a device trusted without a bond is auto-connected by BlueZ and fails the same way every few seconds (33 reconnects in one afternoon's journal) until the user forgets it. So the script now waits on the device reporting `Bonded: yes` - bounded, 15s by default, OMARCHY_BLUETOOTH_BOND_WAIT_SECONDS for tests - before the trap closes the window, and trusts only once that bond exists. `connect` follows the same rule, trusting only a bonded device, so a known device that lost its bond cannot be trusted back into the loop. The mock bluetoothctl answers `info` with MOCK_BONDED, and the tests assert the bond is checked after connect and before the close, that trust follows the bond and never a failed pair, and that connect keeps to the same rule. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BumKJSYXPGgLZEYbzruhVU
connectDevice sent any device that was paired, bonded OR trusted to `connect`. Trusted alone is the one state that cannot be connected out of: a pair that failed after trusting, or a bond the peripheral has since dropped, leaves BlueZ auto-connecting the device and failing every few seconds, and `connect` never opens the pairing window that would let it bond. From the panel the device sat in "known", every press did nothing visible, and the journal kept filling. Only `pair` opens the window, so trust alone now routes there. The test pins the condition to paired-or-bonded and rejects trust in it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BumKJSYXPGgLZEYbzruhVU
|
Two more fixes pushed, from a real case that hit this exact flow on 2026-09-03: a Keychron K3 that had lost its bond after a suspend/resume. The window closed before the bond formed (7b4741e). Unconditional The panel routed that stuck state to Nine assertions cover the three: the bond is checked after |
|
heads up this is the same RequestAuthorization gap as #12897. that one's a replacement agent rather than feeding stdin — please close this as a duplicate of that. |
|
Reviewed at b0e0e25 and verified on a disposable Omarchy worker. The bug is real and this fixes it. Reproduction. bluetoothd and bt-agent ran on the worker, and bt-agent was asked Tests on the worker. Linked: #10771 (exactly the rejection reproduced above) and #7879 (trust before a bond, and the panel sending trusted-only devices to Competing fix, not a duplicate. #12897 fixes the same Second opinion: none. The configured reviewer, Codex Medium, answered a ping but could not run, because the day's review budget was already spent. This was reviewed by Claude Opus 5.5 alone. A review nobody else checked cannot be marked Waiting on the maintainer: a second opinion on the next pass, and the choice between this and #12897. |
|
Re-reviewed at b0e0e25. The branch no longer merges into The
A fix tied to the request would hold where the window does not. #12897's agent checks Smaller finding. The conflict. It is in Overlapping pull requests. Those that change the same lines are #7880, #10111, #11198, #12897 and #13811. Answering the agent's authorization prompt is this PR's alone among the older ones, and #12897 is a newer route to the same thing. #7880 also moves trusted-only devices out of the PAIRED group in What was checked. I read the diff against current Waiting on the author: resolve the conflict, and tie the auto-accept to the pairing the user started rather than to the adapter's bondable flag. The choice among the overlapping PRs is the maintainer's. |
Resolves the conflict in test/shell.d/systemd-test.sh by taking quattro's file: omacom#16334 removed the tests that only read unit source, the bt-agent greps among them. Drops the connectDevice block from bluetooth-test.sh for the same reason, since panelSource no longer exists there. The tests that run omarchy-bluetooth-device against the mock stay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bonded() matched "Bonded: yes" anywhere in bluetoothctl info, so a device named or aliased that way was trusted without a bond. Match the tab-indented property line exactly instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A package update replaces bt-agent.service on disk, but the agent already running keeps the old ExecStart, with stdin at /dev/null, until the next login. Reload the user manager and restart the agent only where it is already active. If the user manager is running but unreachable, exit non-zero so omarchy-migrate retries. bt-agent does not exit on SIGTERM, so systemctl restart sits in stop-sigterm until the user manager's 90 second stop timeout and holds omarchy update that long. The migration SIGKILLs the unit's cgroup and then starts it instead. Starting rather than restarting means that if Restart=on-failure brings the agent back first, on the reloaded unit, the start has nothing left to do instead of stopping the new agent through the same timeout. Folded in from omacom#12897. Co-Authored-By: Taksh <takshkothari09@gmail.com> Co-Authored-By: Codex Medium <noreply@openai.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I pushed three commits to this branch, so it now merges cleanly into What I pushed:
What was checked: On a disposable Omarchy VM with a virtual Bluetooth controller, I sent the agent Still open, unchanged by these commits. Both reviewers confirmed this too. #11198, which also changes how |
[Medium impact] The changes affect Bluetooth pairing and reconnection in user sessions. Do not merge until pairing approval is restricted and the pairing window stays correctly owned and reliably closed. Findings
SummaryThe PR feeds automatic answers to the Bluetooth agent and changes pairing behavior:
Approval still reaches unrelated devices, and the pairing-window cleanup misses other controllers, termination signals, and overlapping actions.
|
| # permanently (#7889). omarchy-bluetooth-device now opens the window only around | ||
| # `pair` and closes it on every exit path; ExecStartPost clears it once more at | ||
| # login, covering a session where that script has not run yet. | ||
| ExecStart=/bin/sh -c 'yes | /usr/bin/bt-agent -c NoInputNoOutput' |
There was a problem hiding this comment.
Unrelated devices get pairing approval
yes approves requests from every device, not just the address the user selected. While omarchy-bluetooth-device enables pairing on the adapter, a nearby device can request its own JustWorks pairing and receive approval without the user choosing it. Restrict approval to the selected address rather than treating the open window as consent for every device.
How this was verified: The pair action enables adapter-wide pairability, while the separate agent receives unconditional answers with no address check.
| # from the journal, where that line precedes "Agent registered", and by the | ||
| # adapter reading `Pairable: true` afterwards. Clearing it once registration has | ||
| # settled sticks. | ||
| ExecStartPost=-/bin/sh -c 'sleep 3; exec /usr/bin/timeout 5 /usr/bin/bluetoothctl pairable off' |
There was a problem hiding this comment.
ExecStartPost closes pairing only on the default controller. If a machine has both a built-in controller and a Bluetooth dongle, the other controller keeps BlueZ's default Pairable=true, but the new agent can approve requests on it too. The cleanup in omarchy-bluetooth-device also targets only the default controller. Close pairing on every controller, including controllers added later, before relying on this guard.
How this was verified: Both cleanup commands use bare bluetoothctl pairable off, while omarchy-bluetooth-power explicitly documents and handles Bluetooth commands reaching only the default controller.
| pairable_off() { | ||
| timeout 5s bluetoothctl pairable off >/dev/null 2>&1 || true | ||
| } | ||
| trap pairable_off EXIT |
There was a problem hiding this comment.
Every invocation closes the adapter's pairing window, even when another invocation still needs it. The panel launches helpers independently, so disconnecting an existing device while another device is pairing can run this trap before the new device sends its security request. That defeats the added wait for peripherals that bond after connecting. Coordinate ownership of the adapter-wide window so one action cannot close another action's window.
| pairable_off() { | ||
| timeout 5s bluetoothctl pairable off >/dev/null 2>&1 || true | ||
| } | ||
| trap pairable_off EXIT |
There was a problem hiding this comment.
trap pairable_off EXIT does not cover an unhandled SIGTERM. If the helper is terminated while the pairing window is open, Bash can die without running this cleanup. The adapter stays pairable while the agent keeps approving requests. Add explicit termination handlers that exit through cleanup, and give the window an independent expiry so an abruptly killed helper cannot leave it open indefinitely.
How this was verified: The helper opens pairability and installs only an EXIT trap; no termination handler or independent expiry closes the window.
| : >"$device_tmp/log" | ||
| PATH="$mock_bin:$ROOT/bin:$PATH" BLUETOOTHCTL_LOG="$device_tmp/log" \ | ||
| OMARCHY_BLUETOOTH_POWER_WAIT_SECONDS=0 "$@" || | ||
| OMARCHY_BLUETOOTH_POWER_WAIT_SECONDS=0 OMARCHY_BLUETOOTH_BOND_WAIT_SECONDS=0 "$@" || |
There was a problem hiding this comment.
Delayed bonds lack test coverage
Every new bond test sets OMARCHY_BLUETOOTH_BOND_WAIT_SECONDS=0, and the mock returns a fixed MOCK_BONDED value. None tests the delayed bond that wait_for_bond was added to support. Add a case that reports no bond first and a bond on a later probe, then checks that trust and window cleanup happen afterward.
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!
|
I checked Greptile's five findings on 9788a1a against the code. Codex Medium and muse-wonder (thinking high) checked them too. 1-3 are the gaps my last comment already listed as open. These are the address-blind 4 does not hold. Bash runs an 5 is a real test gap. Every bond test sets I pushed nothing this time, because the authorization change will rework this same code. Still waiting on you for that change. #11198 still carries |
|
Recommend: Don't merge — lost to #12897, which now fixes the same
Checked: reproduced the rejection on an Omarchy worker with two virtual Bluetooth controllers and real |
Gating the agent on an adapter's Pairable property tied consent to the Bluetooth panel being open rather than to a device: while it was open the agent accepted any device on that adapter, a marker left by a shell that died could renew the window, and `omarchy bluetooth pair` from a terminal with the panel closed could never take a pairing the device asks for itself. Since omacom#20332 the panel pairs through `omarchy bluetooth pair` too, so that command is where consent belongs. Consent is now per device. `omarchy bluetooth pair` records the address it is pairing, with an expiry, in $XDG_RUNTIME_DIR for as long as it runs, and the agent accepts a pairing request only for that address. A pair the host starts is accepted by BlueZ without asking the agent, so pair falls back to connecting and waiting for the device to pair when the host's pair is turned down; the reports in omacom#10771 (an Xbox controller) and omacom#8929 (a Keychron K3) bonded through a pairing the device asked for once connected. AuthorizeService is accepted only for paired devices, as bluez-tools' bt-agent did. Pairable is left to BlueZ. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bluez-tools' bt-agent ignores SIGTERM, so `systemctl --user restart` sat out the 90 second stop timeout inside `omarchy update`. Kill it and start the new agent; if Restart=on-failure gets there first, start has nothing to do. Taken from omacom#8929, where this was measured on a worker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Closing in favour of #12897, at the maintainer's request. Thanks, x3m: feeding |
What's wrong
default/systemd/user/bt-agent.servicesays-c NoInputNoOutputauto-accepts pair requests. It does not.For JustWorks pairing bluez calls the agent's
RequestAuthorization, and bluez-tools'bt-agentimplements that by promptingon stdin, regardless of the capability it was started with. Under systemd stdin is
/dev/null, so the prompt is never answered and every pairing times out.This is the only pairing agent Omarchy ships — the Quickshell shell registers none, and
install/user/first-run/enable-user-units.shenables this unit — so on a stock install no BLE peripheral that needs JustWorks authorization can pair.Symptom
The device is left trusted-but-unbonded, then reconnects and drops roughly once per second, filling the journal:
Those ATT errors are insufficient-authentication surfacing: HID-over-GATT needs an encrypted link, which needs a bond that never formed.
The fix
Pipe
yesinto the agent, which is what actually makes it auto-accept — the behaviour the unit'sDescriptionand comment already claim. The existing safety rationale is unchanged and kept in the comment.Verification
Omarchy 4.0.1, bluez 5.87, Logitech M850 L (BLE HID). Pairing failed in a loop for several minutes with the stock unit. With stdin fed,
bluetoothctl paircompleted immediately:Only stdin differed between the two attempts.
Relationship to existing issues
omarchy-bluetooth-device pairtrusts the address even when pairing failed, so the device is thereafter only ever connected, never re-paired. This PR removes the reason the first pair fails for BLE HID devices in the first place. The two are complementary — Bluetooth panel treats trusted-but-unbonded devices as paired and never retries pairing #7879 is still worth fixing on its own, since any other pair failure leads to the same trap.bluez-tools).Fixes #10771
Fixes #7879