Skip to content

Feed bt-agent stdin so Bluetooth pairing authorization can be answered - #8929

Closed
x3m wants to merge 8 commits into
omacom:quattrofrom
x3m:fix/bt-agent-authorization-stdin
Closed

x3m wants to merge 8 commits into
omacom:quattrofrom
x3m:fix/bt-agent-authorization-stdin

Conversation

@x3m

@x3m x3m commented Aug 29, 2026 •

Copy link
Copy Markdown

What's wrong

default/systemd/user/bt-agent.service says -c NoInputNoOutput auto-accepts pair requests. It does not.

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 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.sh enables 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:

bluetoothd: profiles/deviceinfo/deviceinfo.c:read_pnpid_cb() Error reading PNP_ID value:
            Request attribute has encountered an unlikely error
bluetoothd: profiles/input/hog-lib.c:info_read_cb() HID Information read failed: ...
bt-agent:   Authorize this device pairing (yes/no)? Device: Logi M850 L (DB:D8:...)

Those ATT errors are insufficient-authentication surfacing: HID-over-GATT needs an encrypted link, which needs a bond that never formed.

The fix

Pipe yes into the agent, which is what actually makes it auto-accept — the behaviour the unit's Description and 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 pair completed immediately:

Paired: yes
Bonded: yes
Connected: yes

Only stdin differed between the two attempts.

Relationship to existing issues

Fixes #10771

Fixes #7879

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).
Copilot AI balanced review requested due to automatic review settings August 29, 2026 11:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 yes into 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-515 only starts discovery, and no repository code changes BlueZ's Pairable property. 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.
@x3m

x3m commented Aug 29, 2026

Copy link
Copy Markdown
Author

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:

  1. Nothing in the tree ever sets Pairable. grep -rniE 'pairable' across the repo returns exactly one hit: the comment in the unit I was editing. Panel.qml manages discovering, never pairable.
  2. Confirmed on a running install, panel closed: bluetoothctl show reports Pairable: yes.
  3. Bluetooth remains pairable after the Omarchy panel is closed #7889 is open and titled "Bluetooth remains pairable after the Omarchy panel is closed".

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 yes accepts every JustWorks RequestAuthorization on an adapter that is permanently open. Worst case is an unsolicited HID keyboard bond, which is arbitrary input injection.

Rather than document the hole, the new commit makes the guard real:

  • 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 — normal return, timeout expiry, or a signal. The trap is unconditional, so every invocation converges the adapter to non-pairable whatever the action; that also closes Bluetooth remains pairable after the Omarchy panel is closed #7889.
  • bt-agent.service gains ExecStartPost=-/usr/bin/timeout 5 /usr/bin/bluetoothctl pairable off, clearing it once at login for a session where that script has not run yet.
  • The unit comment now describes the guard that exists instead of one that did not.

I went with bounding the adapter state rather than your first suggestion of scoping acceptance to the requested device, because bt-agent registers a single global agent with no per-device hook — scoping it there would mean replacing the agent entirely, which is a much larger change than this bug warrants.

Tests: five new assertions in bluetooth-test.sh cover that pair opens the window, opens it before attempting the 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 wants an omarchy-pkgs checkout this environment lacks), verified by stashing.

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.
@x3m

x3m commented Aug 29, 2026

Copy link
Copy Markdown
Author

Correction to my previous comment: the ExecStartPost I described did not actually work, and I only caught it by testing on a live adapter instead of trusting the exit status. Fixed in c69d3ce.

The journal shows the race:

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 — before bt-agent registers with bluez — and registering the default agent leaves the adapter pairable. So the clear landed first and was undone immediately after. It reported success, the journal looked correct, and Pairable read true regardless. Running the identical command after registration sticks.

I measured with busctl rather than bluetoothctl to rule out the probe being the cause: adapter set pairable, unit started from inactive, property still true five seconds later. With a settle delay it goes false and stays false across repeated reads.

A fixed sleep is unlovely, but bt-agent gives no readiness signal (it isn't Type=notify), so there's nothing better to wait on. Happy to swap it for something else if you'd prefer — a bluetooth-pairable.service ordered After=, or dropping the ExecStartPost entirely and leaning only on the omarchy-bluetooth-device trap, which is the load-bearing half either way.

The new systemd-test.sh 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.


One unrelated observation while testing, not addressed here since it predates this PR: bt-agent ignores SIGTERM, so systemctl --user stop bt-agent hangs until TimeoutStopSec and the process is finally SIGKILLed. I verified the stock unit behaves identically with my drop-in removed, so it isn't introduced by the sh -c wrapper — but it does mean systemctl restart takes ~90s, which is worth knowing if you test this by hand. Might warrant its own issue.

x3m and others added 2 commits September 3, 2026 15:00
…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
@x3m

x3m commented Sep 3, 2026

Copy link
Copy Markdown
Author

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). connect returned at once with InProgress, because the trust a line earlier had already made BlueZ start connecting the device; the EXIT trap closed the window, and the kernel finished the handshake non-bondable: Paired: yes, Bonded: no. That pairing was gone at the keyboard's next disconnect. The K3 also ignores a host-initiated Pair() altogether (kernel: unexpected SMP command 0x0b) and only bonds through its own security request during connect, so the window has to outlast connect, not just pair. The script now waits on the device reporting Bonded: yes (bounded, 15s, OMARCHY_BLUETOOTH_BOND_WAIT_SECONDS for tests) before the trap closes it.

