Skip to content

Fix flaky 04752_persisted_expression_cancellation oracle - #113943

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:fix-04752-grep-oracle-double-match
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:fix-04752-grep-oracle-double-match

Conversation

@groeneai

@groeneai groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Related: #96844

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):

...

Description

Reported on the private sync CI of #96844: the test produced one extra TIMEOUT_EXCEEDED line after the geohash_skipindex marker.

Root cause: a test-oracle defect, not a cancellation-timing flake. grep -o -m1 is line-limited, not match-limited: -m1 stops after the first matching line, and -o then prints every match on that line. A line that renders the error code twice therefore emits two output lines, against a .reference that is a strict two-lines-per-case alternation.

Timing cannot produce that symptom: each case emits exactly two lines in all three outcomes (timeout under bound, over bound, no timeout) and timing only changes the label text. The only path emitting a bare token is the grep -o, so it printed two lines for one query. Every stopped promptly marker passed on the failing run, so cancellation itself worked.

The change replaces the value-printing oracle with a boolean one at both call sites in the file, making the match count irrelevant:

if <client> ... 2>&1 | grep -qw "TIMEOUT_EXCEEDED"
then echo "TIMEOUT_EXCEEDED"; else echo "$label: no timeout"; fi

.reference is unchanged: the assertion (a TIMEOUT_EXCEEDED was raised) is identical, and only the counting is removed. No bound is widened and no tag is added.

I have not established which input rendered the code name twice; the fix is deliberately independent of that.

Two sibling cancellation tests carry the same idiom. This PR stays at one file and one concern; I am happy to sweep the class separately if you want it.

Validation. GNU grep 3.11: a doubly-rendered line gives 2 lines before and 1 after; a single render and a no-match both give 1 in each form, so the fallback still fires. Reverting either call site alone reddens only that site. [ OK ] end to end, and 50/50 randomized runs pass.

The test failed on the private sync CI of ClickHouse#96844 with one extra
TIMEOUT_EXCEEDED line after the geohash_skipindex marker.

`grep -o -m1` is line-limited, not match-limited: `-m1` stops after the
first matching line and `-o` then prints every match on that line, so a
line rendering the error code twice emits two output lines. The reference
is a strict two-lines-per-case alternation, so that is an output mismatch.

It is not a cancellation-timing flake. Each case emits exactly two lines
in all three outcomes, and timing only changes the label text, so no
timing effect can add a line; every `stopped promptly` marker passed on
the failing run. I have not established which input rendered the code
name twice, and the change is deliberately independent of that: the
oracle becomes a boolean test, so the match count no longer matters.

Both call sites in the file are changed, including the direct-baseline
loop, which carries the same defect two functions below the reported
line. The reference is unchanged, so nothing is relaxed: the assertion
that a TIMEOUT_EXCEEDED was raised is identical and only the counting is
removed. No bound is widened and no tag is added.

`grep -ow -m1 ... | head -1` was rejected: the pipeline returns head's
status, so the `|| echo` fallback silently stops firing and a missing
timeout would print nothing, which is worse than the present bug.
@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Two independent review passes over 118ac8d2: a cold read of the resulting diff, then a second-model
pass over the change and the PR contract. Findings and how each was resolved.

# Finding Verdict
⚠️ The Related: line sat inside the leading HTML comment, so it would not have rendered. Fixed before publishing: moved below the closing -->. Category still parses to CI Fix or Improvement, with a two-category and a no-category control both rejected.
💡 The a-i self-check claimed 0 non-comment grep -o occurrences remain, but a plain grep -c 'grep -o' on the file returns 1: the added comment quotes the idiom it replaces. Clarified in that comment.
💡 The scope note justified leaving the two sibling tests alone by arguing their paths cannot reach the defect. Reworded. The fix is independent of which input produced the second match, so the reason to stay narrow is one file and one concern, not unreachability. The PR offers the sweep rather than asserting it is unnecessary.
❌ -w is added rather than preserved, so it could in principle redden a passing test. Disagreed, measured. It fails loud rather than silent: a missed match prints the fallback label and mismatches the reference. The only rendering the server produces is the parenthesized (TIMEOUT_EXCEEDED) appended at src/Common/Exception.cpp:688, which -w matches; MY_TIMEOUT_EXCEEDED_X is correctly rejected. TIMEOUT_EXCEEDED is not a substring of any other error code.
❌ The census of same-idiom sites looked off by one (33 rather than the 32 reported). Disagreed, self-refuted. The extra hit has no fallback bound to its grep: the `

Also checked and clean: the test still fails if the fix is reverted, and reverting either call site
alone reddens only that site; .reference is byte-identical, no bound widened, no tag added. One
competing explanation was ruled out rather than assumed - an extra line could have come from stderr,
but the harness runs {test} > {stdout} 2> {stderr} and diffs the reference against stdout only, so
the third line had to come from stdout, and the only bare-token stdout path was the grep -o.
shellcheck reports zero findings on both the old and the new file.

@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

a-i self-check
# Check Answer
a Deterministic repro? Yes, at the oracle level where the defect lives. /bin/grep -o -m1 TIMEOUT_EXCEEDED <line-with-two-renderings> | grep -c . prints 2, deterministic on every run. Not a "~1%". The fixture was asserted to carry the token twice on one line before use, since a single-render fixture is a control masquerading as a witness.
b Root cause explained? Yes. -m1 bounds matching lines, not matches; -o then prints every match on the line it stops at. One doubly-rendered line therefore emits two output lines, and the .reference is a strict two-lines-per-case alternation, so the run fails on an output mismatch. Timing cannot add a line: each case emits exactly two lines in all three outcomes and timing changes only the label text.
c Fix matches root cause? Yes. The oracle becomes a boolean test (grep -qw) and the echo supplies the single canonical line, so the match count is irrelevant by construction. Not a band-aid: no bound widened, no no-random-settings, no dataset reduction, no guard placed over a product bug. Raising the bound or adding a SCALE multiplier was rejected because timing is provably not the cause.
d Test intent preserved / tests added? Yes. .reference is byte-unchanged and the latency assertions are untouched; the assertion that a TIMEOUT_EXCEEDED was raised is identical, only the counting is removed. No new test file: the change is a test change, and the proof obligation is discharged by the mutation matrix in row (e).
e Both directions demonstrated? Yes. Same fixture, GNU grep 3.11: pre-fix 2 lines, post-fix 1. Mutation matrix over the two call sites: reverting site 1 gives 2 lines at site 1 and 1 at site 2; reverting site 2 is the exact mirror; the shipped file gives 1 at both. That asymmetry shows both hunks are independently load-bearing.
f General across code paths? Yes. Census of grep -o combined with -m1 under tests/queries/0_stateless/: 267 matching lines in 105 files, of which 32 use the || echo <fallback> shape that turns a spurious line into a mismatch. Both sites in this file are fixed, including one two functions below the reported line that would otherwise have stayed latent. Post-fix the file has 0 non-comment grep -o occurrences (a plain grep -c 'grep -o' returns 1: the added comment quotes the idiom it replaces). Three further sites are deliberately not touched: two are pure local SELECT paths with no reproduction (one of them is being edited in #113923), and one carries no-msan so it cannot run on the failing flavour.
g Generalizes across inputs? Yes, by construction: 1, 2 or N renderings all yield one line. Boundary inputs measured: zero matches (the fallback branch fires), one match, two matches, the token inside parentheses (matches, since -w treats them as non-word characters), and the token as a substring of a longer identifier (correctly rejected).
h Backward compatible? Not applicable, and asserted: one .sh test file, no setting, no default, no serialization format, so no SettingsChangesHistory.cpp entry is owed.
i Invariants and contracts preserved? Yes. The invariant is one line per outcome per case, now guaranteed on all three branches. bash -n is clean. The fallback semantics are preserved, which is precisely why the grep -ow -m1 ... | head -1 variant was rejected: the pipeline returns head's status, so the fallback silently stops firing and a missing timeout prints nothing. No error or early-return path changed; no concurrency or durability surface is involved.

Validation runs: the test passes end to end, and 50 randomized repeats pass 50/50 with zero output
mismatches. Note these are corroboration only, since no local input produces the doubled rendering:
rows (a) and (e) are the evidence.

@groeneai groeneai mentioned this pull request Aug 8, 2026
1 task done
@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @george-larionov, could you review this? It is a test-only fix: the oracle used grep -o -m1, which stops after the first matching line and then prints every match on it, so a line rendering the error code twice emitted two lines against a reference that expects one; the oracle becomes a boolean test and .reference is unchanged.

@PedroTadim PedroTadim self-assigned this Aug 8, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6ca5e91]

Summary: ✅


AI Review

Summary

This PR fixes a flaky oracle in 04752_persisted_expression_cancellation.sh by replacing the value-printing grep -o -m1 pipeline with a boolean grep -qw check, so one server line containing TIMEOUT_EXCEEDED twice can no longer emit an extra output line and break the unchanged .reference. I did not find any correctness, safety, or PR-metadata issues in the current diff.

Final Verdict

✅ No findings.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 8, 2026
@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 118ac8d

One failure, owned, not PR-caused.

Check / test Reason Owner / fixing PR
Fast test / 02764_parallel_replicas_plain_merge_tree flaky 300s receive_timeout in the parallel-replicas cancel path, unrelated to this diff: 6 hits / 5 distinct PRs / 1 master hit in 14 days a fix task is created (investigating at full effort - fixing PR link to follow on this PR)

Gate detail: (a) 0 check-runs queued or in_progress across all 174 (fully paginated); (b) Finish Workflow = success at 2026-08-08T18:32:21Z; (c) 22 minutes since the last completion, past the 20-minute CIDB ingestion buffer; (d) the one line has an owner. No CH Inc sync row on this head.

Why this is not PR-caused, although it is a Fast test red. Fast test failures are normally the PR's own bug, so I checked the attribution rather than assuming it. This PR's diff is a single file, tests/queries/0_stateless/04752_persisted_expression_cancellation.sh, and it changes only that test's own grep -o -m1 oracle to grep -qw. It adds no source change and does not touch parallel replicas. The failing test is a different test that this PR cannot influence, it timed out at 60s under the Fast test budget, and it has independent history including one master hit. This PR's own test 04752_persisted_expression_cancellation was SKIPPED in the Fast test run, so the change under review is not the thing that failed.

I searched for an existing fixing PR before creating an owner and found none: the open PRs matching this test name are unrelated changes that merely mention it in CI output.

Session id: cron:our-pr-ci-monitor:20260808-183000

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai check the fast test failure

@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

@PedroTadim The Fast test red is 02764_parallel_replicas_plain_merge_tree, not the test this PR changes.

04752_persisted_expression_cancellation carries no-fasttest, so it is skipped in every Fast test run by construction, and it was skipped in this one. The whole diff is that test's own oracle (grep -o -m1 to grep -qw, one file, +8/-4). There is no source change and nothing touching parallel replicas, so it cannot influence 02764.

It is the flake already tracked in #109265, the one you handed to @ nickitat on 3 August for the cancel-semantics decision. I checked the mechanism against this run's own server log rather than matching on the test name: two follower replicas sit in TCPHandler::receivePartitionMergeTreeReadTaskResponse until the peer resets, and the query that actually times out is the trailing DROP TABLE parallel_replicas_plain (here at the Fast test 60 s cap rather than the usual 300 s receive_timeout). Same signature, shorter deadline.

Independent history, last 14 days: 5 further failures on four other pull requests, one of those through the merge queue. No fix PR exists (searched open and closed, with a control query), so this red will not clear on a re-run and it is not this PR's to clear. I have not merged master or re-run CI to hide it.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113943&sha=118ac8d29731210ea5cff8a687061689ed09b5a7&name_0=PR&name_1=Fast%20test
Full triage of this run: #113943 (comment)

@clickhouse-gh

clickhouse-gh Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6ca5e91b8 with master 8cb46d93b (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: compile time of recompiled translation units.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 690.64 MiB 687.62 MiB -3.02 MiB (-0.44%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units ⚠️

7023 translation units recompiled, 6517 s compile time in total, 6 of them have a recent master baseline.

Translation units without a recent master baseline:

  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Passes/PassBuilder.cpp: 24.3 s
  • contrib/aws-cmake/__/aws/generated/src/aws-cpp-sdk-s3/source/S3Client.cpp: 14.3 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp: 14.2 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/vm/plugin_modules.cpp: 13.2 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp: 11.4 s
  • contrib/aws-cmake/__/aws/generated/src/aws-cpp-sdk-glue/source/GlueClient.cpp: 11.3 s
  • contrib/aws-cmake/__/aws/generated/src/aws-cpp-sdk-glue/source/GlueClient1.cpp: 11.1 s
  • contrib/rocksdb-cmake/__/rocksdb/db/db_impl/db_impl.cc: 10.1 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/api/wasmedge.cpp: 9.3 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Analysis/ScalarEvolution.cpp: 9.1 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Passes/PassBuilderPipelines.cpp: 9.0 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp: 9.0 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/host/wasi/wasimodule.cpp: 8.9 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/CodeGen/CodeGenPrepare.cpp: 8.8 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/vm/vm.cpp: 8.8 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Transforms/IPO/SampleProfile.cpp: 8.3 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp: 8.2 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp: 8.2 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/executor/instantiate/global.cpp: 8.2 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/host/wasi/wasifunc.cpp: 8.0 s
  • ... and 95 more

Job report

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 6ca5e91

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

CI is fully finished on this commit with no failed checks - every dispatched job
reported success, so there is nothing to assign an owner to.

Session id: cron:our-pr-ci-monitor:20260809-170000

@PedroTadim

Copy link
Copy Markdown
Member

I am removing the test myself

@PedroTadim PedroTadim closed this Aug 9, 2026
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 2026
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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants