Skip to content

fix(alfred): clear default timeout timers#14

Merged
flyingrobots merged 2 commits into
mainfrom
fix/timeout-system-clock-fallback
Jun 24, 2026
Merged

fix(alfred): clear default timeout timers#14
flyingrobots merged 2 commits into
mainfrom
fix/timeout-system-clock-fallback

Conversation

@flyingrobots

@flyingrobots flyingrobots commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

  • clear the default runtime timer when timeout() finishes before the deadline
  • preserve injected TestClock behavior for deterministic timeout tests
  • bump the Alfred workspace packages to v0.10.4 and update aggregate release notes

Validation

  • pnpm --filter @git-stunts/alfred test -- timeout.test.js (red before implementation, green after)
  • pnpm -r run lint
  • pnpm -r test
  • git diff --check
  • node scripts/release/preflight.mjs
  • pre-push hook reran lint, tests, and release preflight

Summary by CodeRabbit

  • Bug Fixes
    • Updated timeout() so when the wrapped operation resolves/rejects before the deadline, any pending runtime timer is cleared immediately (prevents stray timers).
    • Preserved deterministic behavior when using injected clocks, including correct timeout failure signaling.
  • Chores
    • Bumped package versions to 0.10.4 across the release family and aligned the related Alfred package-family metadata; no API changes.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c0b7f963-e9bd-4502-8efe-54ab7c33522c

📥 Commits

Reviewing files that changed from the base of the PR and between 9c74c47 and 360934b.

📒 Files selected for processing (2)
  • alfred/src/policies/timeout.js
  • alfred/test/unit/timeout.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • alfred/src/policies/timeout.js

📝 Walkthrough

Walkthrough

timeout() now clears its default runtime timer when the wrapped operation finishes before the deadline, while keeping injected-clock behavior unchanged. Package versions and changelog entries were bumped to 0.10.4 across alfred, alfred-live, and the root release files.

Changes

Timeout cleanup and 0.10.4 release alignment

Layer / File(s) Summary
Timeout cleanup path
alfred/src/policies/timeout.js, alfred/test/unit/timeout.test.js, alfred/CHANGELOG.md, CHANGELOG.md
Adds helper-based timeout scheduling, clears the runtime timer in finally, and adds tests and changelog notes for early completion and error-path cleanup.
0.10.4 package bumps
package.json, alfred/package.json, alfred/jsr.json, alfred-live/package.json, alfred-live/jsr.json, alfred-live/CHANGELOG.md, CHANGELOG.md
Bumps root, alfred, and alfred-live package and manifest versions to 0.10.4, updates the live dependency on @git-stunts/alfred, and adds matching changelog entries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • git-stunts/alfred#4: This earlier timeout work is directly related to the timeout() clock-abstraction and timing behavior changed here.

Poem

I hopped through timers, bright and spry,
and clipped the stray tick drifting by.
The clock still whispers, calm and neat,
while finished tasks leave no lost beat. 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.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 change: clearing default timeout timers in alfred.
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.

✏️ 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/timeout-system-clock-fallback

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
alfred/test/unit/timeout.test.js (1)

275-286: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Also pin the fast-reject path.

This covers early resolution, but the new finally block is also what clears the timer when fn rejects 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

📥 Commits

Reviewing files that changed from the base of the PR and between f597b27 and 9c74c47.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (10)
  • CHANGELOG.md
  • alfred-live/CHANGELOG.md
  • alfred-live/jsr.json
  • alfred-live/package.json
  • alfred/CHANGELOG.md
  • alfred/jsr.json
  • alfred/package.json
  • alfred/src/policies/timeout.js
  • alfred/test/unit/timeout.test.js
  • package.json

Comment thread alfred/src/policies/timeout.js Outdated
@flyingrobots flyingrobots merged commit 8bc06ee into main Jun 24, 2026
2 checks passed
@flyingrobots flyingrobots deleted the fix/timeout-system-clock-fallback branch June 24, 2026 21:21
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