Skip to content

Back off bt-agent restarts while a device flaps - #13598

Open
AnPod wants to merge 3 commits into
omacom:quattrofrom
AnPod:cursor/fix-bt-agent-restart-backoff-ef3e
Open

AnPod wants to merge 3 commits into
omacom:quattrofrom
AnPod:cursor/fix-bt-agent-restart-backoff-ef3e

Conversation

@AnPod

@AnPod AnPod commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #13487: a flapping Bluetooth device can make bt-agent exit about every 15s. With a flat RestartSec=2, the user journal tight-loops for hours.

Changes

  • default/systemd/user/bt-agent.service: keep RestartSec=2 but add RestartSteps=6 / RestartMaxDelaySec=120, so repeated restarts back off up to two minutes instead of retrying every 2 seconds.
  • No StartLimit* override, so a flapping device never leaves the unit stuck in failed and pairing keeps working.
  • test/shell.d/systemd-test.sh checks the backoff settings and that no StartLimit* setting is added.

Test plan

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

Flapping Bluetooth devices can make bt-agent exit about every 15s; a
2s RestartSec tight-loops the journal. Lengthen the delay and cap the
restart burst.

Co-authored-by: AnPod <AnPod@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/fix-bt-agent-restart-backoff-ef3e branch from a57f813 to cd48585 Compare September 29, 2026 21:09

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

please put the start-limit settings in the unit section.

Comment thread default/systemd/user/bt-agent.service Outdated
# Flapping Bluetooth devices can make bt-agent exit about every 15 s (#13487).
# A short RestartSec tight-loops the journal; back off and cap the burst.
RestartSec=15
StartLimitIntervalSec=300

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.

please move StartLimitIntervalSec into [Unit]: systemd accepts that name only there (the legacy [Service] spelling is StartLimitInterval), so this line is ignored. with the normal 10-second limit interval and RestartSec=15, each restart falls outside the window and the intended eight-start cap never takes effect.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adjusts restart behavior for a system service.

The PR appears safe to merge; the revised restart policy keeps retrying at a slower cadence without a confirmed new defect.

Summary

The PR replaces a fixed restart delay and custom start cap with increasing delays, so bt-agent can keep retrying without the original rapid-restart cadence.

  • Updates the shell test to check the new settings and absence of a custom start limit.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Failure["bt-agent fails"] --> Restart["Restart after increasing delay"]
  Restart --> Agent["bt-agent starts"]
  Agent -->|fails again| Failure
  Agent -->|continues running| Pairing["Pairing remains available"]
Loading

Reviews (2) · Last reviewed commit: "Back off bt-agent retries without stoppi..." · Reviewed by Greptile

Comment thread default/systemd/user/bt-agent.service Resolved
@omarchybot omarchybot added the bug Something isn't working label Oct 3, 2026
@jandrusk

jandrusk commented Oct 7, 2026

Copy link
Copy Markdown

One concern with the start limit: StartLimitBurst=8 in StartLimitIntervalSec=300 turns a flap into a stopped pairing agent for the rest of the session. In #13487 bt-agent exits about every 15 s. With RestartSec=15 that's a start roughly every 30 s, so the 8-start budget runs out after about 4 minutes. Then the unit sits in failed until the next login, and pairing from the Bluetooth panel silently stops auto-accepting even after the bad device is gone. On quattro the agent always comes back.

systemd's restart backoff (v254+) gets rid of the journal spam without ever giving up:

[Unit]
# no StartLimit* overrides

[Service]
Restart=on-failure
RestartSec=2
RestartSteps=6
RestartMaxDelaySec=120

That ramps the delay from 2 s to 120 s while the device keeps flapping, then goes back to a quick restart once the agent stays up. The systemd-test.sh assertions would need to check RestartSteps/RestartMaxDelaySec and the absence of StartLimitBurst.

@omarchybot omarchybot removed the bug Something isn't working label Oct 7, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at f027fdf. The classification is unsettled, so this has not gone further yet, and nothing has been run on a worker.

Two models classified it separately and disagreed. Claude Opus 5.5 read it as a bug fix: on quattro, a flapping device keeps bt-agent in a restart loop that spams the user journal for hours (#13487), and this stops that. Codex Medium read it as an enhancement: the unit restarts a failing bt-agent exactly as configured, the crash itself is in bt-agent (bluez-tools), and slowing the restart cadence is a deliberate change of behaviour. Both readings are defensible, so the earlier bug label has come off until the maintainer decides which it is. Once they have, the next step is to verify the new restart backoff on a worker.

One thing for the author in the meantime: the description still lists RestartSec=15 and StartLimitIntervalSec=300 / StartLimitBurst=8, which the latest commit replaced with RestartSteps=6 and RestartMaxDelaySec=120. Updating it to match the diff would help whoever reviews it next.

Waiting on the maintainer to settle the classification.

@jandrusk

jandrusk commented Oct 8, 2026

Copy link
Copy Markdown

Thanks, f027fdf does exactly that: RestartSteps=6 / RestartMaxDelaySec=120 with no StartLimit* override, so a flapping device backs off and pairing never ends up stuck in failed. The test checks both. LGTM from my side. Just update the PR description, which still lists RestartSec=15 and StartLimitBurst=8.

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.

bt-agent (auto-accept) crash-loops every ~15 s while a flapping Bluetooth device is present

5 participants