Repository navigation
Cherry pick #122484 to 26.8: Issue AI function requests concurrently from a server-wide thread pool - #128317
Merged
robot-ch-test-poll merged 33 commits intoOct 30, 2026
Conversation
Requests run on `getAIRequestThreadPool` (a `StaticThreadPool`), configured by `max_ai_request_thread_pool_size`, `max_ai_request_thread_pool_free_size` and `ai_request_thread_pool_queue_size`. `ai_function_max_concurrent_requests` bounds one function call's share. Retries, API-call reservation and token accounting move into `submitAIRequest` / `submitAIEmbeddingRequest`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`AIQuotaTracker::checkQuotas` and `recordApiCall` throw on `KILL QUERY` or `max_execution_time`, so a killed query no longer finishes its current block, and queued requests and retries are not dispatched. Also doc and comment tweaks. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`submitAIRequest` is overloaded for both request types over one `submit` template; `runAttempt` overloads pick `call` or `embed`. `AIEmbeddingResponse` gains an always-zero `output_tokens`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A `/v1/chat/jitter` mock endpoint answers after a random delay, so concurrent responses complete out of order. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`ai_function_max_concurrent_requests` becomes `ai_function_max_concurrent_requests_per_stream`, defaulting to 16. `max_ai_request_thread_pool_size` defaults to 1000. Token-quota tests pin the setting to 1. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Measured against the inference gateway, 8 per stream keeps a typical query within provider rate limits, and 3 retries absorb the remaining 429s. Tests that call unreachable endpoints pin one retry. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Settings history moved into the declarations on master: the new `ai_function_max_concurrent_requests_per_stream` and the `ai_function_max_retries` default change now carry their 26.10 records there. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`ai_function_max_concurrent_requests_per_stream` becomes `..._per_thread`, and the pool settings become `ai_function_max_thread_pool_size`, `ai_function_max_thread_pool_free_size` and `ai_function_thread_pool_queue_size`. Regenerated reference docs for these settings. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
New `ProfileEvents`: `AIAPICallsRetried`, `AIAPICallsFailed` (including errors replaced by a default value) and `AIAPICallsThrottled` (HTTP 429). Server-wide totals and history come from `system.events` and `system.metric_log`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…me limits `ai_function_max_concurrent_requests_per_thread` records 1 -> 8 in 26.10, so `compatibility` below 26.10 keeps the previous serial behavior. Integration tests cover `max_execution_time` with both overflow modes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Conflicts were only in the generated settings route maps and explorers: master's versions plus this branch's `ai_function_*` settings. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Conflicts were only in the generated session settings route map and explorer: master's versions plus `ai_function_max_concurrent_requests_per_thread`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The generated settings route maps and explorers are taken from master as-is: the nightly docs regeneration adds this branch's settings after merge, so they no longer conflict with every regeneration. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ai_function_max_retries` is at most 5 and `ai_function_retry_initial_delay_ms` at most 10000, checked in `makeRequestPolicy`, so the backoff needs no cap. `AIEmbeddingResponse::output_tokens` is `static constexpr`, keeping the struct assignable. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Conflicts with the query id change: the executor path now sets `query_id` and `initial_query_id` and submits `AIChatRequest`; `sanitizeForLog` is `sanitize`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Conflicts were only in the AI function integration tests: the cancellation tests from master run alongside this branch's concurrency tests, pinned to one request per thread. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Brings in `ai_function_allow_sql_named_collections`; merged without conflicts. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A killed or timed-out query no longer waits for other queries' requests queued ahead of its own in the shared AI request pool. Queue admission, waits for results, and the cleanup on error check for cancellation every 100 ms. Requests left in the queue by a cancelled query throw instead of being sent. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A cancelled query does not wait for its AI requests, so they can outlive it. Their memory is tracked under the user trackers in `process_list`, so drain the pool in `~ContextSharedPart`. The retry backoff stops once the query is cancelled, which bounds the drain. Tolerate `NOTHING_TO_KILL` in the cleanup of the cancellation test. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…atic-pool Issue AI function requests concurrently from a server-wide thread pool
Adapt the request executor to 26.8's value-returning `IAIProvider::call`/`embed`, without porting #114905 or its tests. Keep 26.8's generated docs pages and `aiEmbed` row counters; add the settings changes to the `26.8` block of `SettingsChangesHistory`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #122484
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job