Skip to content

fix(compile): keep StopSending graceful during parallel reader build - #27890

Merged
XuPeng-SH merged 3 commits into
mainfrom
fix/27261-terminal-owner
Aug 31, 2026
Merged

XuPeng-SH merged 3 commits into
mainfrom
fix/27261-terminal-owner

Conversation

@aptend

@aptend aptend commented Aug 31, 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:

issue #27261

What this PR does / why we need it:

The incident terminal error is not evidence of duplicate cleanup senders. A concrete fatal path exists when StopSending cancels a remote scan while ParallelRun is still constructing parallel readers. Reader construction returns context canceled before parallelScope is published, and the deferred source cleanup previously treated that raw cancellation as a pipeline failure. Connector cleanup then published EventError, so the fan-in receiver observed context canceled even though the query context was still active.

This PR normalizes cancellation at that pre-publication ownership boundary before cleanup chooses EventEnd versus EventError. StopSending cancellation is graceful, while real query cancellation and substantive failures remain terminal errors.

The deterministic regression exercises the actual scope/pipeline boundary: a real CancelPipelineSending call interrupts blocked reader construction while another genuine producer has already completed on the shared edge. It verifies that the receiver completes normally and the query stays alive. A negative-control test verifies that query cancellation is still propagated as context canceled.

For recurrence diagnosis, the same boundary now increments PipelineCleanupEventCounter using four fixed, low-cardinality classifications: internal cancellation, query cancellation, cancellation with a substantive cause, and unattributed cancellation. It also emits a warning through the existing cleanup rate limiter. The warning records the build phase, query and node identifiers, DOP, root operator, raw and normalized errors, pipeline/query context state and causes, and the selected terminal event. Query-specific values are log fields only and never metric labels.

Validation:

  • focused regression tests under the race detector with count=100;
  • full pkg/sql/compile tests;
  • full pkg/sql/compile tests under the race detector;
  • go vet ./pkg/sql/compile.

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

Request changes — the implementation is race-clean and bounded, but the causal regression is not closed and the new classification can hide a distinct-sender topology error.

recordTerminalFrom correctly recognizes a sender already present in terminalSenders, but after doneClosed it also returns PipelineTerminalAlreadyGraceful for a sender that has never been seen. Connector/Dispatch then accept that result through EndAccepted() and suppress the previous abort/warning path. Therefore these two materially different cases become indistinguishable:

  1. the same logical sender is cleaned twice (the intended idempotent case);
  2. a new distinct sender arrives after NilBatchCnt was exhausted because the expected sender count/topology is wrong.

In case 2 the receiver may already have terminated before a real producer finished. Treating the extra sender as successful can turn an observable protocol error into silent early completion/data loss or sibling cancellation; it can also mask the actual cause of #27261.

The current tests only invoke Reset twice manually on the same Connector/Dispatch. In the production paths I traced, one Pipeline cleanup already deduplicates operator resets with resetDone, and parallel workers are distinct cloned operator instances. I could not find the production ownership path that resets the same concrete sender twice. The incident evidence does not establish it either: the first LogReader context canceled messages begin before the only emitted connector-cleanup warning, so that warning may be aftermath. The failing window had multiple cleanup-send failures on a shared edge, but the current evidence does not distinguish duplicate sender from sender-count mismatch.

Please close this before merge with a deterministic regression at the real scope/pipeline boundary: reproduce the actual duplicate cleanup ownership while another genuine sender remains live, show the base behavior causes premature completion/cancellation, and show this head keeps the receiver/query alive. Also preserve explicit detection/telemetry for a previously unseen sender arriving after graceful completion (or demonstrate from the production topology why that state is impossible), instead of accepting it unconditionally as idempotent.

Validation performed on exact head 49b6e5cc98b1bc5bc31d552d4d1006fed7c1b69e: focused tests passed; all four owning packages passed under -race; the concurrent duplicate-sender test passed 100 iterations; Linux UT/SCA/BVT CI is green. Those results validate implementation mechanics, but not the missing production causal invariant above.

