Skip to content

Keep the Bluetooth adapter pairable only while its panel is open - #14795

Open
kwsantiago wants to merge 1 commit into
omacom:quattrofrom
privkeyio:gate-bluetooth-pairable
Open

kwsantiago wants to merge 1 commit into
omacom:quattrofrom
privkeyio:gate-bluetooth-pairable

Conversation

@kwsantiago

@kwsantiago kwsantiago commented Oct 10, 2026 •

Copy link
Copy Markdown

bt-agent.service runs the pairing agent as NoInputNoOutput, which answers every incoming pairing request without asking. Its comment says this is safe because the adapter is only pairable while the Bluetooth panel is open and scanning. Nothing sets the adapter's Pairable property, and BlueZ brings every controller up pairable with no timeout, so that gate did not exist. What keeps unknown devices away today is that the adapter is not connectable or discoverable unless something makes it so; anything that does, such as bluetoothctl discoverable on to pair from a phone, opened a window in which a nearby device could bond with no prompt.

The panel now owns the property. PairableGate.qml writes Pairable on while its panel holds pairing and off otherwise: on open and close, when an adapter appears, and when BlueZ reports it changed behind the shell's back. quickshell applies the write locally at once, so the gate is event-driven with no retries; a Set that BlueZ refuses is not recovered, and the comment says so. Every controller gets a gate through an Instantiator over Bluetooth.adapters, not only the default one the panel shows. Per-monitor instances agree through one shared pairingHeld read over the bar's widget list, an instance being torn down drops its hold before its gate runs, and a gate replaced while its panel still holds leaves the write to its successor.

omarchy-bluetooth-device pair asks the shell over IPC to hold pairing for the length of the pairing (holdPairing and releasePairing, a counter with a 90 second safety timer), so closing the panel mid-pair cannot stop a Low Energy device from bonding, and pairs started from a terminal still bond. Without a shell to ask it sets the property itself and puts it back. The service comment now describes the real protection and its limits: the gate lives in the bar widget, so with the widget removed or the shell not running BlueZ's default stands.

bluetooth-pairable-gate-test.sh runs three gate instances on one fake adapter under the headless compositor and asserts exact write counts across open, close, a sibling holding, an external toggle, a late adapter, and teardown while held. bluetooth-test.sh gains checks for the panel wiring and the service comment, and mocks omarchy-shell and bluetoothctl for the hold, the no-shell fallback, an already pairable adapter, and connect.

Known limitations

The shell owns the live pairable state, so a few edges fall back to BlueZ's default rather than being handled, and all of them fail safe (pairing turns off, not on). A property write BlueZ refuses is not retried. With the widget removed from the bar or the shell not running, the adapter keeps BlueZ's default. If the shell restarts during a pairing started by omarchy-bluetooth-device while every panel is closed, the fresh shell starts with no holds and its gates turn pairing off before the command finishes, so a Low Energy device can pair without bonding; connecting it again repairs it. A durable cross-restart hold would close that last window at the cost of the shell reading command state off disk, which is more machinery than a defense-in-depth gate warrants.

@greptile-apps

greptile-apps Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Bluetooth adapter pairing control and device pairing flow.

Preserve active pairing holds across shell restarts before merging.

Findings

  1. P1 Restart interrupts pairing ▶

Summary

The PR makes Bluetooth adapters pairable while a panel is open or a pairing command holds permission.

  • Bluetooth adapters are pairable only while someone needs to pair.
  • Bluetooth pair commands keep the adapter pairable until pairing ends.

The four supplied previous threads are unnumbered and resolved. The monitor, overlapping-command, and blind-release findings have corresponding fixes. The fixture now also tests gate creation for multiple adapters. Those threads were manually resolved without explanatory replies.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Command[Pairing command] --> IPC{Shell answers?}
  IPC -->|Yes| Tokens[Hold token in shell]
  IPC -->|No| Lock[Shared fallback lock]
  Tokens --> Gates[Adapter gates]
  Panel[Open panel] --> Gates
  Gates --> Pairable[Adapter pairable]
  Lock --> Pairable
  Restart[Shell restart] --> Empty[New shell has no tokens]
  Empty --> Off[Closed panels turn pairing off]
  Command --> Detached[Pairing continues separately]
Loading

Reviews (4) · Last reviewed commit: "Keep the Bluetooth adapter pairable only..." · Reviewed by Greptile

Comment thread bin/omarchy-bluetooth-device Resolved
@kwsantiago
kwsantiago force-pushed the gate-bluetooth-pairable branch from 87fd302 to 6a66c8e Compare October 10, 2026 00:25
Comment thread bin/omarchy-bluetooth-device Resolved
@kwsantiago
kwsantiago force-pushed the gate-bluetooth-pairable branch from 6a66c8e to 12bccc5 Compare October 10, 2026 00:37
@kwsantiago
kwsantiago force-pushed the gate-bluetooth-pairable branch from 12bccc5 to 9c6a901 Compare October 10, 2026 01:05
Comment on lines +50 to +52
if pairing_token=$(omarchy-shell omarchy.bluetooth holdPairing 2>/dev/null) &&
[[ $pairing_token =~ ^[0-9a-f]{32}$ ]]; then
return

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 Restart interrupts pairing

After receiving a token, hold_pairing returns without keeping a hold outside the shell. If the shell restarts during pairing, the new BluetoothPairing starts with no tokens. With the panels closed, its gates turn pairing off even though the detached pairing command is still running. A Low Energy device can then fail to bond and be forgotten after disconnecting.

Keep command holds somewhere the replacement shell can read, or have the command renew its hold after a restart.

Knowledge Base Used: CLI command platform

@jandrusk

Copy link
Copy Markdown

This closes a real gap: bt-agent is NoInputNoOutput (auto-accept) while BlueZ brings adapters up pairable with no timeout, and nothing previously owned Pairable. Gating it to the panel open / omarchy-bluetooth-device pair hold is the right model, and the Instantiator-per-adapter + shared pairingHeld reading looks carefully thought through.

Ready for review from my side. Related product/security discussion still open around device-initiated Just Works in #12897 — worth keeping those two stories consistent.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for this. It got a first read, but not a full review yet, and nothing was run.

Each item's class (bug or enhancement) needs two models to agree before the rest of the review starts. Claude Opus 5.5 read the diff against quattro and classed it as a bug: the comment in default/systemd/user/bt-agent.service says the adapter is only pairable while the Bluetooth panel is open, but nothing on quattro sets Pairable (it only appears in that comment). So BlueZ's default stands, and the NoInputNoOutput agent accepts any pairing that reaches it. The second model, Codex Medium, did not run. It was reachable, but today's review budget was already used up. Until both agree, the class is unsettled, so this has no label and was not verified on a worker.

Also relevant for whoever picks this up: #12897, which is older and still open, also makes the Bluetooth panel own Pairable. It does this as part of replacing bt-agent with an agent that accepts pairing only while an adapter is pairable. Both change Panel.qml, bt-agent.service and omarchy-bluetooth-device to solve the same problem, so the maintainer will need to choose between them.

Next step: this goes back into the queue for a full review, with tests on a worker, once the second opinion is available. Nothing is needed from you in the meantime.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants