Skip to content

fix(expert mode): do not apply auto start cooldown after a reboot#2196

Open
evil-raider wants to merge 1 commit into
keymapperorg:developfrom
evil-raider:fix/reboot-cooldown
Open

fix(expert mode): do not apply auto start cooldown after a reboot#2196
evil-raider wants to merge 1 commit into
keymapperorg:developfrom
evil-raider:fix/reboot-cooldown

Conversation

@evil-raider

@evil-raider evil-raider commented Jul 22, 2026

Copy link
Copy Markdown

Problem

Fixes #2195

created by opus 4.8

The system bridge (Expert mode) has a 5-minute auto-start cooldown that
prevents it from restarting if it was last auto-started less than 5 minutes
ago. This exists to avoid an infinite restart loop when the bridge keeps
being killed shortly after starting.

The cooldown is based solely on the wall-clock time of the last auto start
(systemBridgeLastAutoStartTime), which persists across reboots. So this
happens:

  1. Reboot the device with Key Mapper running → bridge auto-starts, stores the timestamp.
  2. Use the device for 1–2 minutes.
  3. Reboot again → the bridge is stopped by the reboot (a correct
    termination, not a crash), but the cooldown still fires.
  4. User gets the "expert mode stopped unexpectedly / not auto restarting
    because last auto started less than 5 minutes ago" notification and the
    service does not start.

Fix

Store the device boot time (unixTimestamp() - elapsedRealtime()/1000)
alongside the last auto-start time, and skip the cooldown when the current
boot time differs from the stored one (i.e. the device has rebooted since the
last auto start).

A crash loop within a single boot session still triggers the cooldown,
because the boot time does not change between kills — so the original
protection is preserved. A 60-second tolerance absorbs clock jitter/NTP
adjustments so they aren't mistaken for a reboot.

Testing

Added a unit test in SystemBridgeAutoStarterTest covering the case: last
auto start was <5 minutes ago but during a previous boot → the bridge should
still auto start.

The system bridge auto start has a 5 minute cooldown that prevents it
from being auto started again if it was last auto started less than 5
minutes ago. This exists to avoid an infinite restart loop when the
system bridge keeps being killed shortly after starting.

The cooldown was based solely on the wall clock time of the last auto
start (systemBridgeLastAutoStartTime), which persists across reboots.
So if the user rebooted, used the device for 1-2 minutes and rebooted
again, the system bridge was stopped by the reboot (a correct
termination, not a crash) but the cooldown still fired. The user got the
"expert mode stopped unexpectedly / not auto restarting because last
auto started less than 5 minutes ago" notification and the service did
not start.

Store the device boot time (unix time - elapsed realtime) alongside the
last auto start time, and skip the cooldown when the current boot time
differs from the stored one, i.e. the device has rebooted since the last
auto start. A crash loop within a single boot session still triggers the
cooldown because the boot time does not change between kills.

Fixes keymapperorg#2195
@evil-raider
evil-raider force-pushed the fix/reboot-cooldown branch from c4916c0 to 881ae88 Compare July 22, 2026 18:02
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.

after second reboot within 5 minutes the accessibility service does not start up

1 participant