fix(runners,tasks): duplicate dispatch, terminal status overwrite, and HA finalization leaks#4028
Draft
cursor[bot] wants to merge 2 commits into
Draft
fix(runners,tasks): duplicate dispatch, terminal status overwrite, and HA finalization leaks#4028cursor[bot] wants to merge 2 commits into
cursor[bot] wants to merge 2 commits into
Conversation
When every runner is at capacity, ErrAllRunnersBusy requeued tasks by enqueueing them while they still sat in the running set, then sending EventTypeRequeued from a defer. A periodic queue tick could ClaimAndDequeue the task in that window and start a second dispatch on the same TaskRunner. Release running/active bookkeeping before enqueueing and notify the pool synchronously, matching the reconciler requeue paths. Co-authored-by: Denis Gukov <fiftin@outlook.com>
…finalization Runner client: when applyTerminatedJobs emergency-stops a job and Run() unwinds with an error, the error path overwrote stopped with failed. Add finalizeAfterRun that respects an already-finished status. HA reconciler: when failTaskRunnerLost wins the finalize lock but the DB already has a terminal status, complete finalization instead of bailing so pool/Redis state and autorun children are not leaked. Harden offline requeue with a pre-mutation DB re-check and rollback on persist failure. Co-authored-by: Denis Gukov <fiftin@outlook.com>
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.
Summary
Fixes three critical runner/task correctness bugs still present on
developafter PR #4023/#4024. These were previously identified by the bug-inspection automation but never merged.Bugs and impact
1. Duplicate dispatch on
ErrAllRunnersBusyWhen every runner is at capacity, the task server requeued tasks by calling
Enqueuewhile they still sat in the running set, then sentEventTypeRequeuedfrom a defer. A concurrent queue tick couldClaimAndDequeuethe task in that window and start a second dispatch on the sameTaskRunner.Trigger: Launch multiple remote tasks when all runners are busy; a periodic queue tick can double-dispatch the same task.
2. Stopped → failed after
terminated_jobsemergency stopOn the runner client, when
applyTerminatedJobsemergency-stops a job andRun()unwinds with an error, the error path overwrote an already-terminalstoppedstatus withfailed.Trigger: Server tells runner to emergency-stop a reassigned/orphaned job; runner reports
failedinstead ofstopped, breaking workflow edges and user-visible status.3. HA pool state leak in
failTaskRunnerLostWhen the reconciler won the finalize lock but the DB already had a terminal status (e.g. runner report on another node),
failTaskRunnerLostreturned early without completing finalization. Pool/Redis state (running set, claims) and autorun children could leak.Trigger: HA deployment; runner goes offline while another node finalizes the task; reconciler observes finished DB row but leaves stale pool state.
Root cause
ErrAllRunnersBusy, offline runner requeue, undispatched requeue) enqueued before releasing running/active bookkeeping.job_poolerror handler did not respect an already-finished status after emergency stop.failTaskRunnerLosttreated an already-finished DB status as a no-op instead of completingfinalizeRemoteTaskLocked.Fix
onTaskStop) before enqueueing on all requeue paths; notify pool synchronously withEventTypeRequeued.finalizeAfterRunon the runner client to preserve terminal status whenRun()returns an error.failTaskRunnerLostsees a finished status, callfinalizeRemoteTaskLockedto release pool state.End != nilcleanup infinalizeRemoteTaskLockedoutside HA-only guard.Validation
go test ./services/tasks/... ./services/runners/... ./api/runners/...— all passTestTaskRunner_ErrAllRunnersBusy_ReleasesRunningBeforeEnqueue,TestRunningJob_finalizeAfterRun_KeepsFinishedStatusOnRunError, reconciler HA finalization tests