Skip to content

TCP: report the driver version, not 0.0.0, so distributed queries work - #725

Merged
alex-clickhouse merged 4 commits into
mainfrom
alex-clickhouse/tcp-client-version
Nov 13, 2026
Merged

alex-clickhouse merged 4 commits into
mainfrom
alex-clickhouse/tcp-client-version

Conversation

@alex-clickhouse

@alex-clickhouse alex-clickhouse commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The native TCP client reported client version 0.0.0 in its handshake and in the ClientInfo of every query. A ClickHouse server refuses to send a distributed query on to another server when the client that started it reports 0.0.0. So clusterAllReplicas, remote() and Distributed tables failed through this client:

ClickHouseTcpServerException : Sending a distributed query with unknown (zero) client version. The query context was not initialized as an initial query: While executing Remote

Why the client sent 0.0.0. ClientHandshakeParameters.VersionMajor and VersionMinor were never set, and ClientInfo wrote client_version_patch as a literal 0. The client also sends query_kind = InitialQuery, and the server fills in its own version only for a query that has no query kind (Session.cpp). The check that refuses the zero version is in RemoteQueryExecutor.cpp.

What changes. The client reports this package's version (major, minor, patch) in the Hello and in every ClientInfo. It reads the version from the TCP assembly's AssemblyInformationalVersion, which the release build sets with /p:Version. clickhouse-go does the same with its own version (2.51.0 in client_info.go). A build whose version is missing, cannot be read, or is 0.0.0 (the benchmark builds use 0.0.0-baseline and 0.0.0-pr.N) reports 1.0.0 instead.

How this was found. StreamAsync_CancelledMidResult_StopsTheQueryOnTheServer and StreamAsync_EnumerationAbandonedEarly_StopsTheQueryOnTheServer fail in the Cloud TCP job on main and on #724. Both read system.query_log through clusterAllReplicas(default, ...). On a Cloud service the other replicas are remote, so that read is a distributed query. The tests were right; the client was wrong. On the local test container the same lookup reads the local node only, which is why the regular matrix never saw it.

Tests

  • ClientVersionIntegrationTests.ExecuteScalarAsync_RemoteQueryToTheSameServer_Succeeds runs remote('localhost:9000', system.one, ...) with prefer_localhost_replica = 0, so the local container takes the remote path. On main it fails with the same error as Cloud; with this change it passes.
  • ExecuteScalarAsync_QueryThatReadsEveryCloudReplica_Succeeds (Cloud only) runs clusterAllReplicas(default, system.one).
  • ExecuteAsync_AnyQuery_RecordsTheDriverVersionAsTheClientVersion reads client_version_major/minor/patch from system.query_log.
  • ClientVersionTests: parsing of 1.5.0+hash, 1.4.0-rc2+hash, 0.0.0-baseline, empty and unparsable versions, and the handshake defaults.
  • Local runs of ClickHouse.Driver.Tcp.Tests on net8.0, net9.0, net10.0: 4199 passed, 1 skipped (the Cloud-only test), 0 failed. main at c8f641a: 4186 passed.
  • The Cloud TCP job on this PR runs the two cancellation tests that fail on main.

Checklist

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG

🤖 Generated with Claude Code


Note

Medium Risk
Touches native protocol handshake and per-query ClientInfo metadata used by distributed query routing; behavior change is intentional but affects all TCP connections.

Overview
Fixes distributed queries failing on ClickHouse 26.8+ because the native TCP client advertised 0.0.0 in the handshake and every query’s ClientInfo. The driver now derives major/minor/patch from the assembly informational version via a new ClientVersion helper, defaults handshake metadata to that value, and writes the patch on the wire instead of a hard-coded zero; unusable or 0.0.0 builds fall back to 1.0.0.

Adds unit tests (parsing, wire layout, handshake defaults), integration tests (remote, clusterAllReplicas, system.query_log columns), a changelog entry, and TCP docs on how client_name / client version appear on the server.

Reviewed by Cursor Bugbot for commit 04bc611. Bugbot is set up for automated code reviews on this repo. Configure here.

alex-clickhouse and others added 2 commits November 12, 2026 13:51
The TCP client reported client version 0.0.0 in its Hello and in the
ClientInfo of every query: the version fields were never set, and the
patch was written as a literal 0. It also sends query_kind InitialQuery,
so the server does not fill in its own version. A server refuses to send a
distributed query on when the initiator version is 0.0.0, so
clusterAllReplicas, remote() and Distributed tables failed with
"Sending a distributed query with unknown (zero) client version". On
ClickHouse Cloud this broke every system.query_log lookup in the TCP
suite's cancellation tests.

The client now reports this package's version (major, minor, patch) from
the assembly's informational version, as clickhouse-go reports its own.
A build with no usable version, or with 0.0.0 (benchmark builds), reports
1.0.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

AI review gate — AI review passed

Clean review from: Cursor Bugbot.

- A wire test writes ClientInfo with version 12.34.56 and reads the three
  fields back. A dev build reports 1.0.0, so a dropped minor or patch did
  not show in the other tests.
- ClientVersion.Fallback is a property, so Current does not depend on the
  order of the static fields.