Unconditional trust built the reconnect loop (same commit). A device trusted without a bond is auto-connected by BlueZ and fails identically every ~4s — 33 uhid registrations and as many Authorize this device pairing prompts in one afternoon's journal — until the user forgets it. Trust now follows the bond, in pair and connect both.

The panel routed that stuck state to connect (b0e0e25). connectDevice treated trusted alone as connectable, and connect never opens the window, so from the panel the device could never heal. Trust alone now goes through pair.

Nine assertions cover the three: the bond is checked after connect and before the close; trust follows a bond and never a failed pair, on pair and on connect; and the panel condition is pinned to paired-or-bonded. Each new assertion was checked to fail against the previous commit. bluetooth-test.sh, bin-style-test.sh and systemd-test.sh pass. The full test/shell run has the same four failures with and without these commits (config-test and unowned-system-paths-test want an omarchy-pkgs checkout; snapper-test and theme-install-guards-test fail identically on the base).

@chessing234

Copy link
Copy Markdown
Contributor

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.

@omarchybot omarchybot added bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review labels Oct 1, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

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 RequestAuthorization the way bluetoothd asks it for a device-initiated Just Works pairing. Under quattro's bt-agent.service it answers Pairing rejected. Under this PR's unit it accepts. Putting quattro's unit back makes it reject again. bluez-tools' source agrees: in interactive mode, RequestAuthorization reads a yes/no from stdin and rejects anything else, and under systemd stdin is /dev/null. The worker has no radio, so pairing a real peripheral was not tested. That part rests on your M850 L and K3 results.

Tests on the worker. ./test/cli passes (116), as do bluetooth-test.sh (62), systemd-test.sh and bin-style-test.sh. The new assertions fail against quattro's versions of the three changed files, so they test the change. The branch merges cleanly into the current quattro.

Linked: #10771 (exactly the rejection reproduced above) and #7879 (trust before a bond, and the panel sending trusted-only devices to connect), so both close when this merges.

Competing fix, not a duplicate. #12897 fixes the same RequestAuthorization gap by replacing bt-agent with a new Python agent. A second fix by a different route is a competing fix, so this PR stays open. Choosing between them is the maintainer's call. The main difference: #12897's agent accepts only while an adapter is Pairable and keeps the adapter pairable while the panel is open. This PR keeps bluez-tools' agent, which accepts every authorization request, and relies on the adapter being non-pairable outside an explicit pair. That guard comes from the helper's EXIT trap. The login-time close depends on bt-agent registering within the 3-second sleep. #7880, #11198 and #13811 also change the same pair/trust lines in bin/omarchy-bluetooth-device, so whichever lands first will conflict with the rest.

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 ready, so it carries verified and nothing more.

Waiting on the maintainer: a second opinion on the next pass, and the choice between this and #12897.

@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed at b0e0e25. The branch no longer merges into quattro (d367a56). This time the second opinion ran, and it found a gap in the safety argument. The PR needs changes before it can go further.

The Pairable off guard does not stop the auto-accept. The PR relies on the adapter being non-pairable outside an explicit pair to make yes | bt-agent safe. In BlueZ, Pairable is the kernel's bondable flag, and a non-bondable adapter refuses only pairing requests that ask for bonding. In net/bluetooth/smp.c (v6.12, lines 1765-1767), smp_cmd_pairing_req returns SMP_PAIRING_NOTSUPP only when HCI_BONDABLE is clear and the remote set SMP_AUTH_BONDING. A non-bonding Just Works request passes that check and reaches user space as a confirmation (lines 887-893). bluetoothd asks the agent RequestAuthorization, the same call reproduced on the last pass, and with yes on stdin bt-agent accepts it. So with Pairable off, any device that can reach the adapter still gets a temporary encrypted pairing without the user doing anything. quattro rejects it today, though only because the prompt reads EOF. No over-the-air attack was attempted, and what such a session could then reach was not established. Other weak spots in the same guard:

  • ExecStartPost closes the window once, 3 seconds after spawn. An agent that registers later reopens it, and so does an adapter that appears after login, such as a USB dongle.
  • Bare bluetoothctl pairable off acts only on the default controller.
  • The EXIT trap also runs on connect, disconnect and forget. One of those can close a pairing window that another invocation opened for an active pair.

