Skip to content

fix(tooling): unref background timers + raise pre-commit timeout budgets - #5484

Merged
bokelley merged 1 commit into
mainfrom
fix/precommit-unref-background-timers
Jun 11, 2026
Merged

bokelley merged 1 commit into
mainfrom
fix/precommit-unref-background-timers

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Root-cause fix for the sporadic vitest pre-commit teardown hang (#2541), which #2542 mitigated with --pool=threads + a shell timeout but left the actual handles in place.

The bug

Seven background setInterval loops were missing .unref():

  • crawler.ts — periodic crawl, catalog crawl, manager-revalidation
  • luma/sync.ts — calendar sync
  • addie/jobs/scheduler.ts — periodic job runs
  • scheduled/auto-provision-digest.ts, scheduled/seat-request-reminders.ts

They're lazy (don't fire at import), but a test that imports-and-triggers one (e.g. luma-sync.test.ts, training-agent.test.ts) leaves a live timer in the vitest worker, whose event loop then never drains at exit — the zombie-worker hang #2541 documented (37 zombies across workspaces, some running 2 days). 12+ sibling intervals already .unref(); these were just inconsistent. Since the server stays alive via its HTTP listener (never these timers), .unref() is correct in production too.

Also

Raises the pre-commit with-timeout budgets — test:unit 60→180s, precommit:server-unit 120→240s. The suites legitimately grew past the caps set in #2542, so under multi-workspace CPU contention they were SIGTERM'd mid-run even without a hang. The timeout stays as a generous catastrophic-hang guard, not a normal-run tripwire.

Validation

This PR's own commit passed its pre-commit gate on the first attempt at load avg 41 — where commits on main's 60s budget needed a load-26 window. luma-sync and the affected modules' tests stay green; typecheck clean. No wire/schema/runtime-contract change → no-bump changeset.

🤖 Generated with Claude Code

Root-cause fix for the sporadic vitest pre-commit teardown hang (#2541): 7 background setInterval loops (crawler x3, luma/sync, addie/jobs/scheduler, 2 scheduled/*) were missing .unref(), so a test that triggers one keeps the worker's event loop alive at exit. These are server-internal background loops (the server stays alive via its HTTP listener, not these timers), so unref is correct in production and matches the 12+ siblings that already do it.

Also raises with-timeout budgets (test:unit 60->180s, server-unit 120->240s): the suites grew past the caps set in #2542, so under multi-workspace CPU contention they were SIGTERM'd mid-run even without a hang.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@aao-release-bot aao-release-bot 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.

Clean root-cause fix for the #2541 zombie-worker hang. .unref() on a lazy background loop is the right shape — the server is held alive by its HTTP listener, never these timers, so this is correct in production and just makes the seven loops consistent with the 12+ siblings (index.ts:61, worker-watchdog.ts:147) that already do it.

Things I checked

  • All seven setInterval .unref() placements land on the right handle, immediately after assignment. code-reviewer: placements correct, no production risk.
  • No wire/schema/docs/reference/build-script change → not a wire-touching PR, so the empty-front-matter no-bump changeset is the correct call, not a missing one.
  • crawler.ts probe setTimeouts (L851–L1048) correctly left alone — short-lived Promise.race reject timers, not retained handles.
  • package.json budget bumps (test:unit 60→180s, precommit:server-unit 120→240s) are a catastrophic-hang guard, not a normal-run tripwire. No correctness impact.
  • typecheck/affected-module tests green per the PR's own pre-commit run.

Follow-ups (non-blocking — file as issues)

  • Two delayed-start setTimeout wrappers in the touched files are still not unref'd. auto-provision-digest.ts:48 schedules the setInterval inside a 5-minute INITIAL_DELAY_MS setTimeout — that wrapper keeps the worker's event loop alive for up to 5 min before the now-unref'd inner interval ever exists. Same pattern at scheduler.ts:273 (job.initialTimeoutId = setTimeout(runJob, initialDelayMs) when config.initialDelay is set). No current test triggers either path, so the gap is latent — but the changeset's "root-cause fix" framing slightly overstates what ships while those two siblings can still zombie a worker. initialTimeoutId?.unref() / job.initialTimeoutId?.unref() closes it.

Minor nits (non-blocking)

  1. Optional chaining is unnecessary. intervalId?.unref() — the variable is assigned setInterval(...)'s return on the prior line and typed ReturnType<typeof setInterval>, so it's never undefined and never a number (that's DOM-lib typing). Repo convention is plain .unref(). Harmless, just inconsistent with the siblings you're matching.

LGTM. Follow-ups noted below.

@bokelley
bokelley merged commit 4361c48 into main Jun 11, 2026
28 checks passed
@bokelley
bokelley deleted the fix/precommit-unref-background-timers branch June 11, 2026 15:35
@mintlify

mintlify Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
adcp 🔴 Failed – Jun 11, 2026, 4:07 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

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