@mergify mergify Bot added the kind/bug Something isn't working label Aug 31, 2026
@aptend
aptend force-pushed the fix/27261-terminal-owner branch from 49b6e5c to 659d0e1 Compare August 31, 2026 09:25
@matrix-meow matrix-meow added size/M Denotes a PR that changes [100,499] lines and removed size/L Denotes a PR that changes [500,999] lines labels Aug 31, 2026
@aptend aptend changed the title fix(pipeline): make cleanup terminal recording idempotent fix(compile): keep StopSending graceful during parallel reader build Aug 31, 2026
@aptend

aptend commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

I rewrote the PR around the causal path identified after the review and removed the terminal-sender idempotence changes entirely. The new regression uses the real scope/pipeline boundary: StopSending interrupts BuildReaders before ParallelRun publishes the parallel scope, while another genuine sender has completed on the shared edge. Base behavior returns and publishes context canceled; this head normalizes only the internal pipeline cancellation before cleanup, while the query-cancellation control still publishes an error. Local focused race tests passed 100 iterations, and the full compile package passed normally, under -race, and with go vet.

aptend added 2 commits August 31, 2026 18:22
StopSending can cancel a remote scan while ParallelRun is still building readers. Normalize that internal pipeline cancellation before cleanup publishes the connector terminal event, while preserving real query cancellation as an error.
Count and rate-limit diagnostic warnings for pre-publication parallel-scope cancellations. Record the pipeline/query context states and chosen terminal event so a recurrence can confirm or falsify the StopSending hypothesis without high-cardinality metrics.

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

Deep re-review completed on exact head b4aac00. The previous request-changes concern is resolved: the terminal-sender idempotence changes and their unknown-sender acceptance path were removed entirely.

The replacement fix matches the concrete #27261 execution chain. ivf_create runs SELECT SAMPLE ... LIMIT n; one remote producer can satisfy LIMIT and trigger StopSending while another scan is still blocked in BuildReaders, before ParallelRun publishes the generated scope. At that ownership boundary the old cleanup converted the raw pipeline cancellation into EventError. This head normalizes it before cleanup, so only cancellation attributable to the canceled pipeline context while the query context remains active becomes graceful End.

Checked failure/cancellation controls:

  • query cancellation/deadline remains terminal through the query context;
  • a substantive pipeline cancel cause is restored and sent as Error;
  • an independent or mixed execution error is not suppressed (joined errors must be entirely cancellation-shaped and attributable);
  • source cleanup still runs exactly once when parallel-scope construction is unpublished, and receiver completion remains bounded;
  • diagnostics execute only on this failed/canceled construction path, use four fixed metric labels, and reuse the existing global warning limiter, so they do not add scan hot-path cost or high-cardinality metrics.

The deterministic test now exercises the real Scope/BuildReaders/Connector fan-in boundary with a genuine completed sibling plus query-cancel negative control. git diff --check passes and exact-head Linux UT, SCA, BVT, coverage, and CodeQL are green. A real IVF nightly should still confirm incident closure, but that is post-merge validation rather than a code-review blocker.

@mergify mergify Bot added the queued label Aug 31, 2026
@mergify

mergify Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-31 11:54 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-08-31 12:02 UTC · at e8d619d7578135808b714c7368ad60709482b845

This pull request spent 8 minutes 52 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 #27890 has been merged manually at 5ada591

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 5ada591 into main Aug 31, 2026
28 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/27261-terminal-owner branch August 31, 2026 12:02
@mergify mergify Bot removed the queued label Aug 31, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…atrixorigin#27890)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#27261

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

