Skip to content

fix: clear cached session state between clients - #27946

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-20022-prepared-cache-regression
Sep 1, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-20022-prepared-cache-regression

Conversation

@VioletQwQ-0

@VioletQwQ-0 VioletQwQ-0 commented Sep 1, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #20022

What this PR does / why we need it:

This follow-up closes the remaining prepared short-connection cache review gaps after PR #27916:

  • separates QueryService ResetSession from MySQL COM_RESET_CONNECTION: the Proxy cache reset starts with an empty database, while the client command continues to preserve its selected database;
  • generates the production-driver shape of a one-parameter binary COM_STMT_EXECUTE packet, including iteration-count 1, null bitmap, new-parameter flag, type, and value, and requires the real Frontend parser to accept it;
  • sends every one of 100 client generations through the real connectToBackendContext cached-login path, including cache authentication, SET CONNECTION ID, database restoration, tunnel traffic, STMT_CLOSE, QUIT, PING fence, ResetSession, cache publication, and the next login;
  • alternates two login databases and finishes with a login that specifies no database, where DATABASE() must return NULL; prepared state must be empty before every next client prepares again.

Validation:

  • PR base: 33af6ae3c0c23e4f277137460577ea64678f7ecf
  • exact head: 4e3e457b228bde8fcd6641f7d1aca3d546b9d529
  • falsification at pre-fix head 2cfed1bb14a3e58de1d8fc5da625d1338e689afc: FAIL because QueryService ResetSession retained must_not_leak
  • focused Frontend and Proxy regressions: PASS
  • Proxy 100-generation regression, count=10: PASS
  • focused Frontend and Proxy race regressions: PASS
  • full pkg/frontend and pkg/proxy: PASS
  • full pkg/frontend -race and pkg/proxy -race: PASS
  • go list, CGo-configured go build, go vet, and git diff --check: PASS
  • semantic preflight: PASS, diff hash a98f98d3e9a6175abfe2ec92efab67e06b15abcee9c61e02c2f5c2245eceff95

QA required: yes. These deterministic regressions do not replace the multi-CN, dual-Proxy prepared short-connection campaign required by #20022.

BVT: N/A. Ordinary SQL BVT cannot enable Proxy connection caching, generate binary prepared short connections, or assert physical backend reuse across client generations.

@mergify mergify Bot added the kind/test-ci label Sep 1, 2026
@VioletQwQ-0
VioletQwQ-0 marked this pull request as ready for review September 1, 2026 06:20
@mergify
mergify Bot requested a review from XuPeng-SH as a code owner September 1, 2026 06:20
@mergify
mergify Bot requested a review from gouhongshen as a code owner September 1, 2026 06:20
@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 →

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

Codex automated review

Revalidation at head 4e3e457, which is byte-identical to the previously approved head (git diff 4e3e457b..HEAD is empty; the delta contains no merge commits). Prior review history: my own Codex approval at this exact head with zero findings — there were no blockers to fix, withdraw, or reconcile. Discussion since the approval: no inline review threads, no human comments, no author replies; only pre-existing Qodo-bot paused notices. Fresh spot-checks of the worktree reconfirm the approved analysis: resetSessionWithContext (sole caller routine_manager.go:566, the QueryService ResetSession RPC used by Proxy cached-handoff) passes preserveDatabase=false, restoring the pre-#27736 DBNAME-clearing contract; resetConnectionWithContext (sole caller routine.go:460, COM_RESET_CONNECTION) passes preserveDatabase=true, matching MySQL semantics; routine_manager_test.go asserts must_not_leak does not survive QueryService ResetSession; conn_cache_test.go drives 100 client generations through the real cached-login path. PR remains mergeable; upstream movement via the recorded merge commit introduces no authored delta. Approval reconfirmed with no blocking or non-blocking findings.

@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 review completed on exact head 4e3e457b228bde8fcd6641f7d1aca3d546b9d529.

Root cause / contract split:

  • COM_RESET_CONNECTION and QueryService ResetSession replace the frontend Session generation but have different database semantics. The client command must retain the selected database; Proxy cache handoff must clear it before the next client runs SET CONNECTION ID and restores its requested database. Reusing one helper with preserveDatabase=true leaked the previous cached client database.
  • The new call split is complete: the wire command is the sole caller of resetConnectionWithContext(... preserveDatabase=true), while RoutineManager/QueryService remains on resetSessionWithContext(... preserveDatabase=false). The no-context reset already clears the database.