- The remote() test asks the server for its native port.
- The changelog entry names the server versions that refuse 0.0.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ClickHouse.Driver.Tcp/Protocol/ClientVersion.cs 92.30% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@alex-clickhouse
alex-clickhouse marked this pull request as ready for review November 13, 2026 08:49
Copilot AI balanced review requested due to automatic review settings November 13, 2026 08:49
@alex-clickhouse
alex-clickhouse enabled auto-merge (squash) November 13, 2026 08:50

Copilot AI left a comment

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.

🟡 Changes recommended

The server-visible client identity change lacks required client documentation explaining package-version reporting and the 1.0.0 fallback.

1 open issue
What changed in this PR

Fixes distributed-query failures in the native TCP client by reporting the driver version instead of 0.0.0. The HTTP client is unchanged.

Changes:

  • Reads the assembly version, falling back to 1.0.0 for missing, invalid, or zero versions.
  • Reports major/minor in the handshake and major/minor/patch in per-query metadata.
  • Adds parsing, wire-format, distributed-query, and query-log tests, plus a changelog fragment.
File Description
ClickHouse.Driver.Tcp/​Protocol/​ClientVersion.cs Resolves the driver version and nonzero fallback.
ClickHouse.Driver.Tcp/​Protocol/​ClientMetadata.cs Retains the patch version for query metadata.
ClickHouse.Driver.Tcp/​Protocol/​ClientInfo.cs Writes the patch version instead of zero.
ClickHouse.Driver.Tcp/​Protocol/​ClientHandshakeParameters.cs Defaults version fields to the driver version.
ClickHouse.Driver.Tcp.Tests/​Protocol/​ClientVersionTests.cs Tests parsing, fallback, defaults, and wire encoding.
ClickHouse.Driver.Tcp.Tests/​Integration/​ClientVersionIntegrationTests.cs Tests distributed execution and server-recorded versions.
changelog.d/​725-tcp-client-version.fixes.md Documents the distributed-query fix.

Review effort: Balanced

Comment on lines +7 to +8
/// The client version the driver reports in its handshake and in the ClientInfo of every query: the version of this
/// package, as major, minor and patch.

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.

Added in 04bc611: a new section "Client name and version on the server" under "Logging and diagnostics" in docs/tcp.mdx. It lists the system.query_log / system.processes columns, says the version is the ClickHouse.Driver package version, and gives the 1.0.0 fallback with its reason.

@security-ai-gate-reviewer security-ai-gate-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated approval by the AI review gate.

The required AI review gate concluded SUCCESS on 1b0c0a5, and this change touches no path that requires a human reviewer. This approval is posted by an automated identity (security-ai-gate-reviewer[bot]), not a human, and is bound to the evaluated commit. A new push dismisses it and re-evaluates.

repo=ClickHouse/clickhouse-cs pr=#725 head=1b0c0a5a4c991d90f8b281d34492cee3387b3b8f

{
/// <summary>The version reported when the build carries no usable one.</summary>
/// <remarks>A property rather than a field, so <see cref="Current"/> can read it whatever the field order.</remarks>
internal static (int Major, int Minor, int Patch) Fallback => (1, 0, 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Major: Document the reported client version and fallback

The root AGENTS.md requires public behavior changes to be documented in docs/tcp.mdx in the same PR, but that page is unchanged. Users inspecting system.query_log or system.processes now see the driver version, and a build with a missing, invalid, or zero version reports 1.0.0; the changelog does not explain that fallback. Add a short note under Logging and diagnostics describing the version fields, their package-version source, and the fallback so users can interpret these values correctly.

A reply here is read on the next review: an explanation that holds up drops the finding.

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.

Added in 04bc611: a new section "Client name and version on the server" under "Logging and diagnostics" in docs/tcp.mdx. It lists the system.query_log / system.processes columns, says the version is the ClickHouse.Driver package version, and gives the 1.0.0 fallback with its reason.

@polyglotAI-bot

Copy link
Copy Markdown
Collaborator

Summary
This TCP-only change reports the driver version in the handshake and query metadata, with a nonzero fallback, to fix distributed queries rejected for an unknown client version. The regression coverage addresses remote execution and version reporting. Request changes for the missing user documentation required by the base-branch guidelines.

⚠️ Majors
  • ClickHouse.Driver.Tcp/Protocol/ClientVersion.cs:19 Document the reported client version and the 1.0.0 fallback in docs/tcp.mdx.
Missing context
  • This was a static review: the sandbox does not permit builds, test execution, or CI access. TCP matrix and Cloud test results would confirm runtime behavior.
Final verdict

⚠️ Request changes: add a short client-version reporting note to docs/tcp.mdx.

Automated review by Polyglot AI (gpt-6-astra) of 1b0c0a5. Replies on the inline threads are read on the next review. A maintainer can ask for a new review by mentioning @polyglotAI-bot or requesting a review from it.

The TCP page now says which client name and version ClickHouse shows in
system.query_log and system.processes, where the version comes from, and
when the client reports 1.0.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@security-ai-gate-reviewer security-ai-gate-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated approval by the AI review gate.

The required AI review gate concluded SUCCESS on 04bc611, and this change touches no path that requires a human reviewer. This approval is posted by an automated identity (security-ai-gate-reviewer[bot]), not a human, and is bound to the evaluated commit. A new push dismisses it and re-evaluates.

repo=ClickHouse/clickhouse-cs pr=#725 head=04bc611a48c671c1df64a213294a0189ed63e528

@alex-clickhouse
alex-clickhouse merged commit 9f6721c into main Nov 13, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants