Skip to content

Cherry pick #123622 to 26.9: Send the query id with OpenAI AI function requests - #127873

Merged
robot-ch-test-poll merged 12 commits into
backport/26.9/123622from
cherrypick/26.9/123622
Oct 27, 2026
Merged

robot-ch-test-poll merged 12 commits into
backport/26.9/123622from
cherrypick/26.9/123622

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Original pull-request #123622

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

george-larionov and others added 11 commits October 2, 2026 22:15
`OpenAIProvider` sends `X-ClickHouse-Query-Id` with `initial_query_id`, or
`current_query_id` for a background mutation, which has no initial query.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The `X-ClickHouse-Query-Id` header now carries the query id of the query
that makes the request. On a remote shard it is the shard's own query id,
which identifies the exact server that made the request and from which the
`initial_query_id` can be reconstructed via `system.query_log`. This is also
consistent with how the query id is exposed elsewhere. A background mutation
sends its task's `current_query_id`, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…m query id headers

The initial query id lets the endpoint group the requests of a distributed query.
Query ids from the native and gRPC protocols are not sanitized, so control
characters could inject extra headers.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… only `query_id`

- Introduce a base struct `AIRequest` with the fields common to chat and embedding
  requests (`function_name`, `query_id`); the chat request is renamed to `AIChatRequest`
  and both it and `AIEmbeddingRequest` inherit from the base.
- Sanitize the `X-ClickHouse-Query-Id` header with the existing `sanitizeForLog`
  (control characters become spaces) instead of a duplicated helper.
- Drop the `X-ClickHouse-Initial-Query-Id` header: the shard's own `query_id` is
  sufficient, and the initial query id can be reconstructed from it.
- Remove redundant comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`X-ClickHouse-Query-Id` carries the current query id, `X-ClickHouse-Initial-Query-Id`
the initial one, which is the same on all shards of a distributed query.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Send the query id with OpenAI AI function requests
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Oct 26, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! labels Oct 26, 2026
@george-larionov

Copy link
Copy Markdown
Member

@groeneai please resolve the merge conflicts in this cherry-pick (AnthropicProvider.{h,cpp}, OpenAIProvider.{h,cpp}). They come from getHeaders(), which exists on 26.9 but not in the cherry-pick's base:

  • Keep the getHeaders() declarations and definitions; change call to take const AIChatRequest &.
  • In both OpenAIProvider header hunks (chat and embedding), keep the getHeaders() loop and replace the chassert + X-ClickHouse-AI-Function lines with setCommonHeaders(http_request, ai_request) (resp. ai_embedding_request), matching master:
for (const auto & header : getHeaders())
    http_request.set(header.name, header.value);
setCommonHeaders(http_request, ai_request);

@groeneai

Copy link
Copy Markdown
Collaborator

Resolved as you described:

  • AnthropicProvider.{h,cpp}, OpenAIProvider.{h,cpp}: kept the getHeaders() declarations and definitions, and call takes const AIChatRequest &.
  • In both OpenAIProvider header hunks the getHeaders() loop is followed by setCommonHeaders(http_request, ai_request) (resp. ai_embedding_request); the chassert and X-ClickHouse-AI-Function lines are gone.

Every resolved region is byte-identical to master. Against backport/26.9/123622 the merge changes the same 11 files as #123622, and its added and removed lines are identical to #123622's diff.

Validated on the 26.9 tree with clang-22, debug build: tests/integration/test_ai_functions passes 128/128, including test_query_id_header and test_query_id_header_control_characters (run as a non-root user, with the mock server copied to /tmp). As a negative control, the official 26.9.26.20 binary fails those two tests.

The merge is on my fork and its first parent is this PR's head, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse resolve-26.9-cherrypick-123622
git push origin FETCH_HEAD:cherrypick/26.9/123622

(resolved head cd537fa8de7bdd4ff01048827f6631dcd7a38a03)

@robot-ch-test-poll
robot-ch-test-poll merged commit 3a9fcdc into backport/26.9/123622 Oct 27, 2026
1 check passed
@robot-ch-test-poll
robot-ch-test-poll deleted the cherrypick/26.9/123622 branch October 27, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants