Skip to content

fix(runners,tasks): critical requeue and finalization bugs#4005

Draft
cursor[bot] wants to merge 2 commits into
developfrom
cursor/critical-bug-investigation-3fcb
Draft

fix(runners,tasks): critical requeue and finalization bugs#4005
cursor[bot] wants to merge 2 commits into
developfrom
cursor/critical-bug-investigation-3fcb

Conversation

@cursor

@cursor cursor Bot commented Jul 4, 2026

Copy link
Copy Markdown

Summary

Cherry-picks validated fixes for three critical runner/task bugs still present on develop.

Bugs fixed

1. Duplicate dispatch on ErrAllRunnersBusy

When every runner is at capacity, requeueing a task enqueued it while it still sat in the running set, then sent EventTypeRequeued from a defer. A concurrent queue tick could ClaimAndDequeue the task in that window and start a second dispatch on the same TaskRunner.

Fix: Release running/active bookkeeping via onTaskStop before enqueueing and notify the pool synchronously.

2. Stopped → failed on runner after terminated_jobs

When applyTerminatedJobs emergency-stops a job and Run() unwinds with an error, the error path overwrote stopped with failed.

Fix: Add finalizeAfterRun that respects an already-finished status.

3. HA pool state leak in failTaskRunnerLost

When failTaskRunnerLost wins the finalize lock but the DB already has a terminal status, it bailed without completing finalization, leaking pool/Redis state and skipping autorun children.

Fix: Complete finalization via finalizeRemoteTaskLocked when status is already terminal.

Validation

  • go test ./services/tasks/... ./services/runners/... — all pass

Recent commits inspected

Since last inspection (8323a87d): OIDC dep bump, Renovate custommanager, Dockerfile paramiko — no new critical issues.

Open in Web View Automation 

cursoragent and others added 2 commits July 4, 2026 11:01
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>
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