Skip to content

Remember Bluetooth power and restore it after login - #13667

Open
AnPod wants to merge 2 commits into
omacom:quattrofrom
AnPod:cursor/fix-bt-off-persist-ef3e
Open

AnPod wants to merge 2 commits into
omacom:quattrofrom
AnPod:cursor/fix-bt-off-persist-ef3e

Conversation

@AnPod

@AnPod AnPod commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Turning Bluetooth off via the panel can lose the preference across reboot when BlueZ AutoEnable races systemd-rfkill.

omarchy-bluetooth-power now mirrors on/off under XDG state, and a session oneshot (omarchy-bluetooth-power-restore.service) re-applies it after login. First-run and a migration enable the unit for new and existing installs.

Fixes #13342

Test plan

  • test/shell.d/bluetooth-test.sh (remember/restore)
  • test/shell.d/systemd-test.sh (unit + first-run)
  • Turn Bluetooth off, reboot, confirm it stays off

@jandrusk

jandrusk commented Oct 7, 2026

Copy link
Copy Markdown

Thanks for digging into #13342. A couple of concerns with the approach:

  1. The state file can override a correct rfkill state. Only omarchy-bluetooth-power writes ~/.local/state/omarchy/bluetooth-power. Turning Bluetooth off any other way (an airplane-mode / Fn key, rfkill block directly, or another tool) leaves the file saying on, and the next login's restore then runs power_on and unblocks the radio. That breaks the systemd-rfkill persistence that works correctly today. It would be safer for restore to only re-apply off (block) and never unblock, or to write the file only when the block state actually changes.
  2. Copying the unit into ~/.config/systemd/user/ in both first-run and the migration means the user copy shadows any future packaged version, so later fixes to the unit never reach existing installs. The other Omarchy user units ship from the package. Could this one ship the same way?
  3. toggle/on record on before power_on runs, so a failed power-on still stores on.

Related: #13867 also changes Bluetooth power behavior (Chromium phone-passkey power-on) and overlaps here, and #12753 changes the scope of the rfkill block. Worth checking the three together.

