Skip to content

fix: a rerun does not save the task it runs again after queueing it - #1885

Merged
v1r3n merged 3 commits into
mainfrom
fix/rerun-save-only-reset-tasks
Nov 26, 2026
Merged

v1r3n merged 3 commits into
mainfrom
fix/rerun-save-only-reset-tasks

Conversation

@v1r3n

@v1r3n v1r3n commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Pull Request type

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • WHOSUSING.md
  • Other (please describe):

NOTE: Please remember to run ./gradlew spotlessApply to fix any format violations.

Changes in this PR

rerunWF saves the task it reruns as SCHEDULED and queues it. finalizeRerun, its last step, then saved every task of the workflow, that task included, from the copy the rerun held in memory:

executionDAOFacade.updateTasks(workflow.getTasks());

A worker can take the task as soon as it is queued. If it finishes before that save, its COMPLETED is overwritten with SCHEDULED. Its update has already removed the queue message, so the task sits SCHEDULED with nothing on its queue until the sweeper repairs it.

finalizeRerun now saves only the tasks it resets itself (the failed and canceled siblings it sets back to SCHEDULED or IN_PROGRESS). What it resets and queues is unchanged. The rerun task, saved and queued by rerunWF, is not saved again.

How it was found: on the native workflows branch (#1832), whose retry reruns the failed task in place through rerunWF, an immediate retry stalled until the sweeper in 2 of 20 and 1 of 25 runs. Any rerun from a task can hit the same window when a worker is fast enough. A build that logged each removal from the task's queue showed the order: the worker's COMPLETED update removed the message, then the rerun's bulk save put SCHEDULED back. With this change, 40 of 40 completed within 1.8 s, the task ran exactly twice, and there were no sweeper repairs.

Tests

  • TestWorkflowExecutor.testRerunDoesNotSaveTheTaskItRunsAgainAfterQueueingIt records every save of the rerun task after it was queued. It fails on main (updateTasks saves it again) and passes with this change.
  • core: 992 tests pass.
  • The test-harness specs that exercise rerun (SubWorkflowRerunSpec, HierarchicalForkJoinSubworkflowRerunSpec, ForkJoinSpec, WorkflowAndTaskConfigurationSpec, JsonJQTransformSpec, QueueResiliencySpec): 71 tests pass.

Alternatives considered

  • Save all tasks before queueing the rerun task. That moves rerunWF's queueing after finalizeRerun, and changes the order the existing comments rely on: tasks are saved before they are queued, so an async worker never reads a stale CANCELED/FAILED state.
  • Re-read the task before the bulk save. It narrows the window but does not close it.

rerunWF saves the task it reruns as SCHEDULED and queues it. finalizeRerun,
its last step, then saved every task of the workflow, that task included,
from the copy the rerun held in memory. A worker that took the task at once
and finished it had its COMPLETED overwritten with SCHEDULED, while its
update had already removed the queue message: the task waited for the
sweeper to repair it.

finalizeRerun now saves only the tasks it resets itself. What it resets and
queues is unchanged.

Seen live on retries that rerun a failed task immediately: 2 of 20 and 1 of
25 stalled until the sweeper; with the change, 40 of 40 completed within
1.8 s with the task run exactly twice and no sweeper repairs.
testRerunDoesNotSaveTheTaskItRunsAgainAfterQueueingIt fails without the
change.
@v1r3n
v1r3n merged commit 38d6b04 into main Nov 26, 2026
13 checks passed
@v1r3n
v1r3n deleted the fix/rerun-save-only-reset-tasks branch November 26, 2026 02:29
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.

2 participants