fix(alfred): clear default timeout timers#14
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesTimeout cleanup and 0.10.4 release alignment
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
alfred/test/unit/timeout.test.js (1)
275-286: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAlso pin the fast-reject path.
This covers early resolution, but the new
finallyblock is also what clears the timer whenfnrejects before the deadline. A mirrored rejection test would lock down the other half of the release note and make this regression harder to reintroduce.🤖 Prompt for 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. In `@alfred/test/unit/timeout.test.js` around lines 275 - 286, The new timeout test only covers successful early completion, but the same cleanup path in timeout() should also be verified when the wrapped function rejects before the deadline. Add a mirrored test alongside the existing timeout test that uses vi.useFakeTimers(), calls timeout(1000, ...) with a Promise rejection, asserts the rejection is propagated, and checks vi.getTimerCount() returns 0 after the finally cleanup. Use the existing timeout helper and the same timer assertion pattern to pin the fast-reject path.
🤖 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 `@alfred/src/policies/timeout.js`:
- Around line 33-45: The timeout handler in the timeoutPromise flow must always
reject even if best-effort hooks fail. Wrap the onTimeout(elapsed) and
telemetry.emit(...) calls in separate try/catch blocks (or otherwise guard them)
so any exception from these side effects is swallowed or logged, and ensure
reject(new TimeoutError(timeoutMs, elapsed)) still runs unconditionally. Use the
timeout.js timeout path and the TimeoutError rejection as the key anchor points
when updating the logic.
---
Nitpick comments:
In `@alfred/test/unit/timeout.test.js`:
- Around line 275-286: The new timeout test only covers successful early
completion, but the same cleanup path in timeout() should also be verified when
the wrapped function rejects before the deadline. Add a mirrored test alongside
the existing timeout test that uses vi.useFakeTimers(), calls timeout(1000, ...)
with a Promise rejection, asserts the rejection is propagated, and checks
vi.getTimerCount() returns 0 after the finally cleanup. Use the existing timeout
helper and the same timer assertion pattern to pin the fast-reject path.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: bb010d4c-8518-4ae5-b409-6b7379c27973
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (10)
CHANGELOG.mdalfred-live/CHANGELOG.mdalfred-live/jsr.jsonalfred-live/package.jsonalfred/CHANGELOG.mdalfred/jsr.jsonalfred/package.jsonalfred/src/policies/timeout.jsalfred/test/unit/timeout.test.jspackage.json
Summary
timeout()finishes before the deadlineTestClockbehavior for deterministic timeout testsValidation
Summary by CodeRabbit
timeout()so when the wrapped operation resolves/rejects before the deadline, any pending runtime timer is cleared immediately (prevents stray timers).