Skip to content

fix(actions): add safety timeout to long-press repeat intervals (#284)#298

Merged
niklam merged 1 commit into
masterfrom
fix/284-fuel-repeat-safety-timeout
Apr 9, 2026
Merged

fix(actions): add safety timeout to long-press repeat intervals (#284)#298
niklam merged 1 commit into
masterfrom
fix/284-fuel-repeat-safety-timeout

Conversation

@niklam
Copy link
Copy Markdown
Owner

@niklam niklam commented Apr 9, 2026

Summary

  • Adds a 15-second safety timeout to FuelService and ReplayControl long-press repeat intervals that auto-stops the repeat and logs a warning when triggered
  • Prevents fuel adjustment and replay control buttons from looping indefinitely when keyUp events are missed (observed on Mirabox devices)
  • Both the repeat interval and safety timeout are stored together and cleaned up in stopRepeat

Closes #284

Test plan

  • All 2699 existing tests pass
  • 6 new tests added (3 fuel-service, 3 replay-control) covering auto-stop, warning log, and normal keyUp cleanup
  • Full build succeeds
  • Manual test on Mirabox: rapidly press Add Fuel button and verify commands stop after 15s if keyUp is missed

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Added a safety timeout to long-press repeat actions. Actions now automatically stop repeating after 15 seconds to prevent accidental continuous repeats if the release event is missed.

Prevent fuel and replay control buttons from looping indefinitely when
keyUp events are missed (observed on Mirabox devices). Both FuelService
and ReplayControl now auto-stop their repeat intervals after 15 seconds
and log a warning when the safety timeout triggers.
@github-actions github-actions Bot added the type: bug Bug fix label Apr 9, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2026

📝 Walkthrough

Walkthrough

The PR adds a 15-second safety timeout mechanism to prevent long-press repeat actions from running indefinitely. When a repeat starts, a safety timeout is scheduled to automatically stop the repeat and log a warning. If onKeyUp is received before the timeout, the safety timeout is cleared. This prevents stuck button issues.

Changes

Cohort / File(s) Summary
Fuel Service Implementation
packages/actions/src/actions/fuel-service.ts
Added REPEAT_MAX_DURATION_MS constant (15s), modified repeatIntervals Map to track both interval and safety timeout handles, updated startRepeat() to schedule a safety timeout that warns and stops repeat, updated stopRepeat() to clear both interval and safety timeout.
Fuel Service Tests
packages/actions/src/actions/fuel-service.test.ts
Added three test cases for safety timeout behavior: (1) repeat context auto-removed after 15s, (2) warning logged with "safety timeout" message, (3) onKeyUp clears safety timeout preventing spurious warnings.
Replay Control Implementation
packages/actions/src/actions/replay-control.ts
Added LONG_PRESS_MAX_DURATION_MS constant (15s), modified repeatTimers Map to track both repeat interval and safety timeout, updated startRepeat() to store both handles, updated stopRepeat() to clear both interval and safety timeout.
Replay Control Tests
packages/actions/src/actions/replay-control.test.ts
Updated imports to include ReplayControl class, extended mock ConnectionStateAwareAction with lifecycle methods, added new long-press repeat test suite verifying safety timeout triggers after 15s, warning is logged, and onKeyUp clears the timeout early.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 A carrot-press gone wild no more,
Fifteen seconds—that's the floor!
Safety timeouts, warnings clear,
No stuck buttons here, my dear! 🥕⏰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding a safety timeout to long-press repeat intervals with reference to issue #284.
Description check ✅ Passed The description provides a clear summary, explanation of the fix, test plan results, and issue reference; all required template sections are addressed.
Linked Issues check ✅ Passed The code changes fully address issue #284 objectives by implementing a 15-second safety timeout to prevent indefinite looping of fuel and replay control buttons when keyUp events are missed.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the safety timeout feature for long-press repeats in FuelService and ReplayControl with corresponding tests; no unrelated changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/284-fuel-repeat-safety-timeout

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/actions/src/actions/replay-control.ts (1)

565-574: Consider adding a brief comment explaining the dual-clear pattern.

The stopRepeat method calls both clearTimeout and clearInterval on entry.timer (lines 569-570). This is intentional because timer holds a setTimeout handle initially, then gets overwritten with a setInterval handle. A short inline comment would help future maintainers understand this design choice.

💡 Suggested comment
   private stopRepeat(contextId: string): void {
     const entry = this.repeatTimers.get(contextId);

     if (entry) {
+      // timer may be setTimeout (initial delay) or setInterval (repeat phase)
       clearTimeout(entry.timer);
       clearInterval(entry.timer);
       clearTimeout(entry.safety);
       this.repeatTimers.delete(contextId);
     }
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/actions/src/actions/replay-control.ts` around lines 565 - 574, Add a
brief inline comment in stopRepeat explaining why both clearTimeout and
clearInterval are called: mention that repeatTimers stores an entry whose timer
field starts as a setTimeout handle and may later be replaced by a setInterval
handle, so both clear* calls are used defensively to ensure the handle is
cleared regardless of type; reference the stopRepeat method and the entry.timer
and entry.safety fields when adding the comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/actions/src/actions/replay-control.ts`:
- Around line 565-574: Add a brief inline comment in stopRepeat explaining why
both clearTimeout and clearInterval are called: mention that repeatTimers stores
an entry whose timer field starts as a setTimeout handle and may later be
replaced by a setInterval handle, so both clear* calls are used defensively to
ensure the handle is cleared regardless of type; reference the stopRepeat method
and the entry.timer and entry.safety fields when adding the comment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 40689c81-6f7f-4daa-9d06-be553f9be490

📥 Commits

Reviewing files that changed from the base of the PR and between 3b0b3a8 and e8e6c75.

📒 Files selected for processing (4)
  • packages/actions/src/actions/fuel-service.test.ts
  • packages/actions/src/actions/fuel-service.ts
  • packages/actions/src/actions/replay-control.test.ts
  • packages/actions/src/actions/replay-control.ts

@niklam niklam merged commit 21b8acb into master Apr 9, 2026
6 checks passed
@niklam niklam deleted the fix/284-fuel-repeat-safety-timeout branch April 9, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fuel Adjustment Buttons Stuck Looping Command

1 participant