Skip to content

Revert the O(1) insert-client lookup in 04365_cancel_insert_when_client_dies_distributed - #119948

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/revert-04365-o1-client-lookup
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/revert-04365-o1-client-lookup

Conversation

@groeneai

@groeneai groeneai commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #119778
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):

Reverted the O(1) insert-client lookup in 04365_cancel_insert_when_client_dies_distributed, which made that test's cancellation guard flip on the arm_binary lane.

Description

This reverts my #119778, which @alexey-milovidov requested in #96844 and approved 29 minutes before
it merged. Since then the test's anti-vacuity guard flips to 0 on Stateless tests (arm_binary, parallel), reddening #119819 and my own #117702. CIDB, that lane and test only:

test file revision window runs FAIL
pre-#111157 06-22..08-18 15:12 21183 10
#111157 8a43197aa9f9 08-18 15:14..09-13 15:47 10251 0
#119778 fc2b4b22204e4 09-13 15:52..09-14 11:15 280 2

Siblings 02434 and 04366, untouched by #119778, are 281/0 and 280/0 there: only the file it
changed regressed.

The guard passes only if a kill lands while the server is holding an insert, ~17 ms of a ~108 ms
client cycle on a release build, so discovery latency decides where the kill lands. #119778 replaced
a /proc/*/cmdline sweep, which can only return a client already alive one poll, with an O(1) read
of a pid published at fork. A/B of both revisions interleaved on one RelWithDebInfo binary: 27.3
cancellations per run with the sweep against 18.9 (per-kill 28.2% against 15.5%, the uniform
in-flight share). That is the direction, not the size: neither arm flips locally on x86, so the case
for reverting is the rate above.

A plain revert, byte for byte back to 8a43197aa9f9, validated on RelWithDebInfo (the arm_binary
build type) on x86; I cannot match ARM locally.

Two disclosures. The sweep costs O(processes on the host): on the shared 59-slot box I test on it
takes 85 to 1820 ms per poll and the guard flips there instead, 21 of 50 runs, so this is a trade-off.
And the failure @ alexey-milovidov reported is on a private lane I cannot read, which #119778 aimed at
and was never shown to fix there; this revert may reopen it.

CIDB query behind the table
SELECT multiIf(check_start_time < toDateTime('2026-08-18 15:14:31'), '1 pre-#111157',
               check_start_time < toDateTime('2026-09-13 15:47:58'), '2 #111157 8a43197aa9f9',
                                                                     '3 #119778 fc2b4b22204e4') AS window,
       count() AS runs, countIf(test_status IN ('FAIL','ERROR')) AS fails
FROM default.checks
WHERE test_name  = '04365_cancel_insert_when_client_dies_distributed'
  AND check_name = 'Stateless tests (arm_binary, parallel)'
  AND test_status IN ('OK','FAIL','ERROR')
  AND check_start_time >= toDateTime('2026-06-22 00:00:00')
GROUP BY window ORDER BY window
window                     runs    fails
1 pre-#111157             21183      10
2 #111157 8a43197aa9f9    10251       0
3 #119778 fc2b4b22204e4     280       2

The window boundaries are revision boundaries, not merge dates: a pull request branched before
#111157 merged still ran the old file, so 2026-08-18 15:14:31 is the first run on that lane after
the last pre-#111157 one. Both failures in window 3 are the same signature, @@ -1,3 +1,3 @@ with
both 500000 data lines intact and -1 / +0 on the guard line, on two different pull requests
rather than one retried, and neither carries LLVM Profile Error (the separate coverage-lane facet,
closed by merged #113619).


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

…ient_dies_distributed"

This reverts commit fc2b4b2, restoring
tests/queries/0_stateless/04365_cancel_insert_when_client_dies_distributed.sh byte for byte
to its 8a43197 (ClickHouse#111157) content.

That commit regressed the test on the public arm_binary lane. CIDB, on
Stateless tests (arm_binary, parallel), this test only:

  test file revision            runs    FAIL    rate
  pre-ClickHouse#111157                  21183      10    0.047%
  ClickHouse#111157 8a43197         10251       0    0%
  ClickHouse#119778 fc2b4b2          220       2    0.909%

The two siblings that commit did not touch are clean over the same post-merge window
(02434_cancel_insert_when_client_dies 221 OK / 0 FAIL, 04366 220 OK / 0 FAIL), so only the
file it changed regressed.

Mechanism. thread_cancel kills the insert client at a random point in its life, and the
test's anti-vacuity guard passes only if some kill lands while the server is holding an
insert. On a release build that window is about 17 ms of a 108 ms client cycle, so the
client-discovery latency decides where the kill lands. The reverted commit replaced a
/proc/*/cmdline sweep, which can only return a client that has already been alive one poll,
with an O(1) read of a pid the client publishes at fork, which returns within about 10 ms
and therefore lands the kill in the client's startup phase, where the server has no query
to cancel. An A/B of both revisions on one RelWithDebInfo binary, interleaved so both see
the same conditions, measures the per-kill cancellation probability at 28.2 percent for the
sweep against 15.5 percent for the O(1) lookup, and 15.5 percent is the uniform in-flight
share. The commit also raised the kill count by 26 percent, which is why the lost quality
is invisible on a debug build.

The cost the reverted commit set out to remove, a /proc sweep starving once the host carries
tens of thousands of processes, was measured on a shared development machine and has never
been observed in CI: the identical code ran 10251 times on arm_binary without one failure.
Synchronising the kill on real server progress is the better design, but one client round
trip costs about 64 ms against a 17 ms window, so it needs a different workload and is out
of scope for this revert.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 14, 2026
@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; 2 gate findings plus 8 from my own
cold pass; bounded: 1 full pass + 1 fix round + 1 delta recheck). The diff itself needed no change:
every AGREE below landed in the PR description, which is why the description states the provenance,
the trade-off and the private lane.

# Sev Finding Verdict Evidence / action
1 ⚠️ The restored sweep records a pid during the scan and signals it later with no second identity check, so a reused pid could be signalled (04365_..._distributed.sh:76,80) DISAGREE Property conceded, action declined. #119778 measured that 12 to 50% of sweep-discovered kills already hit an exited process, and the interleaved A/B on one binary still measures 27.3 cancellations per run for the sweep against 18.9 for the O(1) lookup, so the loss is priced into the number that justifies this revert; a kill to an exited pid is a no-op. The harmful case needs pid reuse inside ~100 ms, and the match string carries the per-run database name, so no other test's client can match. The fix is separable (recheck /proc/$PID/cmdline before kill), but it would insert a fork and a read between discovery and kill in the one PR whose thesis is that discovery latency decides where the kill lands, and it would ship a revision with no CI history in place of one with 10251 clean runs.
2 ⚠️ count() > 0 cannot discriminate between the two revisions or detect partial mechanism failure, so a passing run proves nothing DISAGREE Observation conceded in full; it is a pre-existing property of the test being restored and the PR claims nothing else. The ask is already met in a stronger form: the deciding lane's own history is 10251 runs with 0 failures against 280 with 2 (Fisher exact p ~ 1.4e-3), a sample no A/B I could schedule would approach, and I have no ARM hardware. The alternative asked for, synchronising on server-side insert progress, is the branch Gate A offered against reverting and I rejected it on measurement: the in-flight window is 17 ms while one client round trip costs 50 to 64 ms. Tightening the oracle to a cancellation count would raise the flake rate on that lane, since it fails exactly when the environment degrades.
3 ⚠️ The description did not say the reverted commit was requested and approved by its reviewer AGREE, fixed The description now opens with it and closes by saying this revert may reopen the private-lane failure it was aimed at.
4 ⚠️ "the cost #119778 aimed at has never appeared in CI" is a universal claim I cannot support AGREE, fixed Scoped to the public signal; the private lane is named as unreadable rather than as empty.
5 ⚠️ The CIDB table had no window boundaries and a stale denominator (220) AGREE, fixed Re-measured independently at 11:15Z (280 runs, 2 failures), boundaries stated, query and output in the folded block of the description.
6 ⚠️ Both provenance links sat inside the template's comment block and rendered as nothing AGREE, fixed Moved below the marker; issues/96844 corrected to pull/96844.
7 💡 The local A/B gives the direction of the effect but nothing near the observed rate AGREE, fixed Said so in the description rather than leaving it to be found.
8 💡 Nothing in the file warns the next reader that the sweep's latency is load-bearing DISAGREE Motivation belongs in the commit message, which carries the mechanism in full and which git blame on the restored lines resolves to. A byte-for-byte revert is worth more here than an in-file note.
9 ⚠️ 50 local runs of the restored file gave 29 OK / 21 FAIL, against an expected 100/100 DISAGREE Every failing run has exactly 0 cancelled queries in query_log, so the guard is truthful; server-side insert time is identical in failing and passing runs (17.5 against 17.0 ms mean), so the server is not starved; the failures arrive in two contiguous blocks rather than independently; and in the sampled 20-pair A/B the single flip of the restored arm is the pair where one sweep poll cost 442 ms at 5309 host processes, while the O(1) arm never flipped locally, which is the inverse of the CI direction. Disclosed in the description instead of hidden.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-8:20260914-110900

@clickhouse-gh clickhouse-gh Bot closed this Sep 14, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ada9469]

