Skip to content

Retry bt-agent until bluetooth.service is active - #13620

Open
AnPod wants to merge 5 commits into
omacom:quattrofrom
AnPod:cursor/fix-bt-agent-race-e0d3
Open

AnPod wants to merge 5 commits into
omacom:quattrofrom
AnPod:cursor/fix-bt-agent-race-e0d3

Conversation

@AnPod

@AnPod AnPod commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #13247

ExecCondition permanently skipped bt-agent.service when it raced bluetooth.service at login, leaving the session with no pairing agent.

Change

  • Order after bluetooth.service
  • Use ExecStartPre=systemctl is-active so Restart=on-failure retries until bluetoothd is up
  • Update test/shell.d/systemd-test.sh

Test plan

  • bash test/shell.d/systemd-test.sh

ExecCondition skipped permanently when it raced bluetoothd at login,
leaving the session with no pairing agent (omacom#13247).

Co-authored-by: AnPod <AnPod@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/fix-bt-agent-race-e0d3 branch from 7f91d34 to 6658680 Compare September 29, 2026 21:09
@omarchybot omarchybot added the bug Something isn't working label Oct 1, 2026
omarchybot and others added 2 commits October 3, 2026 10:05
bt-agent is a user unit, and the user manager has no bluetooth.service: it loads as not-found, so After= ordered against nothing and the test asserting the line guarded nothing. The ExecStartPre check plus Restart=on-failure is what waits for the system bluetoothd.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the bluetoothd check moved to ExecStartPre, starting bt-agent before bluetoothd is active fails the start job. enable-user-units.sh starts it under set -e, so on a first login racing bluetoothd it exited 1, failing the first-run step and skipping the owe theme-set hook after it. Start bt-agent with --no-block, so its own retries take over, and keep waiting on the other units so their failures still count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 3, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and reproduced on a worker VM. The fix works. I pushed two small corrections to your branch.

Reproduction. Using a virtual HCI controller, I held bluetooth.service inactive (masked, so D-Bus activation couldn't bring it straight back), started bt-agent, then brought bluez back after 5s and after 50s. On quattro the unit ends Result=exec-condition and never returns. On this branch the ExecStartPre failure retries every ~2s and the agent registers once bluez is up, including after the 50s outage. At RestartSec=2 the restarts stay outside the default 5-in-10s start limit.

Pushed:

  • 41628d2 removes bluetooth.service from After= again, along with its test. This is a user unit, and the user manager has no bluetooth.service (systemctl --user show bluetooth.service reports not-found), so the line ordered against nothing. The ExecStartPre check is what does the waiting.
  • b719dc0: install/user/first-run/enable-user-units.sh starts bt-agent with systemctl --user enable --now under set -e. With the check moved to ExecStartPre, that start now fails while bluetoothd is still coming up. On the worker it exited 1 (0 on quattro), which failed the first-run step and skipped the owe theme-set hook after it. This was the exact login race the PR fixes. bt-agent now gets its own enable --now --no-block line, so its retries take over, and the other units are still waited on. systemd-test.sh asserts the line.

Tests on the worker at b719dc0. test/shell.d/systemd-test.sh, bluetooth-test.sh and config-test.sh pass. ./test/cli has one failure, vscode generated theme references current theme file, which fails the same way on quattro and is unrelated to this change.

One tradeoff for the maintainer. On a machine with an adapter where the user has deliberately disabled bluetoothd, the unit now logs a failed start every 2s instead of skipping once. Omarchy itself turns Bluetooth off with rfkill, which leaves bluetoothd running, so this only affects a hand-disabled service.

Second opinion: Codex Medium, two rounds. The first round found the first-run failure above. The second round, on b719dc0, found nothing open beyond the tradeoff. That second round saw my results, so its agreement is not independent.

This fixes #13247. It is waiting on the maintainer, and on the unrelated ./test/cli failure on quattro.

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears mergeable, though the first-run test should stop modifying the runner’s desktop configuration.

Findings

  1. P2 Repeated starts when Bluetooth stays down ▶
  2. P2 Retry recovery remains untested ▶

Summary

The PR changes the Bluetooth agent’s inactive-service check into a failed pre-start check so systemd can retry it. It also starts the agent without blocking first-run setup and adds service and first-run assertions.

  • The new first-run test should isolate the input-method configuration it invokes.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[First-run setup] --> B[Enable and queue bt-agent]
  B --> C{bluetooth.service active?}
  C -- No --> D[Pre-start fails]
  D --> E[Restart after delay]
  E --> C
  C -- Yes --> F[Start pairing agent]
Loading

Reviews (2) · Last reviewed commit: "Test that a missing bt-agent costs first..." · Reviewed by Greptile

# ExecCondition would skip permanently when it races bluetooth.service at
# login (#13247). Fail the start instead so Restart=on-failure retries until
# bluetoothd is up.
ExecStartPre=/usr/bin/systemctl is-active --quiet bluetooth.service

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 Repeated starts when Bluetooth stays down If a machine has a Bluetooth adapter but bluetooth.service is masked or persistently failing, this check fails on every start attempt. The existing two-second restart interval then produces repeated failures and log entries instead of leaving the unit idle as ExecCondition did. Consider a backoff or a way to distinguish delayed startup from a service that will not start.

Knowledge Base Used: Desktop session and window management

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!

Comment on lines +9 to +10
grep -Fx 'ExecStartPre=/usr/bin/systemctl is-active --quiet bluetooth.service' "$service" >/dev/null
pass "bt-agent retries when bluetooth.service is not yet active"

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 Retry recovery remains untested This assertion checks that the pre-start command is present, but it does not test whether the agent starts after bluetooth.service changes from inactive to active. A test of that transition would protect the race fix; the current test could pass even if recovery stopped working.

omarchybot and others added 2 commits October 11, 2026 03:43
quattro now enables first-run's user units one at a time and exits non-zero if any failed. bt-agent comes out of that loop into its own call, still --no-block so its pre-start retry does not fail first-run, and still counted in the exit status if enabling it fails. --no-block goes before --now so first-run-test's parser, which reads each unit after "--user enable --now", is not handed two words.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bt-agent is enabled on its own line with --no-block ahead of --now, so the per-unit loop, which reads units after "--user enable --now", never covers it. Check it explicitly: first-run must report it and still enable everything else.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 11, 2026
@greptile-apps

greptile-apps Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings could not be posted inline.

  • P2 Test changes desktop settings test/shell.d/first-run-test.sh:53 ▶

    The new test runs enable-user-units.sh repeatedly without isolating the runner’s home or XDG configuration directories. That script calls the real omarchy-input-method configure --defaults, which can rewrite the runner’s Fcitx settings and reload a running input method. Stub that command or isolate its configuration so running the test does not change a developer’s desktop settings.

@omarchybot omarchybot added the ready Good to merge label Oct 11, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

quattro had changed install/user/first-run/enable-user-units.sh under this branch, so I merged quattro in and resolved the conflict. Then I re-verified the merged branch on a worker VM.

The conflict. quattro now enables first-run's user units one at a time and exits non-zero if any of them failed. bt-agent now has its own line after that loop, systemctl --user enable --no-block --now bt-agent.service || failed=1. It still doesn't wait on the start, which can fail while bluetoothd comes up, and a failure to enable it still counts. --no-block goes before --now because first-run-test.sh reads each unit after --user enable --now. That position also takes bt-agent out of the test's per-unit loop, so e5805eb adds an explicit case: with bt-agent.service missing, first-run must report the failure and still enable everything else. The case fails when the script swallows bt-agent's failure.

Reproduction at e5805eb. I used a virtual HCI controller, held bluetooth.service masked and started bt-agent. With quattro's unit, which is this branch's unit with the fix reverted, it ends Result=exec-condition and stays down after bluez starts. With this branch's unit it retries and registers its agent after a 5s outage and after a 50s outage. With bluetoothd down, enable --now exits 1 and enable --no-block --now exits 0.

Tests on the worker. ./test/cli passes. systemd-test.sh, first-run-test.sh, bluetooth-test.sh and config-test.sh pass. config-test.sh passes only when it is pointed at current omarchy-pkgs: the worker's copy predates the package that ships the USB and Thunderbolt authorization units, and quattro fails the same way against it.

Second opinion: Codex Medium, two rounds. The first round found the gap in first-run-test.sh coverage that e5805eb closes. The second round found nothing open. It can read this session's working notes, so its agreement on the rest is not independent.

Greptile's note on first-run-test.sh:53 is correct but not about this PR. enable-user-units.sh now calls omarchy-input-method configure --defaults, which came in with quattro (0b9dace), and the test does not stub it. Running the test can rewrite the runner's Fcitx settings. That belongs in a fix against quattro, not here.

#14795 changes the comment block directly below the line this PR changes in bt-agent.service, so whichever lands second will likely need a small rebase. They fix different things and don't compete.

This fixes #13247 and is waiting on the maintainer.

@omarchybot

Copy link
Copy Markdown
Collaborator

Re-checked at e5805eb by Claude Opus 5.5, with Codex Medium and muse-wonder (pi, thinking high) as second opinions. Nothing was run this time: the head is the one tested on a worker on 11 October, and those results still hold.

It no longer merges into quattro. #16334 removed the tests that only read source text, including the bt-agent assertions this branch edits in test/shell.d/systemd-test.sh, so verified came off. #9131, #11937 and #13258 hit the same conflict, and #13258 has already been brought up to date.

This is one of four open fixes for the skip in #13247 and #8962, and it is the newest. The older ones are #9131 (30 August), #11937 (15 September) and #13258 (25 September). The older fix wins by default. This one doesn't take the place of #11937 or #13258, because both are older and both handle a case it doesn't. On a machine with the bluetooth module loaded but bluetooth.service disabled, this unit's ExecStartPre fails and restarts about every 2 seconds for the whole session. The stock unit skipped once there. #11937 and #13258 wait inside ExecStart and stay quiet on that machine.

Second opinion. Both reviewers compared the four diffs without being told my answer. Both chose #11937 over this one, because it also replaces an agent left registered to a bluetoothd that has since restarted (#9965). Neither found anything here that the winner lacks. The first-run --no-block line and its test are only needed for an ExecStartPre design. They disagreed about the start limit. muse-wonder expected the default 5-in-10s limit to stop the retries after about 10 seconds. Codex worked out that the sixth start lands just after the 10-second window, so the retries never stop. The 11 October worker run supports Codex: the agent registered after bluetoothd had been down for 50 seconds.

I haven't resolved the conflict, because the merge would only be needed if this fix were chosen. If the maintainer picks this one, the conflict is in test/shell.d/systemd-test.sh only, and it resolves to quattro's file.

Waiting on: the maintainer, to choose between the competing fixes.

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.

bt-agent.service is permanently skipped when its ExecCondition races bluetooth.service, leaving the session with no Bluetooth pairing agent

3 participants