Correctness and counterexamples checked:

  • Failed reset restores previousDB; a partially retired generation is still fail-closed through the existing must-close error/cache rejection path.
  • Existing wire coverage proves COM_RESET_CONNECTION still preserves the database; the QueryService regression proves the previous database is absent in the replacement generation.
  • The Proxy regression drives 100 real cached-login generations through authentication, connection-ID reset, alternating database restoration, binary one-parameter prepare/execute parsing, statement close, causal PING fence, QUIT, ResetSession, cache publication, and final no-database login (DATABASE() IS NULL). A single backend connection and per-generation authentication are asserted.
  • Latest main has no changes in the three touched files since the PR merge-base.

Unhappy path / performance:

  • Q1: every per-generation client, tunnel, reader/event loop, prepared statement, process, cache, and backend has an explicit terminal owner; cleanup is idempotently guarded.
  • Q2: waits have context or one-second test guards; production admission/reset bounds are unchanged. No new lock or goroutine is added to production.
  • Q3: test channels and generations are fixed-capacity/fixed-count; production adds no queue, retained state, retry, metric cardinality, or logging. Runtime cost is only selecting the correct existing reset mode.

Evidence:

  • Latest substantive CI attempts are green, including Ubuntu UT, arm64 SCA, coverage, Connector/J reset E2E, Proxy BVT, and pessimistic multi-CN BVT.
  • Focused local exact-head tests passed: TestRoutineManagerResetSessionWaitsForRequestAfterResponseWrite, TestMySQLWireResetConnectionPreservesDatabase, and TestPreparedShortConnectionQuitProductionPath.

Scope note: these deterministic regressions do not replace the open #20022 multi-CN/dual-Proxy prepared-short-connection stability campaign. That remains the issue-closure QA gate, not a code-review blocker.

No blocking correctness, security/isolation, performance, liveness, resource-lifecycle, or test-quality issue found.

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

mergify Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-01 22:11 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-01 22:26 UTC · at 8e0b75d9e1835500c2431d0bbfe6decb29931776

This pull request spent 15 minutes 17 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 #27946 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Failing checks:

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

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

Incremental deep re-review completed on current head 8e0b75d9e1835500c2431d0bbfe6decb29931776 after Mergify merged main@3f6856cc5fa08f77d1dc98fd4f00b17c257b0f86.

  • range-diff shows both PR-authored commits are unchanged.
  • The full PR patch against the new base has the same SHA-256 (1968992972a6e6d452dd4bd0b0309b541f912e64fb84ad445ccffbf5afed523d) as the fully reviewed patch against the old base.
  • There are no files modified by both merge parents and no remerge/conflict-resolution delta. Therefore the reset-contract split, Proxy generation test, Q1-Q3 lifecycle analysis, performance assessment, and focused exact-head evidence from the preceding deep review remain semantically valid.

No new correctness, isolation, performance, liveness, resource-lifecycle, or test-quality blocker was introduced by the base merge. Approval reconfirmed without waiting for duplicate CI.

@XuPeng-SH
XuPeng-SH merged commit b86a0ae into matrixorigin:main Sep 1, 2026
26 of 27 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 1, 2026
XuPeng-SH added a commit that referenced this pull request Sep 2, 2026
## What changed

- give each ordinary MORPC unary request a complete read-timeout window
from admission/flush, instead of charging it for socket-idle time before
the request arrived
- distinguish admitted, successfully flushed, terminal-send-failed, and
expired requests while preserving established idle, internal, and
one-way behavior and giving stream writes their own bounded fallback
window
- make tenant-upgrade tests execute the observable pass directly, bound
every wait, and retain one end-to-end periodic-loop test
- make the merge scheduler test synchronize at the exact
executor/table-check boundary, use deterministic resource admission, and
prevent the test observer from blocking the scheduler
- separate frontend scheduling-preview computation from its production
100 ms best-effort latency policy so correctness tests do not race CI
descheduling

## Root cause and design