A fix tied to the request would hold where the window does not. #12897's agent checks Pairable on each request and rejects when it is off, and that part is worth adopting even if the rest of #12897 is not. Rejecting RequestAuthorization for any address other than the one being paired would close the gap entirely.

Smaller finding. bonded() matches *"Bonded: yes"* anywhere in bluetoothctl info, including a device's Name: or Alias: line. A device named that way gets trusted without a bond. Matching the property line itself, *$'\tBonded: yes'*, avoids this.

The conflict. It is in test/shell.d/systemd-test.sh. #16334 removed the tests that only read source text, the bt-agent unit greps among them, so the resolution is to take quattro's file. bluetooth-test.sh merges without a conflict but breaks: the new connectDevice block uses panelSource, which #16334 deleted, so that block has to go too. The tests that run omarchy-bluetooth-device against the mock still apply.

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 Model.js, which this PR leaves behind. #11198 raises Pairable around pair, as this PR does, but preserves a Pairable: yes it did not set, while this PR forces it off. Whichever lands, the others will conflict.

What was checked. I read the diff against current quattro and the bluez-tools agent source, made a trial merge, and checked the kernel SMP source. No worker ran this time: the head is unchanged since the 2026-10-01 reproduction, and there is no mergeable tree to test until the conflict is resolved. The second opinion came from Codex Medium and muse-wonder (thinking high). Codex raised the non-bonding gap, the default-controller limitation and the Bonded: yes match, and I checked the first against the kernel source as above. Both agreed that this PR is the oldest fix for the authorization bug and that no newer one is clearly better. That agreement is not guaranteed to be independent.

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.

omarchybot and others added 3 commits November 17, 2026 03:20
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>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Nov 17, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

I pushed three commits to this branch, so it now merges cleanly into quattro. The authorization gap from my last comment is still open, and that part is yours.

What I pushed:

  • 71f0599 merges quattro and resolves the conflict as my last comment described. test/shell.d/systemd-test.sh is now quattro's file, and the connectDevice block that read panelSource is gone from bluetooth-test.sh. The tests that run omarchy-bluetooth-device against the mock stay.
  • 7dff02d makes bonded() match the property line \tBonded: yes exactly, so a device named or aliased "Bonded: yes" is no longer trusted without a bond. There is a new test for it, which fails with the old predicate.
  • 9788a1a adds migrations/1794882048.sh, taken from @chessing234's Accept device-initiated Bluetooth Just Works pairing #12897 and credited to them. A package update replaces bt-agent.service on disk, but a running agent keeps the old ExecStart, stdin still /dev/null, until the next login. The migration reloads the user manager and restarts the agent where it is already active. On the worker, bt-agent ignored SIGTERM with both the stock unit and this one, so systemctl restart sat out the 90-second stop timeout. The migration therefore SIGKILLs the unit and then runs start. If Restart=on-failure brings it back first, on the reloaded unit, start has nothing left to do.

What was checked: On a disposable Omarchy VM with a virtual Bluetooth controller, I sent the agent RequestAuthorization over D-Bus. quattro's unit rejected it, this branch's unit accepted it, and quattro's rejected it again. With the stock agent running and the new unit on disk, the migration moved the agent onto yes | bt-agent in 3 seconds. Running it a second time also took 3 seconds. It left a stopped agent stopped, and it settled in 2 seconds when the auto-restart beat it. ./test/cli passed, and so did bluetooth-test.sh, systemd-test.sh, config-test.sh and the three tests that scan migrations. I did not run the full ./test/shell. Codex Medium and muse-wonder (thinking high) reviewed the three commits. They found nothing wrong in the merge or the predicate. In the migration, Codex found a race between Restart=on-failure and the explicit restart, and the switch to start comes from that. muse-wonder's concern that systemctl kill reaches only the main process does not hold: it signals the whole cgroup by default, and the worker journal shows exactly that. Both accepted the final version.

Still open, unchanged by these commits. Both reviewers confirmed this too. Pairable off does not stop a non-bonding LE Just Works request from reaching the yes-fed agent. ExecStartPost closes the window once, after a 3-second sleep. Bare bluetoothctl pairable off acts only on the default controller. The EXIT trap on connect, disconnect and forget can close another invocation's pairing window. Rejecting RequestAuthorization for any address other than the one being paired would close the first gap. That is a design change to this PR, so I have left it to you.

