Skip to content

Fix flaky 04344_server_ast_fuzzer_insert_limit (INSERT timeout) - #114077

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:fix-04344-insert-timeout
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:fix-04344-insert-timeout

Conversation

@groeneai

@groeneai groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Related: #109209 (fixed the teardown-DROP facet of the same test)

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

04344_server_ast_fuzzer_insert_limit intermittently fails with
Code: 159 ... elapsed 25514.95756 ms, maximum: 20000 ms (TIMEOUT_EXCEEDED) charged to one of its two
INSERTs: 3 times in 90 days, all on Stateless tests (arm_asan_ubsan, azure, parallel), against 163,155
OK on PR refs and 0 / 14,497 OK on master and release. Its 5 other failures there (DROP/seed Code: 159,
see #109209; host OOM) are out of scope.

Root cause: the session SET max_execution_time = 20 is sized for the fuzzer's work, but on the two
MergeTree INSERTs it also bounds object-store write latency the test does not control. In a failing
arm_asan_ubsan, azure run the worker thread logs WriteBufferFromAzureBlobStorage: Committed single block
22.79 s after reserving space for a 100-row block; a second repeats it at +28.3 s. 27 unrelated queries
also exceeded 20 s there, so the stall is host-wide.

It cannot just be removed: each fuzzable statement runs 30 fuzzed clones inside the outer query's clock,
and that deadline is the loop's only aggregate bound. So it is raised to 60 s on the two implicated
INSERTs, via their existing SETTINGS clauses. The session value stays 20 s and clones keep the
fuzz-context cap of 10 s (max_execution_time is stripped from fuzzed queries), the property under test.

60 s and not more: the Stress harness constrains max_execution_time to max 60
(tests/docker_scripts/stress_tests.lib) and a per-statement clause is checked with THROW_ON_VIOLATION,
so a larger value would be rejected before the statement runs, silently dropping this coverage. That is over
2x the failing costs (24.97 / 25.51 / 28.39 s).

Verified from system.query_log: the two INSERTs report an effective 60 where the unmodified statement
reports 20, and every clone still reports 10. With that constraint installed locally, 60 runs while a larger
value is rejected before a row is inserted. 50/50 randomized runs pass.

groeneai and others added 2 commits August 9, 2026 18:16
The test intermittently failed with

  Code: 159. DB::Exception: Timeout exceeded: elapsed 25514.95756 ms,
  maximum: 20000 ms. (TIMEOUT_EXCEEDED)

charged to one of its two INSERTs (8 failures / 176,696 OK in 90 days on
PR refs, 0 on master; reruns pass 15/15).

The session `SET max_execution_time = 20` at the top of the test is sized
for the fuzzer's work, but on the two MergeTree INSERTs it also bounds
object-store write latency the test does not control. In the server log of
a failing `arm_asan_ubsan, azure` run (query_id 523bd414-7918) the worker
thread emits only four lines in the gap: reserve 1 MiB, FakeDiskTransaction
on disk cached_azure, then

  WriteBufferFromAzureBlobStorage: Committed single block

22.79 s later for a 100-row block, after which the statement throws at
25.5 s. The same shape was reproduced on a second azure failure at +28.3 s.
The stall is host-wide rather than specific to this test: 27 unrelated
queries exceeded 20 s in the same run (max 89.84 s across the two logs).
They do not fail because they do not deadline themselves.

The bound cannot simply be removed. On success each fuzzable statement runs
30 fuzzed clones inside the outer query's clock and the outer deadline is
that loop's only aggregate bound: per-clone limits (max_execution_time = 10
at executeQuery.cpp:2338, a 30 s wall clock at :2404) bound each clone but
not the loop, which is stopped only by checkTimeLimitSoft against the outer
QueryStatus at :2235. Removing it would admit 30 x 30 s against the 600 s
harness timeout.

So raise it to 120 s on exactly the two INSERTs the logs implicate, using
their existing SETTINGS clauses, and leave the session value at 20 s. The
override lands because applySettingsFromQuery handles ASTInsertQuery's
settings_ast (InterpreterSetQuery.cpp:218-223) at executeQuery.cpp:1578,
before ProcessList::insert at :1623. Fuzzed clones do not inherit it:
max_execution_time is in stripFuzzerSafetyLimitSettings (:1098-1108), so a
clone keeps the fuzz-context cap of 10 s, which is the property this test
exists to prove.

120 s clears the worst single-statement stall measured on these hosts
(89.84 s) with headroom, stays about 37x above the measured 30-clone loop
span (1.9-3.2 s), and is below the client receive_timeout (300 s) and the
harness per-test timeout (600 s), so a genuine runaway still fails as a
diagnosable Code: 159 rather than a harness kill.

Raising the session value instead was rejected: two of the three seed
SELECTs already run unbounded (max_execution_time = 0 means unlimited, and
the `= DEFAULT` form resets to 0 after the changes are applied), so a
session raise would weaken the fuzzer budget only on the statements that
never fail.

Verified from the effective values in system.query_log: the two INSERTs
report 120 where the unmodified statement reports 20, every internal fuzzed
query reports 10, and the fuzzer still produces 129 INSERT clones for this
test. Test green, 50 runs with settings randomization enabled green,
.reference unchanged.
The per-statement max_execution_time on the two INSERTs was 120, which the
Stress harness forbids: tests/docker_scripts/stress_tests.lib
installs a default-profile constraint of max 60 for this setting, and an
INSERT's own SETTINGS clause is checked with THROW_ON_VIOLATION, so both
statements would have thrown SETTING_CONSTRAINT_VIOLATION before executing.
The stress harness does not assert on worker return codes, so the test would
have silently stopped exercising both INSERT paths on that job.

60 is the largest value valid everywhere: SettingsConstraints only throws when
max < value, so value == max is accepted. It is still 2.1x to 2.4x the observed
failing costs (24.97 / 25.51 / 28.39 s) and ~19x the 30-clone fuzz loop's own
span, so the aggregate fuzzer budget the bound provides is intact.

Verified with the constraint installed locally: the 120 form is rejected with
Code 452 before inserting any row, the 60 form runs, and the whole test passes
and matches its reference. The fuzzer still produces 60 INSERT clones and every
clone still runs at the fuzz-context cap of 10.

Co-Authored-By: Claude Fable 5 <[email protected]>
@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

An independent model reviewed this change cold against the description; I adjudicated each finding at
source.

# Finding Verdict
❌ max_execution_time = 120 violates the Stress harness constraint (max 60), so both INSERTs would have thrown SETTING_CONSTRAINT_VIOLATION before executing and the test would have silently stopped covering those paths there Agreed, fixed - both clauses are 60. SettingsConstraints::check only throws when max < value, so 60 is the ceiling rather than an arbitrary retreat, and it is still over 2x the observed failing costs
⚠️ The 60 s clauses exceed the AST fuzzer corpus job's profile cap of 10, so both INSERTs are rejected when this file is used as fuzzer input Disagreed - see below
💡 The comment said "Both INSERTs" but sat above only the first Agreed, fixed - one self-contained comment above the pair, stating the ceiling

On the second: the necessary step, that the two INSERTs ran under the intended bound on that job before
this change, does not hold. Line 7 is a standalone SET max_execution_time = 20;, checked on the same
THROW_ON_VIOLATION path as an INSERT's own SETTINGS clause (InterpreterSetQuery.cpp:46 and :64),
so under a max of 10 that pre-existing line already throws Code: 452 on master today and both
INSERTs already execute at the profile default of 10, before and after this change. The suggested
remedy, bracketing them with session-level 60/20 changes, is the same standalone-SET path and would
throw identically while reintroducing the flake on the profile where all three real failures occurred. No
value both clears a 22.79-28.39 s object-store stall and stays under 10 s. That job also feeds every
.sql file unfiltered as fuzzer input and clears each nonfatal error to keep fuzzing
(programs/client/FuzzLoop.cpp:444-452), and 21 per-statement max_execution_time values above 10
already exist across 6 files under tests/queries/0_stateless.

I also corrected my own text before publishing: the Stress check is the only job installing that
constraint (the Upgrade check never calls configure_limits and runs the previous release's copy of this
test), the failure count now separates the 3 failures of this facet from the test's 5 unrelated ones, and
an unverifiable rerun figure was dropped.

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author
Validation

The CI trigger is a >20 s object-store write, which is not reachable locally by luck, so the equivalent
cost was injected (WHERE NOT sleepEachRow(0.2) over numbers(100), max_block_size = 10) to get the
same Code: 159 on the same statement shape every run.

Four arms that move independently: no per-statement entry, fails; = 60, passes; = 0.5, fails on the
same INSERT, so the per-statement bound is enforced rather than merely present; shipped form, passes.
With a local copy of the Stress profile constraint, = 60 runs, = 61 and larger are rejected, which
confirms the constraint actually loaded. From system.query_log: the two INSERTs report an effective 60
against 20 for an unmodified statement, and all 60 fuzzed INSERT clones report the fuzz-context cap of
10, none at 60.

Generality: of the 14 files under tests/queries/0_stateless mentioning ast_fuzzer_runs, only this one
combines a positive session max_execution_time with ENGINE = MergeTree and INSERT, and both of its
INSERTs are fixed rather than only the one observed publicly. No no-random-* tag, no long tag, no
dataset reduction, no source change, .reference byte-identical.

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

cc @PedroTadim, could you review this? It is a test-only change: the two MergeTree INSERTs in 04344 were bounded by the session max_execution_time = 20, which also bounds object-store write latency the test does not control, so each is given 60 s (the Stress profile's ceiling) via its existing SETTINGS clause while the session value and the fuzz-context cap of 10 s stay as they were.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9f00fca]

Summary: ❌

job_name test_name status info comment
Stress test (arm_tsan) FAIL
Logical error: Sizes of nested column and null map of Nullable column are not equal after deserialization (null map size = A, nested column size = B) (STID: 6726-6874) FAIL cidb

AI Review

Summary

This PR raises max_execution_time to 60 on the two INSERT seeds in 04344_server_ast_fuzzer_insert_limit so the outer query deadline no longer trips on host-wide object-store latency while fuzzed clones stay capped at 10 seconds. I did not find a correctness or coverage regression in the current head: InterpreterSetQuery::applySettingsFromQuery applies the INSERT setting before ProcessList::insert, executeASTFuzzerQueries strips max_execution_time from fuzzed ASTInsertQuery settings before re-execution, the parser tests already cover stripping safety settings from INSERT carriers, and the current CI run is green.

Final Verdict

✅ No new findings.

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

clickhouse-gh Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

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

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 690.67 MiB 687.65 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

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

Job report

@tiandiwonder tiandiwonder self-assigned this Aug 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 9f00fca

Every failure below has an owner: a fixing PR (mine 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.

Check / test Reason Owner / fixing PR
Stress test (arm_tsan) / Sizes of nested column and null map of Nullable column are not equal after deserialization (STID 6726-6874) chronic trunk abort in set skip-index deserialization; this PR changes one stateless test file and touches no serialization or index code #112484 (mine, open) - absent from the build tested here

Config Workflow, Finish Workflow and all 176 other check-runs completed; 0 incomplete.

Attribution is from the stack, not the STID prefix: SerializationNullable.cpp:178
deserializeBinaryBulkWithMultipleStreams <- MergeTreeIndexSet.cpp:196
MergeTreeIndexBulkGranulesSet::deserializeBinary. #112484 places its usability check in the
non-virtual IMergeTreeIndex::getDeserializedFormat, consulted on the shared filterMarksUsingIndex
prefix, so it covers the bulk reader arm shown here as well as the non-bulk one.

This PR's whole diff is tests/queries/0_stateless/04344_server_ast_fuzzer_insert_limit.sql, so it
cannot reach the aborting path.

Session id: cron:our-pr-ci-monitor:20260810-023000

Comment on lines +29 to +30
-- Both INSERTs raise max_execution_time: it bounds their whole 30-clone fuzz loop and must exceed
-- the host's object-store write latency. 60 is the ceiling: the stress profile constrains it to 60.

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.

checked the ceiling claim: stress_tests.lib sets a max_execution_time constraint with <max>60</max>, which is inclusive, so 60 is accepted and 61+ would be rejected before the statement runs. 60 is the largest legal value here.

-- the host's object-store write latency. 60 is the ceiling: the stress profile constrains it to 60.
INSERT INTO t_04344 SELECT number, toString(number), range(number % 8) FROM numbers(100)
SETTINGS max_rows_to_read = 0, read_overflow_mode = 'throw';
SETTINGS max_rows_to_read = 0, read_overflow_mode = 'throw', max_execution_time = 60;

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.

this doesn't weaken the runaway-fuzz property: fuzzed clones are still pinned to max_execution_time = 10 on the fuzz context, and the seed's max_execution_time is stripped from every clone in stripFuzzerSafetyLimitSettings, so raising the seed to 60 can't leak in.

-- overrides, so this stays bounded even though the seed asks for a 1M-row block.
INSERT INTO t_04344 SELECT number, toString(number), range(number % 8) FROM numbers(100)
SETTINGS min_insert_block_size_rows = 1000000, max_block_size = 1000000, max_rows_to_read = 0;
SETTINGS min_insert_block_size_rows = 1000000, max_block_size = 1000000, max_rows_to_read = 0, max_execution_time = 60;

@tiandiwonder tiandiwonder Aug 10, 2026 •

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.

the 60 s covers the real object-store write (~22-28 s observed) plus the 30-clone loop, which is bounded by this same outer deadline via checkTimeLimitSoft.

@groeneai groeneai added the groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet label Aug 19, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Dear @tiandiwonder, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@PedroTadim

Copy link
Copy Markdown
Member

The test is no longer flaky

@PedroTadim PedroTadim closed this Sep 11, 2026
pull Bot pushed a commit to sonvt1710/ClickHouse that referenced this pull request Sep 29, 2026
… lock wait)

On the `Stateless tests (arm_asan_ubsan, azure, parallel)` lane MergeTree
tables default to the `azure_cache` policy, whose disk `cached_azure` is a
write-through filesystem cache (cache_on_write_operations = 1). Every file a
part writes is registered in the cache priority queue by
LRUFileCachePriority::add, which takes the queue lock exclusively. Debug and
sanitizer builds run FileCache::assertCacheCorrectness from
FileCache::getOrSet/get with probability check_cache_probability (0.001), and
its second pass walks the whole queue under that lock shared, checking the
file of every entry on disk. With ~42k entries on that IO-saturated host a
pass takes ~2.3 s (1,086 passes, 2,517 s of checking and 7,673 s of priority
write-lock wait server-wide in one job), so each of the ~11 files of a 100-row
part can wait seconds. The test bounds its seed statements with the session
max_execution_time = 20, and the seed INSERTs failed with Code 159:

- 2026-09-27, PR ClickHouse#122520: block-forming INSERT, elapsed 20,575 ms, of which
  20,454 ms was FilesystemCachePriorityWriteLockMicroseconds
- 2026-09-17, PR ClickHouse#104076: plain INSERT, elapsed 28,097 ms, 28,011 ms waiting

The trace_log of the 2026-09-27 query shows its writer thread in
SharedMutex::lock <- LRUFileCachePriority::add <- FileCache::doTryReserve <-
FileSegment::reserve <- CachedOnDiskWriteBufferFromFile::cacheData in 21 of 21
samples, and the part's 11 blob uploads took 1.6-2.9 ms each, so the time is
the cache lock, not object storage latency. In the same jobs, parts on the
local `default` disk took at most 104 ms / 54 ms, versus 20.6 s / 33.5 s on
cached_azure.

Pin t_04344 to the implicit local `default` storage policy. Where its parts
live is incidental to what the test verifies (stripping of seed SETTINGS on
the INSERT, block-forming, CREATE storage and BACKUP carriers), so its
INSERTs, their fuzzed clones, the BACKUP and the teardown DROP no longer touch
the cache, and no time bound is widened: the session max_execution_time = 20
still bounds the fuzz loop. t_04344_storage keeps the lane's default policy,
because its SETTINGS clause must hold only max_rows_to_read for the
empty-SETTINGS pruning carrier.

Reproduced locally on a debug build with the CI test configs, the
write-through local_cache as the MergeTree default, check_cache_probability =
1, ~335k cache entries and 8 concurrent readers of a cached table: the
unmodified test failed 4 of 5 runs with Code 159 on a seed INSERT (elapsed
31.8-50.4 s, 98.9-99.3% of it priority write-lock wait, same stack as CI).
With this change it passed 3 of 3 under the same load, while 8 of 9
seed-shaped INSERTs into a cached table in the same windows waited 24-47 s.
With check_cache_probability = 0 and the same cache and readers, the
unmodified test passed 3 of 3 with seed INSERT lock waits under 0.4 s.

ClickHouse#114077 raised the INSERTs' bound instead, reading this wait as Azure
latency; it was closed after two quiet months and the test failed twice since.

Related: ClickHouse#114077

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-fuzzing Fuzzers: BuzzHouse (the query generator in the client), the AST fuzzer (QueryFuzzer), and the lib... and removed comp-testing Test content only (no production code). labels Nov 22, 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 comp-fuzzing Fuzzers: BuzzHouse (the query generator in the client), the AST fuzzer (QueryFuzzer), and the lib... groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants