Repository navigation
fix(tooling): unref background timers + raise pre-commit timeout budgets - #5484
Merged
Merged
Conversation
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]>
Contributor
There was a problem hiding this comment.
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-livedPromise.racereject timers, not retained handles. - package.json budget bumps (
test:unit60→180s,precommit:server-unit120→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
setTimeoutwrappers in the touched files are still not unref'd.auto-provision-digest.ts:48schedules thesetIntervalinside a 5-minuteINITIAL_DELAY_MSsetTimeout— 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 atscheduler.ts:273(job.initialTimeoutId = setTimeout(runJob, initialDelayMs)whenconfig.initialDelayis 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)
- Optional chaining is unnecessary.
intervalId?.unref()— the variable is assignedsetInterval(...)'s return on the prior line and typedReturnType<typeof setInterval>, so it's neverundefinedand never anumber(that's DOM-lib typing). Repo convention is plain.unref(). Harmless, just inconsistent with the siblings you're matching.
LGTM. Follow-ups noted below.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
setIntervalloops were missing.unref():crawler.ts— periodic crawl, catalog crawl, manager-revalidationluma/sync.ts— calendar syncaddie/jobs/scheduler.ts— periodic job runsscheduled/auto-provision-digest.ts,scheduled/seat-request-reminders.tsThey'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-timeoutbudgets —test:unit60→180s,precommit:server-unit120→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-syncand the affected modules' tests stay green; typecheck clean. No wire/schema/runtime-contract change → no-bump changeset.🤖 Generated with Claude Code