Skip to content

Fix flaky test 05480_autopr_plan_based_group_by_order_by_top_k - #133636

Open
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-05480-applied-formula-from-client-logs
Open

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-05480-applied-formula-from-client-logs

Conversation

@groeneai

@groeneai groeneai commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #116577
Related: #125888

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Not required.

Description

05480_autopr_plan_based_group_by_order_by_top_k (added in #125888) failed in the private Stateless tests (amd_jemalloc_uaf, meta in keeper, s3 storage, parallel) job (reported on #116577): its last four rows were missing. They come from the final query, which reads the output divisor from the AutoParallelReplicas "The applied formula" line in system.text_log. Only these rows were reported missing, so the query_log block above it still had AutoParallelReplicasApplied = 1, and that event is counted only after the line is logged: the line was logged and then lost on its way to system.text_log. That table is best effort: SystemLogQueue ignores entries past max_size_rows until the next flush, the async logger drops on overflow, a failed flush loses its batch, and the table keeps only the levels its logger lets through. The public CI has no such failure in about 4900 runs.

The test is now a .sh test that runs the same SQL with send_logs_level = trace and --server_logs_file, and reads the divisor of each initial q05480_priced_* query from that file by query_id. The client gets the line through the query's own logs queue, which is unbounded and filled before any text_log handling; a .sql test cannot read that stream. The reference is unchanged. 05218_autopr_set_building_plan_is_left_alone reads a line of the same logger from system.text_log too, but has not failed this way, so it is left as is.

Validation on a master debug build: with text_log at level debug the old test fails 3/3 with exactly these four rows missing, and with a 16-row text_log queue it fails 10/10; the new test passes both. It also passes 50/50 with random settings, 20/20 without, and 30/30 with async logging. With enable_group_by_top_k_optimization = 0 it reads a divisor of 3, so it checks the live value.


Workflow [PR]
Sync PR [sync-upstream/pr/133636]

`05480_autopr_plan_based_group_by_order_by_top_k` failed in the private
`Stateless tests (amd_jemalloc_uaf, meta in keeper, s3 storage, parallel)`
job with its last four rows missing: the output divisor that the final
query reads from the `AutoParallelReplicas` "The applied formula" line in
`system.text_log`.

The query_log block right above it showed `AutoParallelReplicasApplied = 1`
for the same queries, and that event is counted only after the line is
logged, so the line was logged and lost on its way to `system.text_log`.
That table is best effort: `SystemLogQueue` ignores entries past
`max_size_rows` until the next flush ("Queue had been full ... ignored N
logs"), the async logger drops on overflow, a failed flush loses its batch,
and the table keeps only the levels its logger lets through.

The test is now a `.sh` test that runs the same SQL with
`send_logs_level = trace` and `--server_logs_file`, and reads the divisor
from the lines of each initial `q05480_priced_*` query (by `query_id`) in
that file. The client receives the line through the query's own logs
queue, which is unbounded and filled before any `text_log` handling. The
reference is unchanged.

Validated on the master debug build: with `<text_log><level>debug</level>`
the old test fails 3/3 with exactly those four rows absent and the new one
passes 3/3; with a 16-row `text_log` queue the old one fails 10/10 (33 of
40 rows lost) and the new one passes 10/10; the new one passes 50/50 with
random settings (`-j 8`), 20/20 without, and 30/30 with async logging.
With `enable_group_by_top_k_optimization = 0` the new extraction reads a
divisor of 3, so it reads the live value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 nit).

# Sev Finding Verdict Evidence / action
1 💡 With --server_logs_file, a server <Warning> of these queries goes to the log file instead of stderr, so it no longer fails the test AGREE, noted, not blocking Same trade as every --server_logs_file test; client errors still reach stderr and fail it

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261123-012400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @devcrafter, could you review this? Test-only fix: 05480_autopr_plan_based_group_by_order_by_top_k reads the applied-formula divisor from the client's server logs instead of system.text_log, which lost the line in private CI

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Master debug binary, text_log at level debug: the old .sql fails 3/3 with exactly the last four rows missing, the private CI symptom. A 16-row text_log queue (max_size_rows 16) fails it 10/10: Queue had been full ... ignored N logs, 33 of 40 divisor rows lost.
b Root cause explained? The final query reads the divisor from the "The applied formula" TRACE line in system.text_log. AutoParallelReplicasApplied, still 1 in the query_log block (only these four rows were reported missing), is counted only after that line is logged (considerEnablingParallelReplicas.cpp:1466 before :1576), so the line was lost on its way to system.text_log, a best-effort sink (queue overflow, async logger drop, failed flush, level filter).
c Fix matches root cause? Yes. The test reads the line from the server logs the client receives (send_logs_level = trace, --server_logs_file), pushed into the query's own unbounded logs queue before any text_log handling. No widened bound, no tag, no removed assertion.
d Test intent preserved / new tests added? Yes. Same SQL, same queries, same .reference; only the source of the divisor changed. Test-only change, so no new test.
e Both directions demonstrated? Yes. Level-filter server: old 3/3 FAIL, new 3/3 OK. 16-row queue: old 10/10 FAIL, new 10/10 OK. Default config: both 3/3 OK, new stdout byte-identical to the reference.
f Fix is general across code paths? N/A for product code (test-only). 05218_autopr_set_building_plan_is_left_alone reads a line of the same logger from system.text_log, but has no such failure (about 110k OK runs in 30 days), so it is left as is.
g Fix generalizes across inputs (params/datatypes/wrappers)? 50/50 OK with random settings (-j 8), 20/20 without, 30/30 with async logging. Negative control: with enable_group_by_top_k_optimization = 0 the extraction reads a divisor of 3 instead of 1, so it reads the live value.
h Backward compatible? (maintainer-approved exception only) Yes, no settings, formats or product code change.
i Invariants and contracts preserved? The divisor rows are matched by the initial query's query_id, as the old text_log join was; exactly one formula line per priced query was measured. The other three blocks still read system.query_log unchanged; client errors still reach stderr and fail the test.

Session id: cron:clickhouse-impl-slot-4:20261123-010700

@clickhouse-gh

clickhouse-gh Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cf578f4]

Summary: ✅


AI Review

Summary

PR #133636 converts 05480_autopr_plan_based_group_by_order_by_top_k to a shell test and extracts the cost-model divisor from client-received server logs, avoiding dropped or filtered entries in system.text_log. The existing result and profile-event assertions remain intact. No actionable findings. The reported reproduction and negative-control runs, supported by the passing Fast test, provide adequate evidence for this test-only change.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). labels Nov 23, 2026
@devcrafter
devcrafter requested a review from nickitat November 23, 2026 14:14

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

k

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants