Skip to content

Fix IdleShutdown timer #2536#2592

Open
jdeitmerg wants to merge 7 commits intoMiczFlor:future3/developfrom
jdeitmerg:future3/fix-shutdown-timer
Open

Fix IdleShutdown timer #2536#2592
jdeitmerg wants to merge 7 commits intoMiczFlor:future3/developfrom
jdeitmerg:future3/fix-shutdown-timer

Conversation

@jdeitmerg
Copy link

@jdeitmerg jdeitmerg commented Jan 9, 2026

Hi,

I ran headfirst into #2536 and spent some time untangling it.

Context

#1970 Feature issue
#2536 Bug issue
#2535 Workaround for #2536, superseded by this PR

Fixes

With this PR, the shutdown timer works as documented for most cases. For why each change was necessary, refer to the commit messages.

Caveat: New bug

If not audio is playing for > timeout_sec, but there's SSH or file activity, the shut down will be delayed (as expected). However, the system will shut down once there's no more SSH or file activity, even if audio is playing. This is particularly nasty for the kid who wants to listen to the new cards that were just added via the full-sync feature.

Moving on

I ran into a lot of concurrency footguns in this module. E.g. the timer trying to change it's own timeout. Which cancels the timer before it can restart itself.

To fix the new bug above, I'd like to refactor the whole shutdown timer in the following fashion:

  • Keep polling with a 10s timer
  • Keep a timestamp of the last seen activity (audio playback, SSH access, file activity)
  • Shut down if timestamp older than timeout_sec

So no more shutdown timer object which implicitly tracks global state and is modified in asynchronous, hard to debug ways. Instead, simple state tracking and acting on it synchronously.

Can someone provide feedback on that approach before I dive in?

@jdeitmerg jdeitmerg marked this pull request as draft January 9, 2026 10:47
@coveralls
Copy link

coveralls commented Jan 10, 2026

Pull Request Test Coverage Report for Build 20992221818

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 38.14%

Totals Coverage Status
Change from base Build 19665970285: 0.0%
Covered Lines: 492
Relevant Lines: 1290

💛 - Coveralls

@jdeitmerg jdeitmerg changed the title Fix shutdown timer #2536 Fix IdleShutdown timer #2536 Jan 14, 2026
Change to fully synchronous approach rather than mixing synchronous and
asynchronous behavior
- simplifies logic
- fixes order of activity (e.g. playback first, then SSH vs. SSH first,
  then playback) influencing behavior
- replaces some custom code with builtin Python functions

Modifies RPC API of timer_idle_shutdown, potentially breaking
compatibility.
@jdeitmerg jdeitmerg force-pushed the future3/fix-shutdown-timer branch from 3162813 to e745877 Compare January 14, 2026 11:18
@jdeitmerg
Copy link
Author

jdeitmerg commented Jan 14, 2026

I'm done with refactoring IdleShutdownTimer to a fully synchronous approach, as noted above. The timer now behaves as documented.

Notes:

  • Few lines stayed untouched, idle_shutdown_timer.py is best read top to bottom instead of in the diff view
  • This breaks the RPC API of timer_idle_shutdown. That should not be a problem, as there probably aren't any users of that API. The timer didn't work at all, after all. I also didn't find any reference to timer_idle_shutdown except the dead end in src/webapp/src/commands/index.js
  • Regenerating documentation/developers/docstring/README.md leads to a huge diff, which I didn't commit. Is that a problem with my setup or is the committed version completely outdated?

@jdeitmerg jdeitmerg marked this pull request as ready for review January 14, 2026 12:25
@s-martin s-martin added bug future3 Relates to future3 development labels Jan 17, 2026
@s-martin s-martin linked an issue Jan 17, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug future3 Relates to future3 development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 | IdleShutdown timer broken

3 participants

Comments