Skip to content

Fix stale timer cleanup hiding restarted timers - #644

Open
1074016045 wants to merge 2 commits into
Ebullioscopic:devfrom
1074016045:agent/fix-timer-session-cleanup-race
Open

Fix stale timer cleanup hiding restarted timers#644
1074016045 wants to merge 2 commits into
Ebullioscopic:devfrom
1074016045:agent/fix-timer-session-cleanup-race

Conversation

@1074016045

@1074016045 1074016045 commented Jul 23, 2026

Copy link
Copy Markdown

Summary

  • prevent delayed cleanup from a completed timer from hiding a newly started timer
  • give each timer run a unique session identity and cancel stale smooth-close work
  • handle macOS Clock timers that reuse the same duration or identifier
  • add a standalone lifecycle regression test and run it in CI

Root cause

TimerManager.scheduleSmoothClose() scheduled an unconditional presentation update three seconds after a timer completed. If the user stopped that timer and immediately started another timer with the same duration, the old closure set isTimerActive to false for the replacement run. The countdown itself continued, so its alarm still fired without an Island stop control.

SystemTimerBridge also scheduled a 3.2-second external-timer cleanup that checked only whether some external timer was active. It could therefore clear a replacement Clock timer.

Fix

Each manual or external timer run now receives a unique session token. Starting or resetting a timer cancels pending smooth-close work, and delayed cleanup verifies that its captured token still belongs to the current session. A positive external update after completion starts a new session even if Clock reused the previous timer ID and duration.

Validation

  • python3 -m unittest tests.test_privacy_configuration tests.test_timer_lifecycle
  • Swift parser validation for the changed sources
  • manual macOS verification: complete a timer, stop it, restart the same duration within three seconds, and confirm the replacement remains visible and stoppable after both delayed-cleanup boundaries

Summary by CodeRabbit

  • Bug Fixes

    • Prevented delayed “smooth close” cleanup from interfering with a newly started or replacement timer session, improving stability when restarting or resetting timers (including external timer updates).
  • Tests

    • Added a Swift regression executable to validate timer session replacement behavior.
    • Added a Python unittest that compiles and runs the regression executable.
    • Updated macOS CI to include the new timer lifecycle regression test.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d649d7e9-0352-4443-a461-6c32c235a1e7

📥 Commits

Reviewing files that changed from the base of the PR and between 503606c and 5dc7198.

📒 Files selected for processing (7)
  • .github/workflows/ci.yml
  • .gitignore
  • DynamicIsland/managers/SystemTimerBridge.swift
  • DynamicIsland/managers/TimerLifecycle.swift
  • DynamicIsland/managers/TimerManager.swift
  • tests/TimerLifecycleRegression.swift
  • tests/test_timer_lifecycle.py

📝 Walkthrough

Walkthrough

Timer sessions now scope and cancel delayed smooth-close work. External cleanup validates session identity before mutating timer state. New Swift and Python regression tests compile and execute the lifecycle check in macOS CI.

Changes

Timer session safety

Layer / File(s) Summary
Session lifecycle and cancellable cleanup
DynamicIsland/managers/TimerLifecycle.swift, DynamicIsland/managers/TimerManager.swift
Timer sessions receive UUIDs, are replaced or ended across timer operations, and guard cancelable smooth-close work from stale updates.
External timer cleanup validation
DynamicIsland/managers/SystemTimerBridge.swift
Delayed external cleanup now requires the source and captured session to remain current before ending the timer.
Regression test and CI integration
tests/TimerLifecycleRegression.swift, tests/test_timer_lifecycle.py, .github/workflows/ci.yml, .gitignore
The lifecycle regression is compiled and executed through a Python unittest, with the test enabled in CI and preserved by ignore rules.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: preventing delayed timer cleanup from hiding restarted timers.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@1074016045
1074016045 marked this pull request as ready for review July 23, 2026 05:09

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@DynamicIsland/managers/SystemTimerBridge.swift`:
- Around line 822-835: Update completeExternalTimer() to persist the completed
external timer session ID before scheduling the main-queue block, rather than
reading TimerManager.shared.activeSessionID inside that block. Use the stored
completion token for delayed cleanup, and clear or replace it when a new timer
run is observed so a replacement Clock session cannot be ended by stale cleanup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cb3203b9-3fde-4112-8150-3a532089db60

📥 Commits

Reviewing files that changed from the base of the PR and between 503606c and 1b60a50.

📒 Files selected for processing (7)
  • .github/workflows/ci.yml
  • .gitignore
  • DynamicIsland/managers/SystemTimerBridge.swift
  • DynamicIsland/managers/TimerLifecycle.swift
  • DynamicIsland/managers/TimerManager.swift
  • tests/TimerLifecycleRegression.swift
  • tests/test_timer_lifecycle.py

Comment thread DynamicIsland/managers/SystemTimerBridge.swift
@1074016045

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@1074016045

Copy link
Copy Markdown
Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

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.

1 participant