The embedded-cluster failure was not a restore or privilege failure.
`CREATE ACCOUNT` began during an already-running socket `Read` window
and inherited only the remainder of a configured 20-second timeout.
Merely increasing the timeout therefore could not guarantee a newly
admitted request a full response window.

For a normal response-expecting unary request, the backend now models
four relevant states:

1. admitted/queued or being flushed: retain the stale idle timeout
because work is already pending;
2. successfully flushed: start one full response window at the
successful flush timestamp;
3. terminal send failure: do not extend the connection lifetime;
4. expired response window: close the stalled backend; a newer admission
cannot rescue it.

The timestamp is published before the terminal send-completion flag. The
timeout scanner reads that flag before the timestamp, so it cannot
observe an old zero timestamp paired with the new success flag. The hot
path adds one atomic store only for normal unary traffic after a
successful flush; the cold timeout path scans the existing
lifecycle-bounded future set. Internal, one-way, probe-enabled,
cancellation, and close semantics remain unchanged. Probe-less streams
use one backend-level last-successful-flush window only when no unary
response window exists; an expired unary remains authoritative.

The other failures had the same broad symptom but different mechanisms:
correctness depended on a 20 ms asynchronous timer, host/cgroup memory
plus 3/5 ms scheduler polling, or a production 100 ms best-effort
preview timeout. Race instrumentation and package-parallel CI load can
delay those operations without changing their business result. Tests now
synchronize on observable state transitions, carry bounded parent
contexts, and explicitly distinguish expected cancellation from a hang
deadline.

The lifecycle audit found no new unbounded state or waits: future
ownership remains reference-counted and backend-close bounded; the
timeout scan covers only existing live futures; merge observation is
nonblocking and overflow-checked; every new test wait has a 10-second
guard.

Fixes #27963

## Test plan

Passed before rebase:

- MORPC state matrix under race:
`TestReadTimeoutDoesNotChargeIdleTimeToNewRequest` (`-count=100`)
- actual MORPC request tracking under race:
`TestReadTimeoutTracksRequestsWithoutLivenessProbe` (`-count=50`)
- merge scheduler under race: `TestScheduler` (`-count=100`)
- frontend strict-pool path under race:
`TestDirectSessionStrictPoolWithoutLabelSelectorFailsClosed`
(`-count=50`)
- all seven tenant-upgrade tests separately under race (`-count=20`
each)
- full package tests: `pkg/common/morpc`, `pkg/bootstrap`,
`pkg/frontend`, and `pkg/vm/engine/tae/db/merge`
- full `pkg/common/morpc` package under race
- targeted `go vet` for all four owning packages
- real embedded-cluster regression under race:
`TestAuthenticatedTestsReuseBaseCluster` and
`TestIssue26640ClusterRestoreRebindsSubscriptionPrivileges`

Rebased cleanly onto current `main` (`3f6856cc5f`). The two new upstream
commits touched only frontend code, so the affected closure was rerun
after rebase:

- full `pkg/frontend`: passed (13.974 s)
- strict-pool frontend counterexample under race, `-count=50`: passed
(1.296 s)
- full `pkg/bootstrap`: passed (18.523 s)
- `go vet ./pkg/frontend ./pkg/bootstrap`: passed
- real embedded-cluster regressions under race: passed (36.040 s)
- `git diff --check`: passed

No SQL result, wire API, or planner contract changes are introduced, so
no SQL BVT case is required; the embedded-cluster tests exercise the
public transport/session path directly.

CI reruns for the unrelated failures on #27949 and #27946 were triggered
separately; this PR does not wait for those reruns.

Post-review deterministic-clock closure (99e9d6c):

- removed the remaining 25/50 ms wall-clock oracle from TestScheduler;
policy composition now uses a lifetime longer than the test hang guard
- added TestSchedulerPolicyPatchExpirationUsesInjectedClock to prove
in-place policy merging, exact-deadline validity, and removal
immediately after the injected clock crosses the deadline
- focused normal tests passed; both scheduler tests passed separately
under race detection with count 100; the full merge package passed

---------

Co-authored-by: Claude Fable 5 <[email protected]>
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 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 matrixorigin#20022

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

This follow-up closes the remaining prepared short-connection cache
review gaps after PR matrixorigin#27916:

