Repository navigation
Send the query id with OpenAI AI function requests - #123622
Conversation
`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]>
|
Workflow [PR], commit [120570e] Summary: ✅
AI ReviewSummaryPR #123622 adds the current and initial query IDs to AI requests using the Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings or unresolved review concerns require changes. |
Build profile diff (arm_release)Commit See the job log for details. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
It is wrong to send initial_query_id instead of a query_id. Why?
The actual query_id on shards provides more precise information. Initial query_id can be reconstructed from it. For the purpose of distributed tracing, it is important to know what exact server has made a request. This is also important for audit purposes. This is also worth noting that you've named the header as Query-Id, and nothing tells that it is the initial query id - so it would lead to confusion. It is also inconsistent with all other cases of where the query_id is sent or exposed.
|
Everything else LGTM. |
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]>
This comment was marked as low quality.
This comment was marked as low quality.
…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]>
|
@alexey-milovidov the inference team needs this query ID for debugging customer issues, and the customer won't know their distributed query_ids, they will only know the initial ID. See this Slack thread. I'm going to add both in this PR if the query_id is also needed, see my next commit. |
This comment was marked as low quality.
This comment was marked as low quality.
… 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]>
|
🕵 The only red check, |
Cherry pick #123622 to 26.8: Send the query id with OpenAI AI function requests
Cherry pick #123622 to 26.9: Send the query id with OpenAI AI function requests
Merge backport/26.8/123622 into cherrypick/26.8/123622. The conflicts come from 26.8's provider shape (`call` returns `AIResponse`, `getHeaders()`, `embedTexts` returns its result), which differs from master's. Keep that shape and add only what #123622 introduces: the `AIRequest` base struct with `query_id` / `initial_query_id` and the `AIChatRequest` rename, `setCommonHeaders` in place of the manual `X-ClickHouse-AI-Function` line, and the query-id arguments to `embedTexts`. The out-param / `SCOPE_EXIT` refactor from master is not brought over. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport #123622 to 26.9: Send the query id with OpenAI AI function requests
Backport #123622 to 26.8: Send the query id with OpenAI AI function requests
OpenAIProvider(used by theopenai,huggingfaceandteiproviders) now sends two headers with every AI function request (aiGenerate,aiClassify,aiExtract,aiTranslate,aiEmbed,aiSimilarity), next to the existingX-ClickHouse-AI-Functionheader:X-ClickHouse-Query-Id: thequery_idof the query that makes the request. On a remote shard of a distributed query it is the shard's own query id; for a background mutation it is the mutation task's id.X-ClickHouse-Initial-Query-Id: theinitial_query_id, the same on all shards of a distributed query. Not sent for a background mutation, which has no initial query.The initial query id lets the endpoint group the requests of one user query. ASCII control characters in both values are replaced with spaces, because query ids from the native and gRPC protocols are not sanitized. The
anthropicprovider does not send these headers.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
AI functions using the
openai,huggingfaceorteiprovider send the query id and the initial query id in theX-ClickHouse-Query-IdandX-ClickHouse-Initial-Query-IdHTTP headers.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123622]
Version info
26.10.1.2391-master(included in26.10and later)26.9.26.22,26.8.35.20