The incident terminal error is not evidence of duplicate cleanup
senders. A concrete fatal path exists when StopSending cancels a remote
scan while ParallelRun is still constructing parallel readers. Reader
construction returns context canceled before parallelScope is published,
and the deferred source cleanup previously treated that raw cancellation
as a pipeline failure. Connector cleanup then published EventError, so
the fan-in receiver observed context canceled even though the query
context was still active.

This PR normalizes cancellation at that pre-publication ownership
boundary before cleanup chooses EventEnd versus EventError. StopSending
cancellation is graceful, while real query cancellation and substantive
failures remain terminal errors.

The deterministic regression exercises the actual scope/pipeline
boundary: a real CancelPipelineSending call interrupts blocked reader
construction while another genuine producer has already completed on the
shared edge. It verifies that the receiver completes normally and the
query stays alive. A negative-control test verifies that query
cancellation is still propagated as context canceled.

For recurrence diagnosis, the same boundary now increments
PipelineCleanupEventCounter using four fixed, low-cardinality
classifications: internal cancellation, query cancellation, cancellation
with a substantive cause, and unattributed cancellation. It also emits a
warning through the existing cleanup rate limiter. The warning records
the build phase, query and node identifiers, DOP, root operator, raw and
normalized errors, pipeline/query context state and causes, and the
selected terminal event. Query-specific values are log fields only and
never metric labels.

Validation:

- focused regression tests under the race detector with count=100;
- full pkg/sql/compile tests;
- full pkg/sql/compile tests under the race detector;
- go vet ./pkg/sql/compile.

---------

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#27890)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#27261

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

The incident terminal error is not evidence of duplicate cleanup
senders. A concrete fatal path exists when StopSending cancels a remote
scan while ParallelRun is still constructing parallel readers. Reader
construction returns context canceled before parallelScope is published,
and the deferred source cleanup previously treated that raw cancellation
as a pipeline failure. Connector cleanup then published EventError, so
the fan-in receiver observed context canceled even though the query
context was still active.

This PR normalizes cancellation at that pre-publication ownership
boundary before cleanup chooses EventEnd versus EventError. StopSending
cancellation is graceful, while real query cancellation and substantive
failures remain terminal errors.

The deterministic regression exercises the actual scope/pipeline
boundary: a real CancelPipelineSending call interrupts blocked reader
construction while another genuine producer has already completed on the
shared edge. It verifies that the receiver completes normally and the
query stays alive. A negative-control test verifies that query
cancellation is still propagated as context canceled.

For recurrence diagnosis, the same boundary now increments
PipelineCleanupEventCounter using four fixed, low-cardinality
classifications: internal cancellation, query cancellation, cancellation
with a substantive cause, and unattributed cancellation. It also emits a
warning through the existing cleanup rate limiter. The warning records
the build phase, query and node identifiers, DOP, root operator, raw and
normalized errors, pipeline/query context state and causes, and the
selected terminal event. Query-specific values are log fields only and
never metric labels.

Validation:

- focused regression tests under the race detector with count=100;
- full pkg/sql/compile tests;
- full pkg/sql/compile tests under the race detector;
- go vet ./pkg/sql/compile.

---------

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#27890)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#27261

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

The incident terminal error is not evidence of duplicate cleanup
senders. A concrete fatal path exists when StopSending cancels a remote
scan while ParallelRun is still constructing parallel readers. Reader
construction returns context canceled before parallelScope is published,
and the deferred source cleanup previously treated that raw cancellation
as a pipeline failure. Connector cleanup then published EventError, so
the fan-in receiver observed context canceled even though the query
context was still active.

This PR normalizes cancellation at that pre-publication ownership
boundary before cleanup chooses EventEnd versus EventError. StopSending
cancellation is graceful, while real query cancellation and substantive
failures remain terminal errors.

The deterministic regression exercises the actual scope/pipeline
boundary: a real CancelPipelineSending call interrupts blocked reader
construction while another genuine producer has already completed on the
shared edge. It verifies that the receiver completes normally and the
query stays alive. A negative-control test verifies that query
cancellation is still propagated as context canceled.