- separates QueryService `ResetSession` from MySQL
`COM_RESET_CONNECTION`: the Proxy cache reset starts with an empty
database, while the client command continues to preserve its selected
database;
- generates the production-driver shape of a one-parameter binary
`COM_STMT_EXECUTE` packet, including iteration-count `1`, null bitmap,
new-parameter flag, type, and value, and requires the real Frontend
parser to accept it;
- sends every one of 100 client generations through the real
`connectToBackendContext` cached-login path, including cache
authentication, `SET CONNECTION ID`, database restoration, tunnel
traffic, `STMT_CLOSE`, `QUIT`, PING fence, ResetSession, cache
publication, and the next login;
- alternates two login databases and finishes with a login that
specifies no database, where `DATABASE()` must return `NULL`; prepared
state must be empty before every next client prepares again.

Validation:

- PR base: `33af6ae3c0c23e4f277137460577ea64678f7ecf`
- exact head: `4e3e457b228bde8fcd6641f7d1aca3d546b9d529`
- falsification at pre-fix head
`2cfed1bb14a3e58de1d8fc5da625d1338e689afc`: FAIL because QueryService
ResetSession retained `must_not_leak`
- focused Frontend and Proxy regressions: PASS
- Proxy 100-generation regression, `count=10`: PASS
- focused Frontend and Proxy race regressions: PASS
- full `pkg/frontend` and `pkg/proxy`: PASS
- full `pkg/frontend -race` and `pkg/proxy -race`: PASS
- `go list`, CGo-configured `go build`, `go vet`, and `git diff
--check`: PASS
- semantic preflight: PASS, diff hash
`a98f98d3e9a6175abfe2ec92efab67e06b15abcee9c61e02c2f5c2245eceff95`

QA required: yes. These deterministic regressions do not replace the
multi-CN, dual-Proxy prepared short-connection campaign required by
matrixorigin#20022.

BVT: N/A. Ordinary SQL BVT cannot enable Proxy connection caching,
generate binary prepared short connections, or assert physical backend
reuse across client generations.

---------

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
## What changed

- give each ordinary MORPC unary request a complete read-timeout window
from admission/flush, instead of charging it for socket-idle time before
the request arrived
- distinguish admitted, successfully flushed, terminal-send-failed, and
expired requests while preserving established idle, internal, and
one-way behavior and giving stream writes their own bounded fallback
window
- make tenant-upgrade tests execute the observable pass directly, bound
every wait, and retain one end-to-end periodic-loop test
- make the merge scheduler test synchronize at the exact
executor/table-check boundary, use deterministic resource admission, and
prevent the test observer from blocking the scheduler
- separate frontend scheduling-preview computation from its production
100 ms best-effort latency policy so correctness tests do not race CI
descheduling

## Root cause and design

The embedded-cluster failure was not a restore or privilege failure.
`CREATE ACCOUNT` began during an already-running socket `Read` window
and inherited only the remainder of a configured 20-second timeout.
Merely increasing the timeout therefore could not guarantee a newly
admitted request a full response window.

For a normal response-expecting unary request, the backend now models
four relevant states:

1. admitted/queued or being flushed: retain the stale idle timeout
because work is already pending;
2. successfully flushed: start one full response window at the
successful flush timestamp;
3. terminal send failure: do not extend the connection lifetime;
4. expired response window: close the stalled backend; a newer admission
cannot rescue it.

The timestamp is published before the terminal send-completion flag. The
timeout scanner reads that flag before the timestamp, so it cannot
observe an old zero timestamp paired with the new success flag. The hot
path adds one atomic store only for normal unary traffic after a
successful flush; the cold timeout path scans the existing
lifecycle-bounded future set. Internal, one-way, probe-enabled,
cancellation, and close semantics remain unchanged. Probe-less streams
use one backend-level last-successful-flush window only when no unary
response window exists; an expired unary remains authoritative.

The other failures had the same broad symptom but different mechanisms:
correctness depended on a 20 ms asynchronous timer, host/cgroup memory
plus 3/5 ms scheduler polling, or a production 100 ms best-effort
preview timeout. Race instrumentation and package-parallel CI load can
delay those operations without changing their business result. Tests now
synchronize on observable state transitions, carry bounded parent
contexts, and explicitly distinguish expected cancellation from a hang
deadline.

The lifecycle audit found no new unbounded state or waits: future
ownership remains reference-counted and backend-close bounded; the
timeout scan covers only existing live futures; merge observation is
nonblocking and overflow-checked; every new test wait has a 10-second
guard.

Fixes matrixorigin#27963

## Test plan

Passed before rebase:

- MORPC state matrix under race:
`TestReadTimeoutDoesNotChargeIdleTimeToNewRequest` (`-count=100`)
- actual MORPC request tracking under race:
`TestReadTimeoutTracksRequestsWithoutLivenessProbe` (`-count=50`)
- merge scheduler under race: `TestScheduler` (`-count=100`)
- frontend strict-pool path under race:
`TestDirectSessionStrictPoolWithoutLabelSelectorFailsClosed`
(`-count=50`)
- all seven tenant-upgrade tests separately under race (`-count=20`
each)
- full package tests: `pkg/common/morpc`, `pkg/bootstrap`,
`pkg/frontend`, and `pkg/vm/engine/tae/db/merge`
- full `pkg/common/morpc` package under race
- targeted `go vet` for all four owning packages
- real embedded-cluster regression under race:
`TestAuthenticatedTestsReuseBaseCluster` and
`TestIssue26640ClusterRestoreRebindsSubscriptionPrivileges`

Rebased cleanly onto current `main` (`3f6856cc5f`). The two new upstream
commits touched only frontend code, so the affected closure was rerun
after rebase:

- full `pkg/frontend`: passed (13.974 s)
- strict-pool frontend counterexample under race, `-count=50`: passed
(1.296 s)
- full `pkg/bootstrap`: passed (18.523 s)
- `go vet ./pkg/frontend ./pkg/bootstrap`: passed
- real embedded-cluster regressions under race: passed (36.040 s)
- `git diff --check`: passed

No SQL result, wire API, or planner contract changes are introduced, so
no SQL BVT case is required; the embedded-cluster tests exercise the
public transport/session path directly.

CI reruns for the unrelated failures on matrixorigin#27949 and matrixorigin#27946 were triggered
separately; this PR does not wait for those reruns.

Post-review deterministic-clock closure (99e9d6c):

- removed the remaining 25/50 ms wall-clock oracle from TestScheduler;
policy composition now uses a lifetime longer than the test hang guard
- added TestSchedulerPolicyPatchExpirationUsesInjectedClock to prove
in-place policy merging, exact-deadline validity, and removal
immediately after the injected clock crosses the deadline
- focused normal tests passed; both scheduler tests passed separately
under race detection with count 100; the full merge package passed

---------

Co-authored-by: Claude Fable 5 <[email protected]>
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 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 matrixorigin#20022

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

This follow-up closes the remaining prepared short-connection cache
review gaps after PR matrixorigin#27916:

- separates QueryService `ResetSession` from MySQL
`COM_RESET_CONNECTION`: the Proxy cache reset starts with an empty
database, while the client command continues to preserve its selected
database;
- generates the production-driver shape of a one-parameter binary
`COM_STMT_EXECUTE` packet, including iteration-count `1`, null bitmap,
new-parameter flag, type, and value, and requires the real Frontend
parser to accept it;
- sends every one of 100 client generations through the real
`connectToBackendContext` cached-login path, including cache
authentication, `SET CONNECTION ID`, database restoration, tunnel
traffic, `STMT_CLOSE`, `QUIT`, PING fence, ResetSession, cache
publication, and the next login;
- alternates two login databases and finishes with a login that
specifies no database, where `DATABASE()` must return `NULL`; prepared
state must be empty before every next client prepares again.

Validation:

- PR base: `33af6ae3c0c23e4f277137460577ea64678f7ecf`
- exact head: `4e3e457b228bde8fcd6641f7d1aca3d546b9d529`
- falsification at pre-fix head
`2cfed1bb14a3e58de1d8fc5da625d1338e689afc`: FAIL because QueryService
ResetSession retained `must_not_leak`
- focused Frontend and Proxy regressions: PASS
- Proxy 100-generation regression, `count=10`: PASS
- focused Frontend and Proxy race regressions: PASS
- full `pkg/frontend` and `pkg/proxy`: PASS
- full `pkg/frontend -race` and `pkg/proxy -race`: PASS
- `go list`, CGo-configured `go build`, `go vet`, and `git diff
--check`: PASS
- semantic preflight: PASS, diff hash
`a98f98d3e9a6175abfe2ec92efab67e06b15abcee9c61e02c2f5c2245eceff95`

QA required: yes. These deterministic regressions do not replace the
multi-CN, dual-Proxy prepared short-connection campaign required by
matrixorigin#20022.

BVT: N/A. Ordinary SQL BVT cannot enable Proxy connection caching,
generate binary prepared short connections, or assert physical backend
reuse across client generations.

---------

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
## What changed

- give each ordinary MORPC unary request a complete read-timeout window
from admission/flush, instead of charging it for socket-idle time before
the request arrived
- distinguish admitted, successfully flushed, terminal-send-failed, and
expired requests while preserving established idle, internal, and
one-way behavior and giving stream writes their own bounded fallback
window
- make tenant-upgrade tests execute the observable pass directly, bound
every wait, and retain one end-to-end periodic-loop test
- make the merge scheduler test synchronize at the exact
executor/table-check boundary, use deterministic resource admission, and
prevent the test observer from blocking the scheduler
- separate frontend scheduling-preview computation from its production
100 ms best-effort latency policy so correctness tests do not race CI
descheduling

## Root cause and design

The embedded-cluster failure was not a restore or privilege failure.
`CREATE ACCOUNT` began during an already-running socket `Read` window
and inherited only the remainder of a configured 20-second timeout.
Merely increasing the timeout therefore could not guarantee a newly
admitted request a full response window.

For a normal response-expecting unary request, the backend now models
four relevant states:

1. admitted/queued or being flushed: retain the stale idle timeout
because work is already pending;
2. successfully flushed: start one full response window at the
successful flush timestamp;
3. terminal send failure: do not extend the connection lifetime;
4. expired response window: close the stalled backend; a newer admission
cannot rescue it.

The timestamp is published before the terminal send-completion flag. The
timeout scanner reads that flag before the timestamp, so it cannot
observe an old zero timestamp paired with the new success flag. The hot
path adds one atomic store only for normal unary traffic after a
successful flush; the cold timeout path scans the existing
lifecycle-bounded future set. Internal, one-way, probe-enabled,
cancellation, and close semantics remain unchanged. Probe-less streams
use one backend-level last-successful-flush window only when no unary
response window exists; an expired unary remains authoritative.

The other failures had the same broad symptom but different mechanisms:
correctness depended on a 20 ms asynchronous timer, host/cgroup memory
plus 3/5 ms scheduler polling, or a production 100 ms best-effort
preview timeout. Race instrumentation and package-parallel CI load can
delay those operations without changing their business result. Tests now
synchronize on observable state transitions, carry bounded parent
contexts, and explicitly distinguish expected cancellation from a hang
deadline.

The lifecycle audit found no new unbounded state or waits: future
ownership remains reference-counted and backend-close bounded; the
timeout scan covers only existing live futures; merge observation is
nonblocking and overflow-checked; every new test wait has a 10-second
guard.

Fixes matrixorigin#27963

## Test plan

Passed before rebase:

- MORPC state matrix under race:
`TestReadTimeoutDoesNotChargeIdleTimeToNewRequest` (`-count=100`)
- actual MORPC request tracking under race:
`TestReadTimeoutTracksRequestsWithoutLivenessProbe` (`-count=50`)
- merge scheduler under race: `TestScheduler` (`-count=100`)
- frontend strict-pool path under race:
`TestDirectSessionStrictPoolWithoutLabelSelectorFailsClosed`
(`-count=50`)
- all seven tenant-upgrade tests separately under race (`-count=20`
each)
- full package tests: `pkg/common/morpc`, `pkg/bootstrap`,
`pkg/frontend`, and `pkg/vm/engine/tae/db/merge`
- full `pkg/common/morpc` package under race
- targeted `go vet` for all four owning packages
- real embedded-cluster regression under race:
`TestAuthenticatedTestsReuseBaseCluster` and
`TestIssue26640ClusterRestoreRebindsSubscriptionPrivileges`

Rebased cleanly onto current `main` (`3f6856cc5f`). The two new upstream
commits touched only frontend code, so the affected closure was rerun
after rebase:

