fix(executor): stop counting skipped tasks twice on retry runs - #251
Merged
Conversation
A retry run creates a new executor over the full task set with pre-completed tasks. A pending task whose dependency is already failed takes the skip path in the first startReadyTasks call, which marks it failed and reports it on the completion channel. The finished counter was seeded after that call, so the skip was counted twice and the run could end while other tasks were still starting, panicking with "send on closed channel" when the next task emitted its preamble. Seed the counter before starting tasks, and stop closing the output channel: draining now ends on a dedicated signal, so a line from a goroutine that outlives the run is dropped rather than fatal.
jakobkollerup
approved these changes
Aug 10, 2026
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
Retrying a failed task from the TUI (
r) could crash the whole run:Cause
A retry run builds a new executor over the full task set and calls
WithPreCompleted(succeeded, failed). InsideExecutethe ordering was:startReadyTasks— a pending task whose dependency is alreadystatusFailedtakes the skip path, which setsstatus = statusFailedand reports aCommandResultoncompletionCh.finishedwas seeded by counting tasks already instatusSuccess/statusFailed.A task skipped during that first call was therefore counted twice: once by the seed, once when its completion was read in the main loop. On a first run nothing is pre-failed so the skip path never fires that early; on a retry run it does, as soon as a re-queued task has a sibling dependency that failed and is not being retried.
finishedthen reachestotalwhile other retried tasks are still starting, the loop exits,close(outputCh)runs, and the next task goroutine to come off the parallelism semaphore panics inemitTaskPreamble— which is why the crash lands in the preamble of a task that had only just begun.Fix
finished/totalbeforestartReadyTasks, so a startup skip is counted only via its completion. This is the actual bug.outputCh. Draining now ends on a dedicateddrainStopsignal, with the buffer flushed on exit as before. A goroutine that outlives the run drops its line instead of killing the process, so a future accounting slip costs a log line rather than the session.Two regression tests: against the unfixed
executor.goboth fail with the identical panic; with the fixgo test -race -count=3 ./...is clean.Not addressed here
completionCh <- ...is an unconditional send on the main goroutine. The buffer islen(tasks)*2, so repeated retry/skip cycles could in principle exhaust it and deadlock instead of panicking. Aselectcannot fix that from the main goroutine; it needs a different shape.WithPreCompletedmarks skipped tasks as plainstatusFailedwithskipped = false, soresetForRetry's cascade will not re-queue a skipped dependent on a second retry round.