Skip to content

Report Bluetooth device failures and verify pairing - #14319

Closed
davidboulay wants to merge 1 commit into
omacom:quattrofrom
davidboulay:fix/bluetooth-device-errors
Closed

davidboulay wants to merge 1 commit into
omacom:quattrofrom
davidboulay:fix/bluetooth-device-errors

Conversation

@davidboulay

Copy link
Copy Markdown

Bluetooth device actions launched from the panel discard all errors and return success. A failed pairing still proceeds to trust and connect, leaving the user without an explanation.

This change reports failures through stderr and an Omarchy notification, returns nonzero, and stops the pairing sequence before trust/connect when pairing fails. It also catches bluetoothctl's printed failures when its exit status is zero, checks Paired and Connected state, and skips a redundant connection request when pairing already established the connection. Disconnect and forget failures are surfaced too; forgetting an already disconnected device still works.

Found while investigating an AirPods Pro pairing failure. Direct BlueZ pairing later succeeded, but the original failure's cause is not established; this PR addresses the confirmed suppressed-error behavior and does not replace the Bluetooth transport or add AirPods-specific handling.

Validation:

  • bash test/shell.d/bluetooth-test.sh passed, including regression coverage for pair failures with exit statuses 0, 1, and 124, unconfirmed pairing, already-connected pairing, and connection failure.
  • ./test/cli passed.
  • bash -n bin/omarchy-bluetooth-device and git diff --check passed.
  • Failure paths were tested with mocks to avoid interrupting live Bluetooth devices. The upstream helper change has not been tested with a fresh physical pairing.

@greptile-apps

greptile-apps Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Bluetooth device pairing now reports failures to the user.

The PR should not merge until forgetting a device can still attempt removal after disconnect fails.

Findings

  1. P1 Disconnect failure blocks forgetting ▶
  2. P2 Forget flow lacks tests ▶

Summary

The PR reports Bluetooth command failures, verifies pairing and connection state, and adds mocked regression tests. Its forget flow now stops before removal if disconnect fails.

  • Pair and connect failures are surfaced through stderr and a notification.
  • Forget needs to attempt removal independently of disconnect success.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Forget device] --> B{Connected?}
  B -- No --> E[Remove device]
  B -- Yes --> C[Disconnect]
  C -- Success --> E
  C -- Failure --> D[Notify and exit]
  E --> F[Device forgotten or removal error reported]
Loading

Reviews (1) · Last reviewed commit: "Report Bluetooth device failures and ver..."

timeout 10s bluetoothctl remove "$address" >/dev/null 2>&1 || true
# An already disconnected device can still be forgotten.
if device_has_state Connected; then
run_device_command 10s disconnect

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 Disconnect failure blocks forgetting If disconnecting a connected device fails or times out, this call exits the script before it attempts bluetoothctl remove. The device remains paired even though the user asked to forget it. Report the disconnect failure, but still attempt removal.

Comment on lines +338 to +345
: >"$device_tmp/log"
rm -f "$POWERED_FILE.connected"
if PATH="$mock_bin:$ROOT/bin:$PATH" BLUETOOTHCTL_LOG="$device_tmp/log" MOCK_DEVICE_FAIL=connect \
"$ROOT/bin/omarchy-bluetooth-device" connect AA:BB:CC:DD:EE:FF >"$device_tmp/error" 2>&1; then
fail "connection failure exits nonzero even when bluetoothctl exits zero"
fi
grep -q 'Bluetooth connect failed' "$device_tmp/log" || fail "connection failure notifies"
pass "connection failure is reported"

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 Forget flow lacks tests The new action tests cover pair and connect, but never exercise the changed disconnect or forget paths. Add cases for a disconnect failure during forget and for forgetting an already-disconnected device, so regressions in the new removal flow do not go unnoticed.

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!

@echennells

Copy link
Copy Markdown

I compared this with #7880 and #13811 on real hardware (ThinkPad T14 Gen 2a, Realtek, BLE mouse), applied onto 4.0.4 at 91d98fb0. Table and details: #7879 (comment)

The reporting works. With the pairing agent stopped, the pair failed with exit 1 and a "Bluetooth pair failed" notification, and the device was not left trusted. With the agent running it paired normally (2 runs).

One problem is in the timeout path. device_error "${output:-…timed out or failed…}" never uses its fallback, because after a 20 s timeout the variable output holds bluetoothctl's discovery chatter. When I retried right after the failure, the notification body showed:

  • [DEL] Device <address> <name> lines for unrelated nearby devices
  • ANSI colour codes
  • no actual reason

That body also stays in notification history, with other people's device addresses in it.

Suggestions (untested):

  • Treat exit status 124 as a timeout, with a fixed message such as "Pairing timed out after 20 s. Is the device in pairing mode?"
  • Otherwise pass only the Failed to … line.
  • Strip ANSI codes, e.g. sed 's/\x1b\[[0-9;]*m//g'.

Tested with help from Claude Code; every run was on my machine.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for this. Reviewed at 91d98fb. It overlaps with an older open pull request, so it waits on the maintainer and was not run on a worker.

Overlap. The part of this change that stops a failed pair from going on to trust and connect is also what #7880 (opened 2026-08-23) does, in the same lines of bin/omarchy-bluetooth-device. #7880 already has verified, and it also changes the panel so that a device that is trusted but not paired gets paired again on the next click. The two would conflict if both merged. Under this project's rule, the older fix wins unless it is clearly worse, and #7880 has no defect for this bug: bluetoothctl pair exits non-zero when pairing fails, including after the 20 s timeout, so its exit status is enough.

What this adds. Only this pull request tells the user. The panel starts the helper with Quickshell.execDetached (Panel.qml, runDeviceAction), so it never sees the exit status or stderr, and a notification is the only way a failure reaches anyone. That improvement has been handed to #7880 to fold in, credited to you.

Two defects, found by reading the source:

  • bin/omarchy-bluetooth-device:43: when timeout kills bluetoothctl, output still holds whatever it printed before that, so the fallback message never appears. @echennells saw this on hardware: the notification showed [DEL] Device … lines for other nearby devices, plus ANSI colour codes, and kept them in notification history. Exit status 124 needs its own fixed message.
  • bin/omarchy-bluetooth-device:80: in forget, if the disconnect fails, device_error exits before remove at line 82 runs, so a device that will not disconnect can no longer be forgotten. Before this change, the helper tried to remove it anyway. Greptile flagged the same thing.

Also, the helper's check for output containing Failed to when the exit status is zero covers a case that BlueZ 5.80–5.87 does not produce for pair. The error policy for connect, trust, disconnect and forget also goes beyond the pairing bug.

Who checked. I reviewed it (Claude Opus 5.5), with Codex Medium as the second opinion. Codex was given this pull request, #7880 and #11260 and asked which should win, without my answer. It picked #7880 for the same reason. The two defects above came from its review, and I confirmed both against the source. Its independence is not guaranteed.

Next. This waits on the maintainer. Nothing is needed from you unless they ask for it.

omarchybot added a commit to reinierbutot/omarchy that referenced this pull request Oct 16, 2026
The panel launches omarchy-bluetooth-device with Quickshell.execDetached, so it never sees the helper's exit status or stderr: a failed pair now leaves the device retryable, but nothing says it failed. Notify instead, with a fixed message and a distinct one for the 20 second timeout, and exit 1 for anyone running it by hand. The message never carries bluetoothctl's output, which after a timeout is discovery chatter naming other nearby devices.

Folded in from omacom#14319.

Co-Authored-By: David Boulay <david.boulay@lojel.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidboulay davidboulay closed this by deleting the head repository Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants