Repository navigation
Conversation
Introduce internal/toolcall as the single model of tool declarations, tool choice, argument repair, native call identity and rendering. translate.ValidateChatRequest now delegates tool_choice validation to toolcall.ParseRequest, which keeps an orphan `auto` degrading to unspecified while a `required` or named choice fails instead of being silently dropped. translate's own tool-argument helpers stay in place until the delivery path switches to the new package in a follow-up change.
Adapters now derive their tool payload from the canonical toolcall profile instead of each package reshaping tools on its own, so declared tools, tool_choice and parallel_tool_calls reach the upstream request body unchanged. Adapters also replay a transient failure in place and report the internal retry count upward, keep the upstream Retry-After hint, and fail a stream that ends without a terminal frame instead of relaying it as success.
Each attempt now carries its kind, state, whether the request reached upstream, and the error code, so a failed round can say where it stopped instead of only that it failed. Aggregation pipelines are compiled together with the classifier so a logical model keeps its own target list and grant scope.
…est terminal accounting Route through one dispatch plan: the account reservation and rotation update together, the provider and region stay inside what the request and API key allow, and a member that cannot enforce the requested tool contract is skipped before any upstream attempt. Cooldowns and stream feedback follow the selected account and concrete model, including native Responses. Tool calls reach the client from the canonical contract. A malformed, truncated, or undeclared call is rejected before a success frame or buffered message is written, and one call identity survives from the upstream event to the final frame. Upstream terminal state and the downstream terminal write are recorded separately, flush failures propagate, and timeouts are attributed to the transport stage that failed. Public HTTP and SSE errors are redacted, native failure frames are sanitized, and the upstream Retry-After passes through CORS. Add a gateway quality model (TTFT, head wait, throughput, TPOT, delivery completeness) plus request statistics for TTFT percentiles, incompletion rate and average throughput. Attempt buffers are bounded and reclaimed, attempt sequence is stable, and entry rejections carry the request ID. Aggregation keeps member order, caps dispatches per requested model across tiers, and keeps previews in sync with configured members. The public model list follows API-key grants and routing, and a canceled stream no longer cools a healthy account.
guyu233
force-pushed
the
pr/runtime-contract
branch
from
December 4, 2026 08:01
b96da6e to
9dae282
Compare
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.
What this adds
The remaining backend contract: one dispatch plan per request, canonical tool delivery, and terminal accounting that cannot report success for a stream that never finished.
Dispatch plan (
internal/accounts,internal/runtime,internal/executor)max_attemptscounts dispatches of the requested logical model, including the first one; aggregate ordering is preserved and entry rejections carry the request id.accountsgainsAttemptKind/RequestState/RequestSent/ErrorCodeandCompilePipelineWithClassifierso every attempt carries its own state through the pipeline.CompilePipelineWithClassifier) and the classifier path keeps its own budget.Tool delivery (
internal/gateway)Terminal accounting (
internal/logs,internal/store,internal/quality,internal/app,internal/control,internal/console,internal/server)Retry-Afteris surfaced.internal/qualitymodel: TTFT, head wait, throughput, TPOT and completeness per attempt;storeadds TTFT percentiles, incomplete rate and average throughput.Why this is one PR
I tried to slice this further and the intermediate states do not compile or do not pass tests, so a green PR is not available below this granularity:
internal/apihas five tests that exercise the whole path end to end (TestRelayOpenAIStreamClassifiesAndSuppressesStructuredError,TestResponsesNonStreamRestoresCustomToolCall,TestAPIKeyAttributionAndFilters,TestOpenAINonStreamContractThroughHandler,TestPinnedMissingAccountFallsBackToPool). Updating them without the implementation leavesgo test ./...red.executorcannot build the new attempt state without theaccountsfields, andgatewaycannot build withoutinternal/qualitybecauseopenai.goderives relay quality.internal/qualityout on its own breaksgateway/openai.gocompilation.So this PR is the smallest backend unit that is green on its own. The two PRs before it are the pieces that can stand alone.
Stack
PR 3 of 3, based on #655 (
pr/provider-tool-profiles) which is based on #654. Merge in order; this branch already contains both. The console PR in this set is independent and can land whenever.Verification
go build ./...go vet ./...go test ./...(whole tree, includinginternal/api)python3 scripts/release-notes.py validateBackend tree matches the branch these PRs came from;
frontendandinternal/webui/staticare untouched here.