- full `pkg/frontend`: passed (13.974 s)
- strict-pool frontend counterexample under race, `-count=50`: passed
(1.296 s)
- full `pkg/bootstrap`: passed (18.523 s)
- `go vet ./pkg/frontend ./pkg/bootstrap`: passed
- real embedded-cluster regressions under race: passed (36.040 s)
- `git diff --check`: passed

No SQL result, wire API, or planner contract changes are introduced, so
no SQL BVT case is required; the embedded-cluster tests exercise the
public transport/session path directly.

CI reruns for the unrelated failures on matrixorigin#27949 and matrixorigin#27946 were triggered
separately; this PR does not wait for those reruns.

Post-review deterministic-clock closure (99e9d6c):

- removed the remaining 25/50 ms wall-clock oracle from TestScheduler;
policy composition now uses a lifetime longer than the test hang guard
- added TestSchedulerPolicyPatchExpirationUsesInjectedClock to prove
in-place policy merging, exact-deadline validity, and removal
immediately after the injected clock crosses the deadline
- focused normal tests passed; both scheduler tests passed separately
under race detection with count 100; the full merge package passed

---------

Co-authored-by: Claude Fable 5 <[email protected]>
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 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 matrixorigin#20022

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

This follow-up closes the remaining prepared short-connection cache
review gaps after PR matrixorigin#27916:

- separates QueryService `ResetSession` from MySQL
`COM_RESET_CONNECTION`: the Proxy cache reset starts with an empty
database, while the client command continues to preserve its selected
database;
- generates the production-driver shape of a one-parameter binary
`COM_STMT_EXECUTE` packet, including iteration-count `1`, null bitmap,
new-parameter flag, type, and value, and requires the real Frontend
parser to accept it;
- sends every one of 100 client generations through the real
`connectToBackendContext` cached-login path, including cache
authentication, `SET CONNECTION ID`, database restoration, tunnel
traffic, `STMT_CLOSE`, `QUIT`, PING fence, ResetSession, cache
publication, and the next login;
- alternates two login databases and finishes with a login that
specifies no database, where `DATABASE()` must return `NULL`; prepared
state must be empty before every next client prepares again.

Validation:

- PR base: `33af6ae3c0c23e4f277137460577ea64678f7ecf`
- exact head: `4e3e457b228bde8fcd6641f7d1aca3d546b9d529`
- falsification at pre-fix head
`2cfed1bb14a3e58de1d8fc5da625d1338e689afc`: FAIL because QueryService
ResetSession retained `must_not_leak`
- focused Frontend and Proxy regressions: PASS
- Proxy 100-generation regression, `count=10`: PASS
- focused Frontend and Proxy race regressions: PASS
- full `pkg/frontend` and `pkg/proxy`: PASS
- full `pkg/frontend -race` and `pkg/proxy -race`: PASS
- `go list`, CGo-configured `go build`, `go vet`, and `git diff
--check`: PASS
- semantic preflight: PASS, diff hash
`a98f98d3e9a6175abfe2ec92efab67e06b15abcee9c61e02c2f5c2245eceff95`

QA required: yes. These deterministic regressions do not replace the
multi-CN, dual-Proxy prepared short-connection campaign required by
matrixorigin#20022.

BVT: N/A. Ordinary SQL BVT cannot enable Proxy connection caching,
generate binary prepared short connections, or assert physical backend
reuse across client generations.

---------

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
## What changed

- give each ordinary MORPC unary request a complete read-timeout window
from admission/flush, instead of charging it for socket-idle time before
the request arrived
- distinguish admitted, successfully flushed, terminal-send-failed, and
expired requests while preserving established idle, internal, and
one-way behavior and giving stream writes their own bounded fallback
window
- make tenant-upgrade tests execute the observable pass directly, bound
every wait, and retain one end-to-end periodic-loop test
- make the merge scheduler test synchronize at the exact
executor/table-check boundary, use deterministic resource admission, and
prevent the test observer from blocking the scheduler
- separate frontend scheduling-preview computation from its production
100 ms best-effort latency policy so correctness tests do not race CI
descheduling

## Root cause and design

The embedded-cluster failure was not a restore or privilege failure.
`CREATE ACCOUNT` began during an already-running socket `Read` window
and inherited only the remainder of a configured 20-second timeout.
Merely increasing the timeout therefore could not guarantee a newly
admitted request a full response window.

