Repository navigation
fix(daemon): keep one timer per worker type - #4412
Merged
ruvnet merged 1 commit intoOct 23, 2026
Merged
Conversation
setWorkerEnabled(type, true) called scheduleWorker() without clearing an existing timeout. this.timers kept only the newest handle, so each redundant enable leaked the previous timer; the leaked timer survived stop() (which only clears current map entries) and could run the worker again untracked. Disabling also left the type in pendingWorkers, and an in-flight run rescheduled itself even after disable (ruvnet#4410 automation scan).\n\nClear any existing timer at schedule time, avoid scheduling when a timer or in-flight run already owns the type, remove disabled types from the pending queue, and only reschedule after a run while the worker is still enabled. Add fake-timer regressions; baseline leaks three timers after three enables and keeps the disabled pending worker.
Merged
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.
Problem
The automation scan in #4410 found a timer-ownership bug in
WorkerDaemon:setWorkerEnabled(type, true)calledscheduleWorker()even when a timer for that type already existed.this.timerskeeps only one handle per type, so the previous timeout leaked.stop()becausestop()only clears handles currently in the map.setWorkerEnabled(type, false)removed the current timer but left the type inpendingWorkers, so a deferred run could still execute.Net effect: a redundant enable can produce two concurrent runs of one worker type, and a disabled/stopped worker can fire once more untracked.
Change
scheduleWorker()clears and removes any existing timer for the type before scheduling a new one.setWorkerEnabled(true)does nothing when a live timer or an in-flight run already owns that type.setWorkerEnabled(false)also removes the type frompendingWorkers.this.running && workerConfig.enabled, so disabling during a run cannot resurrect it.Tests
New
worker-daemon-duplicate-timers-4410.test.tsuses fake timers:setWorkerEnabled('map', true)calls leave 1 pending timer;pendingWorkers.Baseline (source stashed,
--no-cache): both tests fail — 3 timers after three enables, and the disabled worker remains queued. Candidate: 2/2 passed.No changes to worker intervals, scheduling order, or worker business logic.
Compatibility