BlueZ AutoEnable can race systemd-rfkill across reboot. Mirror on/off
under XDG state and re-apply it from a session oneshot (omacom#13342).

Co-authored-by: AnPod <AnPod@users.noreply.github.com>
@AnPod
AnPod force-pushed the cursor/fix-bt-off-persist-ef3e branch from a6244b3 to a375536 Compare October 13, 2026 05:38
@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change is limited to Bluetooth power in Omarchy desktop sessions.

The PR should not merge until the Bluetooth tests stop overwriting the user's saved choice.

Findings

  1. P1 Tests overwrite the saved choice ▶
  2. P2 Restore does not wait ▶

Summary

The PR saves Bluetooth power choices and reapplies them after login.

  • Bluetooth power choices are remembered and restored after login.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[User changes Bluetooth power] --> B[Save choice]
  A --> C[Change radio power]
  D[Graphical session starts] --> E[Restore service]
  E --> F[Read saved choice]
  F --> C
Loading

Reviews (2) · Last reviewed commit: "bluetooth: restore the saved power state..." · Reviewed by Greptile

Comment on lines +286 to +288
state_home="$device_tmp/state"
mkdir -p "$state_home"
export XDG_STATE_HOME="$state_home"

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 Tests overwrite the saved choice

XDG_STATE_HOME is set only after earlier calls to omarchy-bluetooth-power. Those calls now save preferences, so running this test with the normal environment overwrites ~/.local/state/omarchy/bluetooth-power. The last earlier toggle saves off, which the new service applies at the next login.

Move the temporary state setup before the first helper call, and isolate OMARCHY_BLUETOOTH_STATE_FILE too.

# bluetoothd may AutoEnable before systemd-rfkill finishes restoring a soft
# block across reboot (#13342). Re-apply the user's last omarchy-bluetooth-power
# choice once the session and bluetooth stack are up.
After=bluetooth.service graphical-session-pre.target

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 Restore does not wait

After=bluetooth.service cannot wait for the system Bluetooth service from this user unit. Bluetooth runs in the system manager, while this service runs in the user manager.

If Bluetooth starts late, the one-time restore can finish before it is ready. The on branch hides failure and does not retry, leaving the saved choice unapplied. Use an explicit readiness check and a bounded retry instead.

Knowledge Base Used: Desktop session and window management

@omarchybot omarchybot removed the enhancement New feature or request label Oct 15, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

The class of this pull request is unsettled, so it carries no class label for now and nothing was run on it this pass.

Two models classified it separately at a375536. I (Opus 5.5 in Claude Code) read it as a bug fix. It is linked to close #13342, which is labelled bug and reports that Bluetooth turned off from the panel comes back on after a reboot, and that is wrong behaviour on quattro today. Codex Medium classified it as an enhancement. The case for that reading is in the diff itself: a remembered on/off preference, a new restore subcommand for omarchy-bluetooth-power, and a new user service with a migration to install it. That is new machinery rather than a correction to the code that already handles the soft block. The enhancement label from an earlier revision has come off, because the two models no longer agree on it.

Nothing else was reviewed or verified, so this is not a finding on the change. Whether it is worked as a fix or treated as a feature is the maintainer's call, and it waits on them.

@echennells

Copy link
Copy Markdown

Hardware test of a3755362 on a ThinkPad T14 Gen 2a (20XLS0A300, Realtek RTL8852AU 0bda:4852 behind tpacpi_bluetooth_sw), the machine whose trace is in #13342. Setup: Omarchy 4.0.6-1, kernel 7.2.8-9-omarchy, systemd 262, Hyprland 0.56.2 with uwsm 0.27.1, bluez 5.87. This covers the unticked box in the test plan, and it confirms omarchybot's ordering concern on real hardware.

Method: the PR's helper first on PATH, and its unit copied into ~/.config/systemd/user/ and enabled, as the migration does. One deviation: a drop-in points ExecStart at the PR's helper, because /usr/bin/omarchy-bluetooth-power on 4.0.6 is the packaged one without restore. Otherwise the unit is verbatim. Each run: omarchy-bluetooth-power off (state file off, type-wide block), wait 7 s for systemd-rfkill to save, reboot, log in, wait. rfkill event from early boot plus the system and user journals give one timeline.

Off kept after reboot
Stock 4.0.6 0/1
This PR (a3755362) 0/3
This PR + After=graphical-session.target 2/2

Why it fails as written (boot 1, seconds since boot):

t
8.87 systemd-rfkill restores the platform block; the radio drops off USB at 9.10
12.33 graphical-session-pre.target is reached and the restore unit runs, finishing in 27 ms. Everything is already blocked, so its rfkill block bluetooth changes nothing (no rfkill event)
13.64 Hyprland's main service has started
13.66 tpacpi_bluetooth_sw is unblocked, 1.33 s after the restore finished
end Bluetooth is on; the state file still says off

Boots 2 and 3 show the same order, with the restore 1.32 s before the unblock. (In boot 2 the old hci0 entry hadn't been removed yet, so the block landed on that stale entry; same outcome.)

The unblock is the kernel rfkill-input unblock-all from #13342: it fires when Hyprland's first input-device sync flushes the SW_RFKILL_ALL event that thinkpad_acpi left queued. So on this machine the cause isn't bluetoothd's AutoEnable. bluetoothd starts about 3 s earlier (10.3 s), and while the platform switch is blocked there is no adapter for it to power. Anything that runs before Hyprland starts loses to that unblock.

With After=graphical-session.target added (a drop-in, ordered the way omarchy-fcitx5.service is; systemd-analyze --user verify reports no cycle):

t
15.71 / 15.73 Hyprland started; tpacpi_bluetooth_sw unblocked
16.27 graphical-session.target reached
16.30 / 16.33 restore runs: block set for type bluetooth
end platform switch blocked, Bluetooth off (2/2)

Two caveats:

  • It's a margin, not a dependency. The target was reached 0.53–0.55 s after the unblock in all six boots today, but nothing orders Hyprland's input sync before the target.
  • With the type-wide block, the radio has already started coming back when the restore blocks again, so it appears on USB for ~0.15 s and drops: two disconnects per boot instead of one. With Scope bluetooth rfkill block to HCI adapters, sparing platform switches #12753's hci-only block this would look different; I didn't test the two together.

Not tested: jandrusk's point about an off set outside omarchy-bluetooth-power.

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

On a ThinkPad T14 Gen 2a the restore ran at graphical-session-pre.target,
about 1.3 s before Hyprland's first input sync flushed the queued
SW_RFKILL_ALL event; rfkill-input then unblocked every radio and Bluetooth
came back on over a saved off (0/3 boots). Ordered after
graphical-session.target, the off state held (2/2), as tested by @echennells.
@omarchybot

Copy link
Copy Markdown
Collaborator

The head moved to 1d5587e since the last pass, so this pull request was classified again, and its class is still unsettled. It carries no class label for now and nothing was run on it.

I (Opus 5.5 in Claude Code) read it as compatibility: a bug whose cause is the machine. It closes #13342, where Bluetooth turned off from the panel comes back on after a reboot, and the trace there puts the unblock in the kernel's rfkill input handler reacting to the SW_RFKILL_ALL event thinkpad_acpi leaves queued, which is specific to ThinkPads. The second classification, by Codex Medium, did not run: the reviewer answers, but the coordinator's daily cap on reviews is spent. One model's reading is not a settled class, so this waits for the next pass, which asks again.

Nothing on this head was reviewed or verified, so this is not a finding on the change.

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.

Bluetooth does not retain OFF setting between reboots

5 participants