For recurrence diagnosis, the same boundary now increments
PipelineCleanupEventCounter using four fixed, low-cardinality
classifications: internal cancellation, query cancellation, cancellation
with a substantive cause, and unattributed cancellation. It also emits a
warning through the existing cleanup rate limiter. The warning records
the build phase, query and node identifiers, DOP, root operator, raw and
normalized errors, pipeline/query context state and causes, and the
selected terminal event. Query-specific values are log fields only and
never metric labels.

Validation:

- focused regression tests under the race detector with count=100;
- full pkg/sql/compile tests;
- full pkg/sql/compile tests under the race detector;
- go vet ./pkg/sql/compile.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
XuPeng-SH added a commit that referenced this pull request Nov 9, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue #32389

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

Backport the missing behavior from #27890 and #28926 to 4.2-dev. A
normal StopSending during parallel reader construction must not publish
a terminal execution error while the query remains live.

Normalize the result before the pre-publication ParallelRun cleanup
chooses End versus Error. Construct readers from the source scope
context so reader cancellation and cleanup classification observe the
same lifetime. Reuse the branch-local normalizer and retain rate-limited
cancellation diagnostics; do not backport main's newer outcome/protocol
refactors. Real query cancellation, deadline, storage errors and mixed
primary/cancellation errors remain terminal.

Validation (base 6d4dc2f):
- Base behavior: FAIL — new deterministic construction-cancellation
regression and real local/remote reader-context boundary tests detect
the old behavior.
- PR-head behavior: PASS — eight focused tests; each also passes 100
race repetitions. Full pkg/sql/compile normal and race tests pass; full
colexec and connector normal tests pass.
- BVT: test/distributed/cases/vector/vector_ivf_sampling_cancel.sql and
.result. Both standalone and two-CN topology pass 27/27 assertions twice
on the same instance; teardown checked after each run. Service logs
confirm SAMPLE 100 PERCENT LIMIT 10000, using 10,001 low-dimensional
vectors and sequential L2/cosine/IP creation/query/drop.
- Static/build: make cgo, service build, compile go vet, incremental
golangci-lint and git diff --check pass.
- Retained unrelated failure: full pkg/vm/process normal tests hit
TestHarvestExternalCounterSetAndTerminalWait at
operator_analyzer_test.go:552 (strictly positive duration around an
empty callback). The unchanged baseline reproduces the same assertion in
46/100 targeted runs; no test was skipped or modified to hide it.
- Earlier setup/oracle attempts retained locally: macOS binary loader
path corrected; IP BVT ordering corrected to ASC for this branch's
negative dot-product function; direct race binary cwd corrected to the
package directory for resource-relative tests. Final checks above use
the corrected inputs.

QA required: yes — the original fixed-version SIFT 1M/128-dimensional
TKE scenario is NOT RUN in this PR preparation. These tests close the
known missing mechanisms; they do not prove the first cancellation owner
of the reported incident or that the original intermittent failure has
disappeared. Keep this PR Draft and #32389 open pending QA. No
performance or zero-intermittency claim.

No public API, SQL syntax, configuration, catalog, storage format, retry
or timeout change.


Review follow-up: the cancellation fixture now owns and closes its
private AutoIncrementService before restoring the prior runtime. Worker
cleanup cancels and joins through a separate completion channel even
when the result is unread. A regression checks service closure,
private-runtime reference removal, old-runtime restoration, and worker
completion after an early subtest return. This follow-up changes only
tests; the product and SQL BVT evidence above is reused.

Follow-up validation: four directly affected tests pass normally and
each passes 100 race repetitions; full pkg/sql/compile normal and race
pass; incremental lint and git diff --check pass. Astra medium re-review
confirms the original P2 is resolved with no remaining confirmed
blocker.

---------

Co-authored-by: XuPeng-SH <[email protected]>

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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants