Skip to content

Verify integration nodes reached the requested state after a compose action - #116044

Open
groeneai wants to merge 5 commits into
ClickHouse:masterfrom
groeneai:integration-harness-verify-node-state
Open

groeneai wants to merge 5 commits into
ClickHouse:masterfrom
groeneai:integration-harness-verify-node-state

Conversation

@groeneai

@groeneai groeneai commented Aug 24, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #104437

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

test_keeper_session_refuse_stale_server::test_session_refused_on_stale_keeper failed on
#104437's Integration tests (amd_tsan, 3/6)
with Cannot wait ZooKeeper container (probably it's a iptables-nft issue) after a 180 s timeout,
on a host whose network was fine. From the artifacts: zoo3's graceful stop overran
stop_grace_period: 5s and it was SIGKILLed, then docker compose start zoo1 zoo2 zoo3 returned
0 having issued a /start call for zoo1 and zoo2 only (dockerd /start POST counts: zoo1 2,
zoo2 2, zoo3 1, and zoo3's is fixture startup). process_integration_nodes logged
Started zookeeper nodes: (zoo1, zoo2, zoo3), so the failure surfaced 180 s later at an unrelated
frame, blaming the firewall.

Neither the exit code nor the printed output distinguishes success from a silent skip. On compose
2.29.7 (CI's pin) I measured start printing both Starting and Started for a service that
stayed exited(7), returning 0. Only the daemon's state is reliable.

process_integration_nodes now inspects each requested node after the compose call and raises if
its State.Status is not what the action asked for, naming the node, container, status and exit
code. State.Running is not usable here: it is also true for paused and restarting. The read is
fresh, since a docker-py handle held across the call reports the old value.
wait_zookeeper_nodes_to_start reports the blocking node, its resolved IP (empty is the tell),
container status and elapsed time, with iptables-nft no longer all it says.

I could not reproduce the compose/dockerd race itself, here or in #109037; the artifacts are the
evidence for the failure, the measurements above for the mechanism this check asserts against.
#109037 made the invocation atomic, fixing a concurrent-compose race; this skip is inside one
invocation. Out of scope: stop_zookeeper_nodes bypasses this seam with a serial per-node loop.

Requested by @ bacek; no open issue found for it.

Validation

All 8 suites using these wrappers pass: test_keeper_session_refuse_stale_server,
test_check_table (kill path), test_inserts_with_keeper_retries, test_read_only_table,
test_reload_zookeeper, test_remove_stale_moving_parts,
test_replicated_user_defined_functions, test_replicated_users. The last four include the
subset-starting callers (['zoo2','zoo3'], ['zoo2']) that a wrongly scoped check would break.
Target test 20/20 on repeat.

Both directions on the real keeper fixture, with the victim not running after a
successful compose start: before the change the wait burns its whole budget and blames
iptables-nft; after it, the failure is immediate (0.2 s) and names the node. Negative control
with every node genuinely up stays silent.

test_cluster_waiters/test_integration_node_state.py adds 13 arms that bind the shipped methods
and run in 0.1 s with no Docker. Seven cover the check: message contents, a negative control,
paused and restarting rejected for start, the read happening after the action in both
directions, subset scoping, the action/status matrix. Six cover the diagnostic, on a faked clock:
message contents, the named node being the one that blocked rather than the first or last, subset
scoping, each of the helper's two lookups failing without masking the reported failure, and a
negative control that returns without spending the budget. None of the 8 suites can see any of
it, since each drives only the success path.

Nine mutants confirm the arms bite: an early-return no-op check reddens all seven of its arms; a
State.Running oracle reddens paused and restarting; a handle cached across the action
reddens freshness; a fixed node set reddens scoping, freshness and the matrix; the old message
reddens five diagnostic arms; dropping the blocking-node tracking reddens three; unguarding
either lookup reddens its own arm; removing the early return reddens the negative control.


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

…action

process_integration_nodes issued one `docker compose <action> <node...>` and
treated rc=0 as proof that every requested node reached the requested state,
logging `%sed ... nodes: %s` unconditionally.

That is not proof. Measured on compose 2.29.7, the version CI pins
(ci/docker/integration/runner/Dockerfile), against a 3-service project:
`start` on a service that is `exited(7)` prints both `Starting` and `Started`,
returns 0, and leaves the service `exited(7)`; `start` on an already-running
service omits it from the output entirely, also with 0. Neither the exit code
nor the printed output distinguishes success from a silent skip.

test_keeper_session_refuse_stale_server::test_session_refused_on_stale_keeper
hit this on PR ClickHouse#104437's `Integration tests (amd_tsan, 3/6)` at head
7de491b. zoo3's graceful stop overran
`stop_grace_period: 5s` and it was SIGKILLed (exit 137,
hasBeenManuallyStopped=true, so `restart: always` correctly did not resurrect
it); the following `docker compose start zoo1 zoo2 zoo3` returned 0 having
issued a `/start` call for zoo1 and zoo2 only. dockerd `/start` POST counts for
the whole job: zoo1 2, zoo2 2, zoo3 1, and zoo3's single one is fixture
startup. Keeper logs corroborate: `Starting ClickHouse` appears twice for
keeper1 and keeper2, once for keeper3. The harness logged
`Started zookeeper nodes: (zoo1, zoo2, zoo3)`, then polled a container with no
IP for 180 s (321 `bad hostname` lines) and raised a message naming
`iptables-nft` on a run where the host network was demonstrably fine. Three
separate reporters read the failure as an infrastructure problem.

The listing race itself did not reproduce, here or during ClickHouse#109037, so this
change does not try to fix it. It removes the amplifier: any compose-side
omission, this one or a future one, now fails immediately and correctly
attributed instead of becoming a success line plus a 180 s timeout at an
unrelated frame.

The oracle is `State.Status`, not `State.Running`, because Running is also true
for `paused` and `restarting` (measured: paused -> Status=paused Running=true;
restarting -> Status=restarting Running=true), which are exactly two states a
`start` must not accept. The status is read after the action, because a
docker-py handle caches its state and one held across the call reports the old
value (measured: a handle fetched while up still reported `running` after a
real `compose stop`; only a reload or a fresh fetch reported `exited`).

This is not a regression of ClickHouse#109037, which replaced N concurrent compose
processes with one atomic invocation and is still in place: that fixed a
concurrent-compose race, whereas this omission happens inside a single
invocation.

Not in scope: raising `stop_grace_period` (the test wipes logs and snapshots
before restarting, so a SIGKILLed keeper is harmless, and an `exited(137)`
service was measured to start fine); retrying the compose call (it would mask
the signal this check exists to surface); routing stop_zookeeper_nodes, which
uses a serial per-node loop, through this seam.
The three properties that make the post-condition check meaningful are all
invisible to the suites that use the seam, because every one of them drives
only the success path: a check that silently became a no-op would keep all
eight of them green.

The arms bind the shipped ClickHouseCluster methods to a stub rather than
copying their logic, in the mocked-harness shape tests/integration/
test_cluster_waiters already uses for helpers/cluster.py, so they need no
Docker and no cluster and run in 0.09s. Four mutants were checked: an
early-return no-op reddens all seven, State.Running reddens the paused and
restarting arms, a handle cached across the compose call reddens the
freshness arm, and a fixed node set reddens scoping, freshness and the
action matrix.

A test asserting that compose lied at the docker layer stays out of scope:
it would have to fabricate the dockerd listing race, which did not
reproduce.
The post-condition check added to process_integration_nodes was already
pinned by seven mocked arms. Its sibling half, the diagnostic
wait_zookeeper_nodes_to_start builds on timeout and the
describe_container_state helper it calls, was not: reverting the message
to the old bare iptables-nft string, dropping the per-iteration
blocking_node assignment so the message names the wrong node, or
unguarding either lookup in the helper so a diagnostic masks the failure
it exists to report, all left every arm green. That half is what a
reporter reads, and misreading it as a firewall problem is what this
change exists to prevent.

Six arms cover it, on a faked clock so the whole budget elapses
instantly and the elapsed figure the message reports is exact: message
contents, the named node being the one that blocked rather than the
first or last of the request, subset scoping, each of the helper's two
except branches failing without the reader losing the ZooKeeper failure,
and a negative control that returns without spending the budget. A
second stub class supplies only the five attributes the waiter and its
helper touch, and binds the shipped methods, so the arms track
helpers/cluster.py rather than a copy.

Nine mutants confirm the arms bite, verdicts read from junit-xml: the
five above plus the four from the check, which redden exactly the arms
they did before the file grew. No source line changes.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Aug 24, 2026
@groeneai

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

Three review rounds on this change: two cold reviews that each bounced it back for
missing test coverage, and a third that found nothing. Findings and how each was
resolved, using the ❌ blocker / ⚠️ major / 💡 nit taxonomy.

# Finding Verdict
⚠️ The post-condition check shipped with no committed test. Every suite that uses the seam drives only the success path, so an early-returning no-op check kept them all green. Agreed, fixed. Seven mocked arms added, binding the shipped methods; the no-op mutant now reddens all seven.
⚠️ The timeout diagnostic was still unpinned after that: reverting the message, losing the blocking node, or unguarding either lookup in the helper left the seven arms green. Agreed, fixed. Six more arms on a faked clock; five mutants map onto them.
💡 The inspect-failure guard in the check has no arm of its own. Disagreed. Unlike its sibling in the diagnostic helper it cannot mask anything: with or without it an exception propagates and from ex keeps the original. It only reframes the message on an already-failing path.
💡 test_inserts_with_keeper_retries runs the restart in a Pool worker and only calls job.wait(), so a raise there is swallowed. Disagreed. Pre-existing error handling in that test, unchanged here, and it makes the check quieter there rather than louder. It never fired across 50 repeat runs.
💡 The stop row of the status table has no producer. Disagreed. casa_del_dolor/dolor.py does pass stop through this seam, and the matrix arm pins the row.
💡 One red in the 50-run repeat pass. Disagreed. test_create_role_then_reference_it_no_unknown_role timing out at the harness's own 300 s budget. It crosses this seam zero times, re-ran 4/4 with the change and 3/3 on the pristine base, and master has since raised that budget in 882f2538b3af55f.

Also checked and clear: the diff removes the old exception text, and nothing in the
repo or in TEST_FAILURE_PATTERNS matches on it; kill plus restart: always is safe,
since dockerd marks an API-initiated kill hasBeenManuallyStopped and suppresses the
policy; project-<service>-1 is the real container name everywhere, as no compose file
in tests/integration/compose/ sets container_name or scales a service; importing
helpers/cluster.py from a Docker-free arm is side-effect free.

Session id: cron:clickhouse-review-slot-8:20260824-023500

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for the mechanism this asserts against: on compose 2.29.7 (CI's pin) start prints Starting and Started for a service that stays exited(7) and returns 0, 100% of the time; and an already-running service is omitted from the output with rc=0, matching the CI output shape. Yes for the end-to-end before/after on the real keeper fixture. No for the compose/dockerd listing race itself, which did not reproduce here or in #109037 - the job artifacts (dockerd /start POST counts: zoo1 2, zoo2 2, zoo3 1) are the evidence for that.
b Root cause explained? zoo3's graceful stop overran stop_grace_period: 5s, was SIGKILLed (exit 137, hasBeenManuallyStopped=true), and the following docker compose start zoo1 zoo2 zoo3 returned 0 having issued /start for zoo1 and zoo2 only. process_integration_nodes treated rc=0 as proof and logged success, so the failure surfaced 180 s later in wait_zookeeper_nodes_to_start against a container with no IP (321 bad hostname lines), blaming iptables-nft.
c Fix matches root cause? Yes. It asserts the post-condition the function already claimed in its own log line, and reports what the wait measured instead of guessing. No widened timeout, no retry, no stop_grace_period change, no host-networking change, nothing suppressed.
d Test intent preserved / new tests added? All 8 suites that use these wrappers pass; no test weakened or removed. New test file tests/integration/test_cluster_waiters/test_integration_node_state.py: 13 arms binding the shipped methods to stubs, 0.10 s, no Docker, parallel-safe, alongside the existing mocked harness in that directory. Seven cover the post-condition check: message contents, a negative control, paused and restarting rejected for start, the read happening after the action in both directions, subset scoping, the action/status matrix. Six cover the timeout diagnostic on a faked clock: message contents, the named node being the one that blocked rather than the first or last, subset scoping, each of the helper's two lookups failing without masking the reported failure, and a negative control that returns without spending the budget. The 8 suites can observe none of it, since each drives only the success path. Nine mutants confirm the arms bite: an early-return no-op check reddens all seven of its arms; a State.Running oracle reddens paused and restarting; a handle cached across the action reddens freshness; a fixed node set reddens scoping, freshness and the matrix; the old message reddens five diagnostic arms; dropping the blocking-node tracking reddens three; unguarding either lookup reddens its own arm; removing the early return reddens the negative control. A further 21 arms against real containers were used during development. A test asserting "compose lied" at the docker layer stays out of scope - it would have to fabricate the unreproduced race.
e Both directions demonstrated? Yes, on the real keeper fixture with the victim ending up not running after a successful compose start, injected two ways. Before: the wait burns its whole budget (12.4 s / 16.7 s of a 12 s budget) and blames iptables-nft. After: raises in 0.2 s with Failed to start zookeeper node zoo3: container ...-zoo3-1 status is exited, expected one of ['running'] (exit code 0, OOM killed False). Negative control with every node genuinely up stays silent in both arms.
f Fix is general across code paths? Fixed at the single seam all 5 call sites cross, so kill_zookeeper_nodes, start_zookeeper_nodes and both casa_del_dolor/dolor.py call sites are covered for every integration, not just zookeeper. stop_zookeeper_nodes uses a serial per-node loop and bypasses the seam - out of scope, disclosed in the description.
g Fix generalizes across inputs (params/datatypes/wrappers)? Action matrix start/stop/kill/unknown (unknown is a no-op, so restart/up callers are unchanged); node-list shapes all-three / two-node subset / single-node subset / node absent from the request (the check iterates the nodes argument, never a fixed tuple - three in-tree tests start only ['zoo2','zoo3'] and one starts ['zoo2']); container statuses running, exited, paused, restarting, removed; exit codes 7 and 137. State.Running was rejected because it is also true for paused and restarting.
h Backward compatible? (maintainer-approved exception only) N/A - test harness only. No src/, no settings, no SettingsChangesHistory.cpp, no serialization format, no compose file. Actions other than start/stop/kill keep their existing behaviour exactly.
i Invariants and contracts preserved? The asserted invariant is the one the success log already claimed. No lock, no shared state, no ordering change; the check runs after the action and before the success log. The container state is read fresh, since a docker-py handle held across the call reports the stale value. describe_container_state is failure-path-only and cannot raise, so a diagnostic can never mask the error it describes - asserted by two arms, one per except branch. from err chains preserved; an inspect failure becomes a clear Cannot inspect ... message rather than a bare traceback.

Session id: cron:clickhouse-impl-slot-4:20260824-021200

@clickhouse-gh

clickhouse-gh Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5c8428f]

Summary: ❌

job_name test_name status info comment
Code Review ERROR

AI Review

Summary

This PR hardens the integration harness around docker compose node actions by checking that the requested containers actually reached the expected post-action state, bounding the extra Docker API requests on both the main and diagnostic paths, and adding focused stub-based coverage for the new checks and ZooKeeper timeout message. I reviewed the current head together with the existing PR discussion and I did not find a remaining correctness issue that warrants a new inline review comment.

Missing context / blind spots
  • ⚠️ I could not execute tests/integration/test_cluster_waiters/test_integration_node_state.py directly in this environment because /usr/bin/python3 does not have the pytest module installed; the run failed before collection (ci/tmp/pr116044_test_integration_node_state.log).
  • ⚠️ I also could not complete a Praktika integration run here because the required CH_AMD_TSAN artifact was missing from S3, so no ClickHouse binary ever became available and integration_test_job.py aborted before pytest collection (ci/tmp/pr116044_praktika_test_integration_node_state.log).
Final Verdict

✅ No blocking review findings on the current head.

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

Copy link
Copy Markdown
Collaborator Author

cc @mstetsyuk, could you review this? docker compose start can exit 0, and even print Started, for a service it did not act on, so the integration harness logged a successful ZooKeeper restart for a node that was still down and the failure surfaced 180s later in the ZooKeeper waiter blaming iptables-nft; this compares the daemon's own view of every requested node against the requested state before logging success.

Comment thread tests/integration/helpers/cluster.py Resolved
The shared docker-py client is built with timeout=600, sized for image pulls. The
diagnostic added to wait_zookeeper_nodes_to_start makes two fresh Docker requests
(the container inspect, and the address lookup behind it) on a path where the
waiter's own 60/180s budget is already spent, so on a slow or wedged daemon it
could hold the caller for up to 20 minutes past the deadline it advertises.

Measured against a listener that accepts and never replies: describing a node
returned in 10.0s with the bound (two 5s requests), and was still blocked at a
25s observation cap without it. docker-py reads api.timeout per request, so
lowering it for the duration of the description bounds both calls; the previous
value is restored so unrelated callers of the shared client, including image
pulls, keep the long timeout.

Six arms in test_cluster_waiters pin the bound, its restoration on both the
succeeding and failing paths, and that a client with no request layer is still
described. Five mutants cover the ways the bound can silently stop working
(removed, leaked, applied to only one of the two calls, widened to the shared
value, or made the thing that breaks the diagnostic); each reddens only its own
arm. The nine mutants from the earlier rounds still redden exactly the arms they
did before, so the existing coverage is unaffected.
Comment thread tests/integration/helpers/cluster.py Resolved
check_integration_nodes_state inspects each requested node through the shared
docker client that ClickHouseCluster.start builds with timeout=600, which is
sized for image pulls. That call is on the main path, so an unresponsive daemon
held start_zookeeper_nodes / kill_zookeeper_nodes for up to 600s per node before
the ZooKeeper waiter even started. Three nodes reach 1800s, past the 900s
per-test timeout in tests/integration/pytest.ini, so the run was killed before
the "Cannot inspect" message it exists to produce was ever emitted.

Wrap the inspect in the existing bounded_docker_requests helper with its own
constant rather than reusing CONTAINER_DESCRIBE_TIMEOUT. The describe path is
best effort and only shapes the text of a failure that already happened, so 5s
is right there; this call decides whether a test passes, so expiring early would
turn a passing run red. Measured worst single inspect against a real daemon:
1.3ms idle, 39ms under container churn, 76ms under 96 API threads plus 16
start/kill loops, and 1.92s under 256 concurrent inspects. 30s keeps a 15.7x
margin over that worst case while capping three nodes at 90s, a tenth of the
per-test budget.

Verified against a TCP listener that accepts and never replies: the unbounded
code stayed blocked at a 45s observation cap while the bounded form raised in
30.03s, with the daemon confirming a connection in both arms so neither returned
without reaching the inspect. On a real daemon the passing path takes 1.1ms, a
stopped container is still rejected, and the shared timeout reads 600 again
afterwards on both paths.

Six new arms in test_cluster_waiters/test_integration_node_state.py pin the
per-node bound, its width relative to the describe bound, restoration on the
passing and both failing paths, and a client with no request layer. Each of six
mutants (bound removed, widened to 600, narrowed to 5, only the first node
bounded, restore dropped, guard removed) reddens only its mapped arm.
@clickhouse-gh

clickhouse-gh Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5c8428fbe with master b4f5ce407 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 4faa0468e; 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 705.82 MiB 702.99 MiB -2.83 MiB (-0.40%)

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, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 5c8428f

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.

Check / test Reason Owner / fixing PR
Code Review job reports no Result provided after its review was already posted: the agent's nested integration_test_job.py verification exits 1 (no CH_AMD_TSAN binary in this job's workspace), then runner.py:956 iterates a None commit_authors a fix task is created (investigating at full effort, fixing-PR link to follow on this PR)

Not caused by this PR: the diff is tests/integration/helpers/cluster.py plus
tests/integration/test_cluster_waiters/test_integration_node_state.py, with no file under
ci/, so it cannot reach the praktika runner or the review job's harness. This is a distinct
defect from the HTTP 401 Bad credentials robot-token failure fixed by #115232: that
signature is absent here (0 Bad credentials, 1 robot used, 0 retries).

Gate (a) 0 of 177 checks incomplete; gate (b) Finish Workflow and Mergeable Check both
success; gate (c) 38.8 min since the last check completed. The run is not void and not
skip-dominated in a way that hides signal: Config Workflow and Style check are both
success, and 25 of 35 Integration tests nodes ran, so the suite this diff touches was
exercised. Exactly one failing leaf.

Session id: cron:our-pr-ci-monitor:20260824-103000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the Code Review job ERROR on this PR: #116121

@groeneai

Copy link
Copy Markdown
Collaborator Author

Correction to my earlier note: #116121 was closed by @maxknv, who is fixing this in the AI review job itself rather than in ci/praktika. The Code Review line on this PR's ledger is owned by that forthcoming job-side fix, not by #116121.

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-testing Test content only (no production code). 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.

1 participant