Skip to content

fix(dispatch): preserve terminal results for late remote receivers - #28326

Merged
XuPeng-SH merged 3 commits into
mainfrom
fix/28313-remote-dispatch-terminal
Sep 7, 2026
Merged

XuPeng-SH merged 3 commits into
mainfrom
fix/28313-remote-dispatch-terminal

Conversation

@aptend

@aptend aptend commented Sep 7, 2026 •

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 #28313

What this PR does / why we need it:

An empty recursive join build can finish a preregistered dispatch before its remote receiver attaches. Normal pipeline cleanup cancels the local context, and a late notify incorrectly turns that cancellation into Error 20101: internal error: convert go error to mo error context canceled instead of returning an empty result.

Publish an immutable terminal result for each dispatch registration before cleanup can wait. Attached and late receivers consume that result, while registration rollback preserves its failure cause. Capture the registration's original cancellation context so late notifications cannot cancel a reused process. Genuine execution errors, request cancellation, and connection failures remain errors; the existing End/Error wire format is unchanged.

Add deterministic tests for completion before/after attachment, waiter cleanup, rollback, cancellation, and process reuse. The SQL regression uses the original recursive query with small synthetic tables and patched statistics, and checks that remote receiver attachment actually occurs.

Validation on commit 9bc213ea37:

  • Same SQL regression on clean main 3d67664696: fails on the first empty-result query with the matching 20101 error.
  • Fixed SQL regression: passes all nine queries across the 500-row, zero-row, and restored 500-row phases on the shared multi-CN cluster (14.2 seconds including startup).
  • Full pkg/sql/colexec, pkg/sql/colexec/dispatch, and pkg/sql/compile test suites pass normally and under -race using the repository CGo wrapper.
  • Eight focused lifecycle/concurrency tests each pass 100 repetitions under -race.
  • CI follow-up 14595165fa: close each SQL result set with a scoped defer; the SQL regression and focused sqlclosecheck/rowserrcheck validation pass locally.

@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 →

@XuPeng-SH XuPeng-SH 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.

Reviewed exact head 14595165fa1041371992ce35e0337b9d6a3fabb0. No confirmed blocking issue found.

The fix addresses the correct invariant: cancellation of a local pipeline context during normal cleanup is not the source's execution result. A registration-generation-owned terminal publishes the actual Reset result once; its done-channel close establishes visibility of the immutable error before readers inspect it. Publication precedes cleanup operations that can wait for consumers, avoiding a terminal-result/cleanup wait cycle.

I checked attached and late-notify paths, first-result/duplicate behavior, partial registration rollback, request cancellation and connection loss, owner-specific registry cleanup, waiter retention/release, and operator/process reuse. Capturing the original cancel function and terminal avoids dereferencing a reused Process for terminal waiting or cancellation. Ready-to-finished retains a result for the late consumer, whereas final registration cleanup and the last published waiter release provide the reclamation boundary. Delayed cleanup is guarded by the owner channel and cannot remove a replacement generation. Existing wire End/Error encoding is unchanged, and external request cancellation is explicitly rechecked after terminal readiness.

The deterministic tests cover before/after attachment, finished registration with an existing waiter, source failure, cancellation/deadline, rollback without Reset, immutable first outcome, and replacement-generation safety. The SQL regression keeps the recursive query shape, checks nonempty → empty → restored results, and verifies actual remote attachment rather than treating a local-only execution as proof. The latest increment correctly scopes result-set Close with defer.

Cost is per registration (terminal object/channel and existing registry synchronization), not per transmitted row or batch. No new polling loop or background worker is introduced. I did not identify a concrete new memory-retention, deadlock or error-loss blocker in the inspected lifecycle.

Evidence in this round: full diff and relevant registration/Reset/notify/waiter/caller source review, test inspection, and git diff --check. The PR reports clean-main falsification plus normal/race suites and repeated lifecycle tests; these are reported author evidence, not fresh executions by this reviewer. I did not rebuild/run a native cluster or race suite and did not wait for CI.

@mergify mergify Bot added the queued label Sep 7, 2026
@mergify

mergify Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-07 11:14 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-07 11:40 UTC · at 9561bb177da6b590fb6e0b8e0c38cb7efc0cc7b7

This pull request spent 25 minutes 42 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

Pull request #28326 has been merged manually at 4503c3b

Failing checks:

Hint

You were too fast!

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 4503c3b into main Sep 7, 2026
33 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/28313-remote-dispatch-terminal branch September 7, 2026 11:39
@mergify mergify Bot removed the queued label Sep 7, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…atrixorigin#28326)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28313

## What this PR does / why we need it:

An empty recursive join build can finish a preregistered dispatch before
its remote receiver attaches. Normal pipeline cleanup cancels the local
context, and a late notify incorrectly turns that cancellation into
`Error 20101: internal error: convert go error to mo error context
canceled` instead of returning an empty result.

Publish an immutable terminal result for each dispatch registration
before cleanup can wait. Attached and late receivers consume that
result, while registration rollback preserves its failure cause. Capture
the registration's original cancellation context so late notifications
cannot cancel a reused process. Genuine execution errors, request
cancellation, and connection failures remain errors; the existing
End/Error wire format is unchanged.

Add deterministic tests for completion before/after attachment, waiter
cleanup, rollback, cancellation, and process reuse. The SQL regression
uses the original recursive query with small synthetic tables and
patched statistics, and checks that remote receiver attachment actually
occurs.

Validation on commit `9bc213ea37`:

- Same SQL regression on clean main `3d67664696`: fails on the first
empty-result query with the matching 20101 error.
- Fixed SQL regression: passes all nine queries across the 500-row,
zero-row, and restored 500-row phases on the shared multi-CN cluster
(14.2 seconds including startup).
- Full `pkg/sql/colexec`, `pkg/sql/colexec/dispatch`, and
`pkg/sql/compile` test suites pass normally and under `-race` using the
repository CGo wrapper.
- Eight focused lifecycle/concurrency tests each pass 100 repetitions
under `-race`.
- CI follow-up `14595165fa`: close each SQL result set with a scoped
defer; the SQL regression and focused `sqlclosecheck`/`rowserrcheck`
validation pass locally.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…atrixorigin#28326)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28313

## What this PR does / why we need it:

An empty recursive join build can finish a preregistered dispatch before
its remote receiver attaches. Normal pipeline cleanup cancels the local
context, and a late notify incorrectly turns that cancellation into
`Error 20101: internal error: convert go error to mo error context
canceled` instead of returning an empty result.

Publish an immutable terminal result for each dispatch registration
before cleanup can wait. Attached and late receivers consume that
result, while registration rollback preserves its failure cause. Capture
the registration's original cancellation context so late notifications
cannot cancel a reused process. Genuine execution errors, request
cancellation, and connection failures remain errors; the existing
End/Error wire format is unchanged.

Add deterministic tests for completion before/after attachment, waiter
cleanup, rollback, cancellation, and process reuse. The SQL regression
uses the original recursive query with small synthetic tables and
patched statistics, and checks that remote receiver attachment actually
occurs.

Validation on commit `9bc213ea37`:

- Same SQL regression on clean main `3d67664696`: fails on the first
empty-result query with the matching 20101 error.
- Fixed SQL regression: passes all nine queries across the 500-row,
zero-row, and restored 500-row phases on the shared multi-CN cluster
(14.2 seconds including startup).
- Full `pkg/sql/colexec`, `pkg/sql/colexec/dispatch`, and
`pkg/sql/compile` test suites pass normally and under `-race` using the
repository CGo wrapper.
- Eight focused lifecycle/concurrency tests each pass 100 repetitions
under `-race`.
- CI follow-up `14595165fa`: close each SQL result set with a scoped
defer; the SQL regression and focused `sqlclosecheck`/`rowserrcheck`
validation pass locally.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…atrixorigin#28326)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28313

## What this PR does / why we need it:

An empty recursive join build can finish a preregistered dispatch before
its remote receiver attaches. Normal pipeline cleanup cancels the local
context, and a late notify incorrectly turns that cancellation into
`Error 20101: internal error: convert go error to mo error context
canceled` instead of returning an empty result.

Publish an immutable terminal result for each dispatch registration
before cleanup can wait. Attached and late receivers consume that
result, while registration rollback preserves its failure cause. Capture
the registration's original cancellation context so late notifications
cannot cancel a reused process. Genuine execution errors, request
cancellation, and connection failures remain errors; the existing
End/Error wire format is unchanged.

Add deterministic tests for completion before/after attachment, waiter
cleanup, rollback, cancellation, and process reuse. The SQL regression
uses the original recursive query with small synthetic tables and
patched statistics, and checks that remote receiver attachment actually
occurs.

Validation on commit `9bc213ea37`:

- Same SQL regression on clean main `3d67664696`: fails on the first
empty-result query with the matching 20101 error.
- Fixed SQL regression: passes all nine queries across the 500-row,
zero-row, and restored 500-row phases on the shared multi-CN cluster
(14.2 seconds including startup).
- Full `pkg/sql/colexec`, `pkg/sql/colexec/dispatch`, and
`pkg/sql/compile` test suites pass normally and under `-race` using the
repository CGo wrapper.
- Eight focused lifecycle/concurrency tests each pass 100 repetitions
under `-race`.
- CI follow-up `14595165fa`: close each SQL result set with a scoped
defer; the SQL regression and focused `sqlclosecheck`/`rowserrcheck`
validation pass locally.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
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 size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] dev:distributed join aborts when remote dispatch targets another local pipeline tree

3 participants