Skip to content

fix: complete cancelled tasks after failed worker assignment - #20867

Merged
amaechler merged 3 commits into
apache:masterfrom
akasakariko:fix/hrtr-cancel-failed-assignment
Nov 11, 2026
Merged

amaechler merged 3 commits into
apache:masterfrom
akasakariko:fix/hrtr-cancel-failed-assignment

Conversation

@akasakariko

@akasakariko akasakariko commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #20773

Description

Record the cancellation status when a task is shut down during worker assignment so that a rejected assignment immediately completes the original future as FAILED and removes the task from both pending-task views

The assigning thread reads the cancellation status and decides whether to retry under statusLock, then completes the cancelled task outside the lock to avoid invoking completion callbacks while holding it

If the worker accepts the assignment, check the cancellation marker when it reports RUNNING and send the shutdown request outside the lock rather than waiting for the next TaskQueue management pass

Extend the existing in-flight shutdown test to cover both accepted and rejected assignments, including actual worker receipt of the shutdown request, the cancellation reason and release of the worker reservation for another task

Validation

  • Original rejected-assignment case reproduced the incomplete future on unpatched master
  • Before the review follow-up, the strengthened accepted-assignment case timed out waiting for the worker shutdown request while the rejected-assignment case passed
  • HttpRemoteTaskRunnerTest and WorkerHolderTest: 30 tests pass with retries disabled
  • Full indexing-service rerun: 3069 tests, 0 final failures or errors, 14 conditional skips or disabled cases and 3 flaky cases that passed on their second attempt using the project-default retry setting
  • The initial full-module run with retries disabled had failures in SeekableStreamSupervisorStateTest.testEmitNoticesQueueSize and WorkerTaskManagerTest.testTaskRun, then both suites passed separately with retries disabled, totaling 103 tests
  • The full rerun retried one autoscaler timing assertion in SeekableStreamSupervisorSpecTest and two parameter cases of WorkerTaskManagerTest.testTaskRun, with no changes to those unrelated tests
  • Checkstyle, PMD, dependency analysis, forbidden APIs, Animal Sniffer, Enforcer, SpotBugs and RAT checks pass for indexing-service and its reactor dependencies
  • Error Prone strict compilation passes for the changed module and its tests
  • JaCoCo diff coverage: 10 of 11 production lines and 5 of 8 branches covered, exceeding both 50% thresholds

Release note

Tasks cancelled during worker assignment are promptly marked failed when assignment is rejected, so they no longer inflate pending-task demand until the next storage sync

If the worker accepts the assignment, the cancellation is sent as soon as the task reports RUNNING instead of waiting for a later cleanup pass

Key changed classes
  • HttpRemoteTaskRunner
  • HttpRemoteTaskRunnerTest

This PR has:

  • been self-reviewed using the concurrency checklist
  • a release note entry in the PR description
  • updated existing unit tests to cover the cancellation handoff

@akasakariko akasakariko changed the title Fix cancelled tasks left pending after failed worker assignment fix: complete cancelled tasks after failed worker assignment Nov 8, 2026

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No actionable issues found in this review. The synchronized shutdown/assignment handoff correctly completes rejected in-flight assignments outside statusLock, and the focused test covers both accepted and rejected outcomes.

Reviewed 2 of 2 changed files.


This is an automated review by Codex GPT-5.6-Luna(max)

@FrankChen021 FrankChen021 added the Approval Recommended Used when AI completes a review and reports no findings label Nov 9, 2026

@amaechler amaechler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up! A couple of bot comments to consider.

@amaechler amaechler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐻

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A cancellation race remains in the accepted-assignment path. If the worker's initial RUNNING announcement arrives before its local RunNotice starts the task, the shutdown request can be ignored; the later RUNNING announcement does not retry it, allowing a cancelled task to execute.

Reviewed 2 of 2 changed files; findings in 1 file.

Validation: git diff --check passed. No builds or tests were run; this was a static review.

Severity Findings
P0 0
P1 1
P2 0
P3 0
Total 1

This is an automated review by Codex GPT-5.6-Luna(max)

After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.

case PENDING_WORKER_ASSIGN:
taskItem.setWorker(worker);
taskItem.setState(HttpRemoteTaskRunnerWorkItem.State.RUNNING);
shouldShutdownTask = taskItem.shutdownStatus != null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Retry shutdown after an early RUNNING announcement

Finding: The cancellation marker is checked only when the first RUNNING announcement transitions the work item from PENDING or PENDING_WORKER_ASSIGN. A worker can publish that first RUNNING update while the task is still only in its assigned queue; cancellation then sends a shutdown request before the worker task runner knows the task, so the request is ignored. The later RUNNING update sees an already-RUNNING work item and does not retry shutdown, allowing the cancelled task to execute.

Suggestion: Preserve cancellation intent for already-RUNNING work items and retry shutdown on subsequent RUNNING announcements until a terminal update is observed; add a test covering this ordering.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed 3a87965 to this branch. shutdown() now records the kill for RUNNING work items too, and the RUNNING arm resends the shutdown on every RUNNING report until the worker reports the task complete. The worker's second RUNNING report is published after taskRunner.run() has the task, so the resend lands. Both orderings have a test. Without it, the cancelled task runs until TaskQueue's storage sync (PT1M by default) drops the entry and the next management pass shuts it down.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @amaechler for pushing 3a87965, resending the shutdown on every RUNNING report until a terminal update covers the early announcement ordering

@FrankChen021 this should address the P1, could you take another look when you have a moment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 changed files at head 3a87965cba2ebda8424ee9afd91b8fa15117a552. The prior P1 is addressed: cancellation is recorded for RUNNING work items and later RUNNING reports resend shutdown, covering the assigned-queue announcement race. I found no further actionable issues.

@FrankChen021 FrankChen021 removed the Approval Recommended Used when AI completes a review and reports no findings label Nov 10, 2026
A worker announces an assigned task as RUNNING before its RunNotice hands the task to the task runner, and the runner ignores a shutdown request for a task it does not know yet. Record the kill for RUNNING work items as well, and send the shutdown again on every RUNNING report until the worker reports the task complete.
@FrankChen021 FrankChen021 added the Approval Recommended Used when AI completes a review and reports no findings label Nov 11, 2026

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up assessment

The prior P1 is resolved: cancellation is retained for RUNNING work items and subsequent RUNNING announcements retry shutdown, covering the early assigned-queue announcement race. No further actionable issues were found.

Reviewed 2 of 2 changed files.

Validation: git diff --check 490cbf0035e0c988c141ef146566706854811097..HEAD passed. No builds or tests were run; this was a static review.


This is an automated review by Codex GPT-5.6-Luna(max)

@amaechler
amaechler merged commit c951187 into apache:master Nov 11, 2026
45 of 46 checks passed
@github-actions github-actions Bot added this to the 40.0.0 milestone Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approval Recommended Used when AI completes a review and reports no findings Area - Ingestion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpRemoteTaskRunner leaves a task killed mid-assignment pending if the assignment fails

3 participants