Skip to content

fix(taskservice): unblock async completion on runner shutdown - #33040

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/task-runner-terminal-lifecycle
Nov 21, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/task-runner-terminal-lifecycle

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #32282
Fixes #32283

Part of #32278.

What this PR does / why we need it:

When a stopped runner's completion queue is full, an executor can block while sending its result after the completion worker has stopped. The stopper waits for that executor, so CN shutdown or generation revocation can hang. The existing execution-slot release before completion handoff lets scheduled SQL continue through its independent completion path when generic writes stall.

  • Allow runner shutdown or loss of task ownership to interrupt a blocked handoff. Keep shared execution slots available to independent work.
  • Keep retrying the same conditional completion write after storage errors while the task remains owned. Shutdown and cancellation can interrupt the retry delay.
  • Release slots and invocation references after rejected submission and shutdown. Build on the existing admission and terminal context cancellation from fix(task): preserve SQL task execution ownership #32331.

The live backlog of generic results during a persistent storage failure is outside this shutdown fix. For generic results that remain uncommitted at shutdown, HAKeeper still marks the existing running row failed once the assigned CN leaves the working pool. The SQL task executor retains its existing completion and recovery ownership.

Validation

  • Reproduced on current main with two gated executors and a capacity-one completion queue, including 10 repetitions under the race detector.
  • Exercised the real runner with a full completion queue and a writer held in a canceled call. Verified that a scheduled SQL firing commits successfully during the stall, the blocked generic publisher detaches before the writer returns, and Stop joins without marking uncommitted generic results complete.
  • Injected a transient completion write failure. Verified that the same failed result is written successfully on retry and its task body runs once.
  • A cancellation-registration probe confirmed that 1,000 duplicate and 1,000 full-queue admissions retain only the accepted task's registration, which is released on removal.
  • Passed race tests for pkg/taskservice, pkg/cnservice, and pkg/hakeeper/task on Linux with Go 1.27.1. The focused shutdown and retry scenarios passed 50 race repetitions, including shutdown during completion backoff with an execution retry parked.
  • Incremental gofmt, vet, golangci-lint, and molint passed.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 4ea9f1737a2e14d6362b901e130153727f425a96

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

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.

mo-bot review · mo-bot-local · review

Commit: 4ea9f1737a2e14d6362b901e130153727f425a96

Assessment: approve

The existing runner and stopper now cancel blocked completion sends and retry delays before Stop joins workers and drains their queues. Live generic completions still retry the same runner- and epoch-conditional write, and releasing the execution slot before handoff lets scheduled SQL publish through its own completion path. The shutdown and retry tests exercise both behaviors. HAKeeper retains recovery of generic rows when their assigned CN expires. The PR discussion adds no substantive concerns.

Model: gpt-6.2-sol / xhigh

Session: 01a1ee80-0d82-7030-a965-b51f496c3054 · slot 2 · generation 1

Validation:

  • Verified the clean frozen head, target and merge-base, complete patch, pinned policy, discussion coverage, and diff whitespace. Matched retained native inputs and passed the private /tmp and loopback preflight. Receipts checks/1795264149901998770-3.json, checks/1795264162225124208-2.json, and checks/1795264150307739242-89.json.

  • The complete pkg/taskservice suite passed under -race (taskservice-race.jsonl and taskservice-race.stderr, checks/1795264288807624835-2.json).

  • TestTaskRunnerStopWithFullCompletionQueue and TestTaskRunnerRetriesCompletionWithoutReexecuting each passed 100 individually selected race-detector repetitions (stop-race-repeat.jsonl and completion-retry-race-repeat.jsonl, checks/1795264398694831160-2.json and checks/1795264406484125050-2.json).

  • A retained, hashed overlay test passed under -race through the real runner with in-memory storage. With one completion in backoff and one execution retry parked, Stop canceled both contexts, released the parked slot, and left both uncommitted rows RUNNING (parked-retry-probe.stdout and parked-retry-probe.stderr, checks/1795264622598148602-2.json).

  • Passed the existing CN generation revocation tests for frontend shutdown ordering and in-flight runner start, the CN stopTask test, and HAKeeper TestReallocateExpiredTasks (runner-consumers.stdout and runner-consumers.stderr, checks/1795264576318155074-2.json).

Limitations:

  • The runner tests use in-memory storage and the CN and HAKeeper consumer checks exercise their components individually. A live multi-CN shutdown and recovery run was outside this local validation.

  • The supplied CI snapshot had the shared build and unit lanes in progress.

This branch was successfully deployed

No deployments
ci — 18362e40 Deployed Nov 21, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/enhancement kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

2 participants