Summary: ✅


AI Review

Summary

This PR reverts the O(1) client lookup in 04365_cancel_insert_when_client_dies_distributed back to the older /proc/*/cmdline sweep to recover the public arm_binary lane. The change is small, but I do not think it is ready as-is because it restores the exact cancellation mechanism that was already failing on the private amd_release, distributed cache, meta in keeper, s3 storage, parallel lane.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/04365_cancel_insert_when_client_dies_distributed.sh:76] thread_cancel is supposed to make the anti-vacuity guard prove that at least one insert was actually cancelled, but this restored /proc/*/cmdline scan is the same code path that previously produced the 500000 / 500000 / 0 failure on the private distributed cache lane Alexey linked in Columns Cache #96844 (comment). The failure's bash log shows this exact line-76 scan immediately before kill, so reverting to it without new evidence just moves the known flake from public arm_binary back to the private release lane.
    Suggested fix: either keep a constant-time client identity handoff here, or replace the cancellation trigger with one that does not depend on process-list scan latency on either lane.
Final Verdict

Changes requested: the revert restores a previously failing cancellation mechanism on another CI lane, so I would not merge it without evidence that the private lane no longer regresses or a lane-independent replacement for the /proc sweep.

PID="$CANDIDATE"
break
fi
PID=$(grep -Fa "query_id=$TEST_MARK" /proc/*/cmdline | grep -Fav grep | grep -Fav insert_data | grep -Eoa "/proc/[0-9]*/cmdline:" | grep -Eo "[0-9]*" | head -1)

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 restores the same /proc/*/cmdline sweep that was already failing on the private Stateless tests (amd_release, distributed cache, meta in keeper, s3 storage, parallel) lane Alexey linked in #96844 (comment): the 04365 failure there is the same 500000 / 500000 / 0 guard flip, and its bash log shows this line-76 scan in the trace immediately before kill.

So even if this fixes the public arm_binary regression, merging the plain revert just moves the known flake back to the private release lane rather than removing it. Can we either keep a constant-time client handoff here, or provide evidence from that lane that the restored scan no longer regresses?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Premise granted where I can check it: line 76 is the restored sweep, and the file is byte-for-byte the pre-#119778 revision, so this does return the design that was in force while that lane was red. The PR body says that at the close and I am not claiming the revert is neutral there.

Two corrections to the citation. The comment you link carries no signature and no bash log: it reports 35 failures in 90 days with 24 on master and asks for an investigation. And that private report is HTTP 401 for this account (re-measured today), with 0 rows in public CIDB for any distributed cache or meta in keeper lane in 90 days. The private facet relayed to me is consistent with your claim: 32 of 32 master-branch failures of this test on the private lanes in 30 days carry the same -1/+0 flip.

On (a): the constant-time handoff is the commit being reverted, and it is the measured cause of the public regression. Stateless tests (arm_binary, parallel), this test only:

design in force runs FAIL
snapshot + long sleeps (pre-#111157) 21183 10
sweep poll (#111157 8a43197aa9f9) 10251 0
O(1) pid file (#119778 fc2b4b22204e4) 313 2

Siblings unchanged on the same lane and window (02434 314/0, 04366 313/0); Fisher one-sided p = 8.7e-4. The sweep costs 85-300 ms per poll, so the kill lands late, inside the roughly 17 ms window where the server holds the insert. The O(1) lookup returns about 10 ms after fork, so kills rose from 0-8 to 110-133 per run while per-kill conversion fell from 28% to 15%, and a whole 40 s window can pass with no cancellation logged. Discovery latency is load-bearing here, so a constant-time handoff that also keeps the public lane green needs the kill synchronised on observed server-side insert progress, and this workload cannot carry that: about 17 ms in flight against a 50-64 ms client round trip. That is a separate change with its own before and after, not a rider on a revert.

On (b): I cannot read that lane, for the reason above. The same standard cuts both ways: the O(1) lookup synced down at 2026-09-13 15:49Z and I hold no post-sync measurement of that lane either, so it has not been shown to fix it. And on your own reading of that log, a scan immediately before kill means the kill did land, which makes that failure a conversion failure rather than the discovery starvation the reverted commit removed.

So I am keeping the plain revert. The #96844 ask stays open on my side after this merges, and if that lane reds again the design named above goes in its own PR with that lane's own numbers. Whether to take the public restore now or hold for one change covering both lanes is @ alexey-milovidov's call, as the reviewer who requested and approved the commit being reverted.

@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Fixed in another PR.

@clickhouse-gh clickhouse-gh Bot added comp-distributed Distributed table engine & query routing across shards (sharding/load balancing). 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-distributed Distributed table engine & query routing across shards (sharding/load balancing). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants