Repository navigation
feat: Workers AI reasoning control and pinned-model integrity (#135, #133, #128) - #139
Merged
Merged
Conversation
…133, #128) First slice of #136. - Map reasoning.effort per Workers AI model from each model's Cloudflare docs page (reasoning_effort, or chat_template_kwargs for Nemotron); never forward undocumented values or aliases that mean max. - Report what was sent in LLMResponse.reasoningEffort; reasoning.strict rejects inexact levels before the call; expose the mapping as ModelCapabilities.reasoningEffort in the catalog and provider. - Add TokenUsage.reasoningTokens and LLMResponse.lengthCause. - Add LLMRequest.allowFallback: false, which stops all failover including built-in fallback, and throws NoRouteError for an unservable pin. - Mark substitutions with LLMResponse.fallback / StreamCompletion.fallback, including skipped providers; add StreamCompletion.provider and model. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- reasoning.strict: new ReasoningEffortUnsupportedError (extends InvalidRequestError) never triggers fallback, and strict requests with an effort never fail over to a provider other than Cloudflare, including via the default any-error rule or a rule's fallbackProvider. - allowFallback: false with a skipped pinned provider throws NoRouteError naming the skip; ALL_PROVIDERS_FAILED messages list skipped providers. - Response cache: validate fallback, reasoningEffort and lengthCause on cached envelopes; document that hits replay the stored fallback report. - lengthCauseFor: handle think tags anywhere, template-opened think blocks (closing tag only) and untagged output from thinking models (QwQ, R1-Distill). - fallback.requestedModel is captured at plan time. - Nemotron medium/high are no longer reported as 'default'; they send nothing and report applied: null. - Docs: strict semantics, GLM-5.3 aliases, stream completion fields. - Tests for each, and a deterministic Math.random in a flaky stream test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- reasoning.strict with an effort is served only by Cloudflare, first hop included. A pin on another provider, or no Cloudflare provider, throws ReasoningEffortUnsupportedError before any call; an unpinned strict request goes to Cloudflare even when another provider is preferred. - onRequestError.willRetry is false when a strict chain has no next hop. - lengthCauseFor only reads think structure at the start of the message, so answer text that mentions <think> is no longer called reasoning. - Nemotron medium/high send normal reasoning (enable_thinking: true) explicitly, per the model page's three documented modes; inexact. - The factory no longer caches envelopes its read path would reject. - No-route message says "First planned provider" when nothing was pinned. - Tests: non-Cloudflare pin, no Cloudflare provider, preferred provider, tool loop, isolated fallback guard, willRetry, cache write guard. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A strict request pinned to a model no configured Cloudflare provider can serve (unconfigured provider, unknown model, images the pin can't take) throws ReasoningEffortUnsupportedError instead of being served by a default Cloudflare model. - lengthCauseFor applies the template-opened rule only to thinking models and only when the message doesn't start with <think>, so answers ending in a literal </think> and reasoning that quotes <think> classify right. - A skipped response-cache write logs a warning and emits an onCache bypass event. - Docs: the error now also covers strict routing failures; getRoutingInfo and allowFallback paragraphs note it; unpinned strict uses the default Workers AI model, so pin a model with strict. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- README: with allowFallback: false, a pin no configured provider can serve throws NoRouteError (that check runs first); only a pin on another configured provider throws ReasoningEffortUnsupportedError. Same note on getRoutingInfo. - Tests: that precedence, and willRetry: false on the stream path for a strict request with no next hop. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
stackbilt-admin
added a commit
that referenced
this pull request
Nov 6, 2026
Workers AI reasoning control and pinned-model integrity (#139). Bumps package.json, package-lock.json and src/version.ts to 1.24.0, dates the CHANGELOG section, and refreshes the issue-sweep checkpoint. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 6, 2026
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.
First slice of #136. Closes #135, closes #133, closes #128. Additive, so it targets a minor release (1.24.0).
Reasoning control on Workers AI (#135, #136 need 1)
Each Workers AI reasoning model documents its own
reasoning_effortlevels, and some document aliases that turn a "lower" value into the model's maximum (GLM-5.3 Flash mapsnoneandmediumtomax). Soreasoning.effortis mapped per model, from each model's Cloudflare docs page (checked 2026-11-06, cited insrc/providers/cloudflare-reasoning.ts):chat_template_kwargs)Models whose pages document no control get nothing sent.
What callers get:
LLMResponse.reasoningEffortreports{ requested, applied, exact }.reasoning.strict: truethrowsInvalidRequestErrorbefore the call when the level can't be sent exactly.ModelCapabilities.reasoningEffort({ exact, source, verifiedAt }) appears in the catalog and in the provider capabilities. Both read the same table.TokenUsage.reasoningTokens, from Workers AIcompletion_tokens_details/output_tokens_details.LLMResponse.lengthCause('reasoning' | 'answer') whenfinishReasonis'length'. It is set by the Cloudflare provider and by the factory for every provider, and an unclosed<think>block counts as reasoning.Evidence gap: for gpt-oss, the field name comes from Cloudflare's
workers-ai-provider3.1.12 (PR cloudflare/ai#504), which forwards top-levelreasoning_effortfor chat input. The gpt-oss model page lists the levels but not the chat request field. None of this was tested against live Workers AI.Pinned-model integrity (#128, #133)
fallbackRules: []was never a full opt-out. Server errors, network errors, timeouts and schema drift fall back after rules are evaluated. A test now shows this.LLMRequest.allowFallback: falselimits the plan to the first provider (the pinned model's provider) and rethrows its error, overriding both rules and built-in fallback. It throwsNoRouteErrorif no configured provider can serve the pin. This coversgenerateResponse, the tool loop,generateManagedResponseStreamandgetRoutingInfo.allowFallbackis part of the semantic request, so the response cache already keys on it.LLMResponse.fallback/StreamCompletion.fallbackcarry{ requestedProvider, requestedModel, failedAttempts }. A planned provider that was skipped (quota-exhausted, circuit-open, ledger-limited, or unable to stream) counts as a failed attempt.normalizeLLMResponse()copies the attempts intorouting.fallbackChain.StreamCompletion.provider/modelreport what served the stream.onRequestError.willRetryis false whenallowFallbackis false.Behavior change
Requests that already set
reasoning.effortand are served by a mapped Workers AI model now actually send it; until now it was silently dropped. Output length, latency and cost can change. This is noted in the CHANGELOG.Not in this PR
allowFallbackisn't carried by the canonical request API.src/providers/cloudflare.ts, so expect small conflicts.Validation (Windows, Node 24)
npm test: 813 passed across 31 files, including 24 new insrc/__tests__/pin-and-reasoning.test.ts.npm run typecheckandnpm run test:worker-import: passed.🤖 Generated with Claude Code