For a normal response-expecting unary request, the backend now models
four relevant states:

1. admitted/queued or being flushed: retain the stale idle timeout
because work is already pending;
2. successfully flushed: start one full response window at the
successful flush timestamp;
3. terminal send failure: do not extend the connection lifetime;
4. expired response window: close the stalled backend; a newer admission
cannot rescue it.

The timestamp is published before the terminal send-completion flag. The
timeout scanner reads that flag before the timestamp, so it cannot
observe an old zero timestamp paired with the new success flag. The hot
path adds one atomic store only for normal unary traffic after a
successful flush; the cold timeout path scans the existing
lifecycle-bounded future set. Internal, one-way, probe-enabled,
cancellation, and close semantics remain unchanged. Probe-less streams
use one backend-level last-successful-flush window only when no unary
response window exists; an expired unary remains authoritative.

The other failures had the same broad symptom but different mechanisms:
correctness depended on a 20 ms asynchronous timer, host/cgroup memory
plus 3/5 ms scheduler polling, or a production 100 ms best-effort
preview timeout. Race instrumentation and package-parallel CI load can
delay those operations without changing their business result. Tests now
synchronize on observable state transitions, carry bounded parent
contexts, and explicitly distinguish expected cancellation from a hang
deadline.

The lifecycle audit found no new unbounded state or waits: future
ownership remains reference-counted and backend-close bounded; the
timeout scan covers only existing live futures; merge observation is
nonblocking and overflow-checked; every new test wait has a 10-second
guard.

Fixes matrixorigin#27963

## Test plan

Passed before rebase:

- MORPC state matrix under race:
`TestReadTimeoutDoesNotChargeIdleTimeToNewRequest` (`-count=100`)
- actual MORPC request tracking under race:
`TestReadTimeoutTracksRequestsWithoutLivenessProbe` (`-count=50`)
- merge scheduler under race: `TestScheduler` (`-count=100`)
- frontend strict-pool path under race:
`TestDirectSessionStrictPoolWithoutLabelSelectorFailsClosed`
(`-count=50`)
- all seven tenant-upgrade tests separately under race (`-count=20`
each)
- full package tests: `pkg/common/morpc`, `pkg/bootstrap`,
`pkg/frontend`, and `pkg/vm/engine/tae/db/merge`
- full `pkg/common/morpc` package under race
- targeted `go vet` for all four owning packages
- real embedded-cluster regression under race:
`TestAuthenticatedTestsReuseBaseCluster` and
`TestIssue26640ClusterRestoreRebindsSubscriptionPrivileges`

Rebased cleanly onto current `main` (`3f6856cc5f`). The two new upstream
commits touched only frontend code, so the affected closure was rerun
after rebase:

- full `pkg/frontend`: passed (13.974 s)
- strict-pool frontend counterexample under race, `-count=50`: passed
(1.296 s)
- full `pkg/bootstrap`: passed (18.523 s)
- `go vet ./pkg/frontend ./pkg/bootstrap`: passed
- real embedded-cluster regressions under race: passed (36.040 s)
- `git diff --check`: passed

No SQL result, wire API, or planner contract changes are introduced, so
no SQL BVT case is required; the embedded-cluster tests exercise the
public transport/session path directly.

CI reruns for the unrelated failures on matrixorigin#27949 and matrixorigin#27946 were triggered
separately; this PR does not wait for those reruns.

Post-review deterministic-clock closure (99e9d6c):

- removed the remaining 25/50 ms wall-clock oracle from TestScheduler;
policy composition now uses a lifetime longer than the test hang guard
- added TestSchedulerPolicyPatchExpirationUsesInjectedClock to prove
in-place policy merging, exact-deadline validity, and removal
immediately after the injected clock crosses the deadline
- focused normal tests passed; both scheduler tests passed separately
under race detection with count 100; the full merge package passed

---------

Co-authored-by: Claude Fable 5 <[email protected]>
@VioletQwQ-0
VioletQwQ-0 deleted the codex/issue-20022-prepared-cache-regression branch December 1, 2026 03:47

This branch was previously deployed

1 inactive deployment
ci — 8e0b75d9 Deployed Sep 1, 2026 by mergify[bot] via Matrixone Utils CI / Coverage #49982
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/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants