feat(chat): route Gemma via LiteLLM, add Qwen 3.6, deadline + fallback#694
Open
feat(chat): route Gemma via LiteLLM, add Qwen 3.6, deadline + fallback#694
Conversation
Regolo's gemma4-31b endpoint hangs upstream — every notebook chat with
the default Gemma model just spun forever because the AI SDK has no
built-in first-token deadline. This change:
- Adds litellmFetchWithThinkingDisabled (sibling to regoloThinkingFetch)
injecting Ollama's `think: false` so LiteLLM-served gemma streams
content instead of burning its entire token budget on `reasoning`.
- Re-routes the user-facing "Gemma 4" model from Regolo → LiteLLM. Old
`gemma-regolo` ID is aliased server-side and migrated client-side
(chatStore v6) to the new `gemma-litellm` ID.
- Adds Qwen 3.6 27B as a selectable model (already in the existing
Regolo reasoning-stream allowlist, so no extra wiring).
- Introduces a 20s first-token deadline + single-step cross-provider
fallback (gemma-litellm ↔ gpt-oss-regolo) in responseStreamingService.
Qwen entries intentionally have no `fallback` field — the
Chinese-only-when-selected firewall (informed-consent boundary,
documented in ModelConfig).
- Fixes pre-existing bug: getModel('litellm', modelId) ignored the
modelId arg and always used LITELLM_DEFAULT_MODEL.
Fallback is silent end-user-side: server emits a `fallback` SSE event,
both runtime adapters log it to the browser console, no UI banner.
Implementation notes:
- streamAndAccumulate / streamAndAccumulateWithReasoning now have a
shared `wrapWithCompatCatch` factory and an `*OrThrow` internal layer
used by streamWithFallback. Existing chat router callers see the same
null-on-failure shape, plus the new deadline + empty-completion
safety nets for free.
- Single shared deadline across initial-probe iterations (was
accidentally giving 40s grace via per-call setTimeout).
- Reasoning streamer split into Phase-1 (race vs deadline until first
text) + Phase-2 (drain without race) — eliminates wasted Promise.race
microtask hops on every reasoning chunk after first content.
- Uses native AbortSignal.any() (Node 20.3+) instead of a hand-rolled
composeAbortSignals helper.
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.
Summary
Regolo's
gemma4-31bendpoint hangs upstream — every notebook chat with the default Gemma model spun forever because the AI SDK has no built-in first-token deadline. This PR fixes the immediate hang, adds resilience for similar future outages, and adds Qwen 3.6 27B as a new selectable model.What changes for users
gemma-regoloselections are migrated togemma-litellmon next page load.REGOLO_REASONING_MODELS).Chinese-only-when-selected firewall
This is the load-bearing constraint of this PR. Qwen entries in
AVAILABLE_MODELSintentionally have NOfallbackfield. The firewall works both directions:Encoded in code, not just docs:
streamWithFallbackearly-returns whenprimary.config?.fallbackis undefined. Reviewers can verify the firewall by readingAVAILABLE_MODELS— Qwen entries omit the field, comment block at `ModelConfig.fallback` explains why.Pre-existing bug fixed
`getModel('litellm', modelId)` ignored the modelId argument and always used `LITELLM_DEFAULT_MODEL`. Latent footgun — masked today because both LiteLLM-mapped IDs (`litellm`, `gemma-litellm`) want the same physical model. Adding any second LiteLLM-served model would have silently routed to the wrong one. One-line fix included.
Implementation highlights
Out of scope (flagged for follow-up)
Test plan
Notes