#11198, which also changes how Pairable is handled around pair, carries ready. Which approach ships is the maintainer's decision. Waiting on you for the authorization gate.

@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 0/5

[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

  1. P1 Security Unrelated devices get pairing approval ▶
  2. P1 Security Other radios stay pairable ▶
  3. P1 Actions close another pairing ▶
  4. P1 Security Stopped pairing stays open ▶
  5. P2 Delayed bonds lack test coverage ▶

Summary

The PR feeds automatic answers to the Bluetooth agent and changes pairing behavior:

  • Bluetooth pairing requests get an answer only during a pair window.
  • Bluetooth devices are trusted only after they form a bond.

Approval still reaches unrelated devices, and the pairing-window cleanup misses other controllers, termination signals, and overlapping actions.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[User selects device] --> B[Open adapter-wide pairing window]
  B --> C[Pair and connect selected address]
  C --> D[Wait for bond]
  D --> E[Trust only if bonded]
  E --> F[Close pairing window on exit]
  G[Nearby device requests pairing] --> H[Agent receives automatic yes]
  B -. Also permits .-> G
Loading

Reviews (1) · Last reviewed commit: "Restart a running bt-agent so the update..." · Reviewed by Greptile

# 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'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 security 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'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 security Other radios stay pairable

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Actions close another pairing

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 security Stopped pairing stays open

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 "$@" ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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!

@omarchybot

Copy link
Copy Markdown
Collaborator

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 yes agent, cleanup that reaches only the default controller, and the EXIT trap closing another invocation's pairing window. Both reviewers agree that 1 cannot be fixed by tuning the window. The agent has to approve only the address being paired. A second controller plugged in later also stays pairable, which a loop over bluetoothctl list would not cover. An address-aware agent would, so the same design change answers both.

4 does not hold. Bash runs an EXIT trap when it dies from an untrapped SIGTERM, SIGHUP or SIGINT. I tested this on bash 5.3 with a script shaped like this one, killed while it waited on a timeout child: the trap ran every time. Codex checked it separately and got the same result. muse-wonder disagreed, but the test settles it. You do not need extra signal handlers. Only SIGKILL skips the cleanup. Setting the adapter's PairableTimeout would bound that case, but it is optional hardening.

5 is a real test gap. Every bond test sets OMARCHY_BLUETOOTH_BOND_WAIT_SECONDS=0, and the mock always gives the same Bonded: answer, so the delayed bond that wait_for_bond exists for is never exercised. A mock that answers no and then yes from a state file, with a wait of 2 or more, would test that trust runs after the bond and pairable off comes last.

I pushed nothing this time, because the authorization change will rework this same code. Still waiting on you for that change. #11198 still carries ready.

@omarchybot

Copy link
Copy Markdown
Collaborator

Recommend: Don't merge — lost to #12897, which now fixes the same RequestAuthorization rejection (#10771, #9676) with an agent that accepts a pairing only for the device being paired; waiting on the maintainer to close this.

yes | bt-agent approves every device that asks, and bluez-tools' agent gives no way to limit that to the address the user picked, which is Greptile's open P1 here. The base has also moved: since #20332 the Bluetooth panel pairs through omarchy bluetooth pair, and nothing calls omarchy-bluetooth-device any more, so the pairing window this PR opens and closes there never opens from the panel, while the ExecStartPost still turns Pairable off at login. Two pieces of this PR carried over to #12897 with credit: the migration kills bt-agent instead of restarting it (stopping it waits out a 90-second timeout), and trusting a device only once it is bonded, with a wait for the bond after connecting. Thank you, @x3m, for the diagnosis and the K3 report that showed why the fallback to a device-started pairing matters.

Checked: reproduced the rejection on an Omarchy worker with two virtual Bluetooth controllers and real bluetoothd (stock bt-agent turns down a pairing the other side starts), and compared both PRs against current quattro. Reviewed by Claude Opus 5.5 and Codex XHigh, with muse-wonder via pi (thinking high) on the panel. Both chose #12897 over this PR; that agreement with each other and with me is not guaranteed to be independent.

omarchybot pushed a commit to chessing234/omarchy that referenced this pull request Dec 3, 2026
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>
omarchybot pushed a commit to chessing234/omarchy that referenced this pull request Dec 3, 2026
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>
@omarchybot

Copy link
Copy Markdown
Collaborator

Closing in favour of #12897, at the maintainer's request. Thanks, x3m: feeding bt-agent a yes answers every device that asks, which bluez-tools' agent gives no way to narrow to the one being paired, so #12897 replaces the agent instead. Two pieces of this pull request carried over there with credit: the migration stops bt-agent rather than waiting out its slow restart, and a device is trusted only once it has bonded.

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

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

4 participants