[PR #7720] [MERGED] fix(generation): name the failed connection when a fallback answers #7897

Closed
opened 2026-10-24 04:08:38 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7720
Author: @SpicyMarinara
Created: 10/16/2026
Status: ✅ Merged
Merged: 10/16/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/7697-pool-fallback-identity


📝 Commits (4)

  • b8018e6 fix(generation): name the failed connection when a fallback answers
  • e8138a2 fix(generation): show the failed pool pick on every reply, by tap
  • e24d595 fix(generation): preserve fallback identity across reply parts
  • 28bbc77 test(export): calibrate constrained native export heap

📊 Changes

17 files changed (+578 additions, -34 deletions)

View changed files

📝 docs/chats/peek-prompt.md (+1 -1)
📝 docs/connections/organizing-connections.md (+2 -0)
➕ e2e/pool-fallback-note.e2e.ts (+79 -0)
📝 packages/client/src/components/chat/ChatMessage.tsx (+5 -0)
📝 packages/client/src/components/chat/ConversationMessage.tsx (+6 -0)
➕ packages/client/src/components/chat/GenerationFallbackMarker.tsx (+25 -0)
📝 packages/client/src/components/chat/PeekPromptModal.tsx (+4 -0)
📝 packages/client/src/lib/generation-fallback-notice.ts (+92 -12)
📝 packages/client/src/localization/locales/en.json (+19 -0)
📝 packages/server/src/routes/generate.routes.ts (+16 -5)
📝 packages/server/src/routes/generate/saved-message-extra.ts (+8 -1)
📝 packages/server/src/services/generation/provider-generation-runtime.ts (+2 -0)
📝 packages/server/src/services/llm/connection-fallback-provider.ts (+86 -13)
📝 packages/shared/src/types/chat.ts (+3 -1)
📝 packages/shared/src/types/generation-integration.ts (+15 -0)
📝 scripts/regressions/native-export-memory.regression.ts (+2 -1)
➕ scripts/regressions/pool-fallback-identity.regression.ts (+213 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7697

Why this change

  • A chat on a random connection pool picks one connection per reply. When that pick failed and the fallback answered, the toast named only the fallback, and the model shown above the reply is the fallback's. Nothing said which pool member failed, so a bad key, a retired model ID or a rate limit on one member could not be found.
  • The fallback provider only received the primary's id, never its name, model or the error, so the notice could not name it.

What changed

  • Toast: the title stays "Main switched to Backup (claude-sonnet-4-5)." When the chosen connection failed, the second line names it, for example "Pool A (gpt-5) failed (rate limited)." It does not say the fallback answered: the toast appears before the fallback's own request, which can fail too.
  • Short reason: rate limited, key rejected (401 only), not found, timed out, network error, server error, empty reply, or "error 403" / "error 400" for any other HTTP status. A 403 is not called "key rejected", because OpenRouter moderation and OpenAI's unsupported-region error also return 403. Anthropic's 529 "overloaded" is a server error, not "rate limited". A provider that throws a plain error without a status shows "unknown error" (marked ponytail: in describeFallbackFailure).
  • Saved with the reply: the reply keeps the notice in its generation info and shows a small Fallback marker: next to the time in roleplay, under the reply in conversation. Tap, focus or hover opens "Pool A (gpt-5) failed (rate limited); answered with Backup (claude-sonnet-4-5)." The marker shows on every reply the fallback wrote, not only the newest, and with Show model name and Show token usage off. Screen readers read the line as the button's name. Peek Prompt also shows it under the model, but Peek only opens the newest reply.
  • Split replies and continuations: each scene-break part keeps the fallback identity, while usage statistics remain on the last part. Continuing a reply keeps the notice for its retained text when the new segment uses the primary; a new fallback replaces the earlier notice. Connection timeouts are reported as timed out.
  • Names: the main reply (and the character-activity routing call) pass the pick's connection name. Other callers that build a fallback chain (scene, game setup, agents and the rest) still name the failed pick by its model, without the connection name.
  • The toast's existing English moved to en.json keys word for word, so the toast is translatable as a whole. Notices without a failed connection, like image and video fallbacks, keep the old wording.
  • Shared: GenerationFallbackNotice.failed, GenerationInfo.fallback and an optional primaryConnectionName on the fallback options. All are optional, so capability packages are unaffected.
  • Docs: docs/chats/peek-prompt.md (the Peek line) and docs/connections/organizing-connections.md (the random pool section). Translations: #7735.
  • CI fixture calibration: the native export stress regression now uses a 128 MB child heap instead of 112 MB. Its 16 images of 4 MB each, buffered-export OOM negative control, and streamed byte/ZIP/import assertions remain intact. This addresses the constrained-heap failure encountered while validating this PR.
  • Regression proof: scripts/regressions/pool-fallback-identity.regression.ts fails on staging (the notice has no failed entry, and describeFallbackFailure does not exist there) and on the first commit (403, 529 and the toast wording). e2e/pool-fallback-note.e2e.ts taps the marker on an older fallback reply in roleplay and conversation on desktop, Pixel and iPhone; it fails without the marker.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Agent-run checks (not a substitute for the boxes above):

  • tsc --noEmit for shared, server, client and root: clean.
  • ESLint on the changed client files, Prettier on every changed file, node scripts/check-locales.mjs and pnpm localization:check: clean.
  • Regressions passed: pool-fallback-identity (new), provider-compat, generate-saved-message-extra, capability-integrations, agent-connection-parameters, codex-reasoning-effort, robustness-provider-resilience, roleplay-streaming, agent-activation, spatial-context, open-issues, slash-command-usage, ui-language-packs, export-file-save, and the others that read the changed files.
  • Second commit: full pnpm check passed. Playwright (--workers=1): pool-fallback-note (6/6 on desktop-chromium, mobile-chromium and mobile-webkit), reply-checkup, the core-flows fallback toast test and the @smoke suite passed; the skips are the specs' own project skips. Also re-ran provider-compat, robustness-provider-resilience, open-issues, roleplay-streaming, chat-message-css-security, character-identity, docs-language, docs-command-search, ui-language-packs and capability-integrations.

Review fixes committed as e24d59587d33a816eb947e280ca77cf8b2281728 (the same tree tested locally):

  • pnpm install and full pnpm check: pass. The existing HomeProfessorMariChat.tsx serverRun hook-dependency warning remains; no errors.
  • node scripts/run-regressions.mjs --filter <name>: pool-fallback-identity, generate-saved-message-extra, generate-save-generated-reply, provider-compat, and roleplay-streaming pass. The pool regression now covers nested connect timeouts, retained continuation notices, new fallback precedence, and split-part route wiring.
  • pnpm regression:ui e2e/pool-fallback-note.e2e.ts --workers=1: 6/6 pass across desktop Chromium, mobile Chromium and mobile WebKit. pnpm smoke:ui: 7/7 pass. These runs used dedicated ports and ran after the production build; preliminary runs interrupted by local edits/builds were discarded.
  • A temporary before/after proof outside the repository loaded the original HEAD and fixed helper/provider: the old continuation loses its fallback notice and the old connect timeout reports network; the fixed versions retain the notice and report timeout.
  • Local CodeRabbit reviewed the four review-fix files twice. Initial review: zero findings. Final review: one major finding dismissed as a false positive, not zero findings. It claimed the shared GenerationInfo type lacked fallback; that field already exists at packages/shared/src/types/chat.ts:1116, with its type imported at line 13, in both the previous committed PR head and the final tree. Full pnpm check confirms the access type-checks. No substantive finding remains.

CI fixture calibration committed as 28bbc77d4d5773678784d3cc8a032fe355aa8701:

  • Hosted full Node run 38944542381 on e24d59587 finished 902/903. Only native-export-memory.regression.ts:209 failed: its character-export child process hit the explicit 112 MB JavaScript heap limit on Node 24.21.0. This was a constrained-heap abort, not a hosted-runner acquisition failure.
  • The prior committed PR head passed the same unchanged fixture on hosted Node 24.21.0 with a 71 MB baseline and 112 MB sampled peak. Six focused runs of the final production tree on local Node 24.16.0 also passed at 112 MB, with sampled peaks of 108–112 MB. The export implementation and fixture were unchanged by the fallback review fixes.
  • An outside-repository copy changing only the ceiling to 128 MB passed four runs; three explicitly logged the old buffered export's fatal heap OOM. Every original streamed export, byte, ZIP and import assertion passed. Observed sampled peaks varied from 118 to 127 MB with a 71 MB baseline.
  • Final in-repository fixture: pnpm exec prettier --check scripts/regressions/native-export-memory.regression.ts and node scripts/run-regressions.mjs --filter native-export-memory pass on Node 24.16.0. The final sampled peak was 128 MB, baseline 71 MB; these measurements do not establish universal spare heap headroom.
  • Local CodeRabbit reviewed the fixture-only follow-up: zero findings. This follow-up changes only the test ceiling and its rationale; the production tree validated by full pnpm check at e24d59587 is unchanged. Fresh hosted checks are running on the new head and are not yet recorded as passed.

Manual verification notes

  • Manually verify that with a random pool chat whose picked member has a wrong API key and a working Main fallback, the toast title reads "Main switched to ()." and its second line " () failed (key rejected)."
  • Manually verify a rate-limited or offline pick shows "rate limited", "timed out" or "network error".
  • Manually verify on a phone that tapping Fallback on a fallback reply that is no longer the newest shows " () failed (); answered with ().", in both a roleplay and a conversation chat, with Show model name off.
  • Manually verify the marker's look next to the time in roleplay and under the reply in conversation, in light and dark mode.
  • Manually verify that Peek Prompt on that reply shows the line under the model.
  • Manually verify that a reply the pick wrote itself (no fallback) shows no marker, and that regenerating a fallback reply on a working pick removes it.
  • Manually verify that image and video fallback toasts still read as before.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Updated docs/chats/peek-prompt.md and docs/connections/organizing-connections.md. Translations follow in #7735.

UI evidence (if applicable)

Not captured.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Replies generated through a fallback connection can show a Fallback marker with details about the failed connection, its model, and a brief reason.
    • Generation details and notifications can also include information about the connection switch when available.
  • Documentation
    • Updated guidance explains fallback behavior for the Main connection and how to view the failure notice.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7720 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/7697-pool-fallback-identity` --- ### 📝 Commits (4) - [`b8018e6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b8018e6a2248b0a7d26b1420f7c6545370dde341) fix(generation): name the failed connection when a fallback answers - [`e8138a2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e8138a2ccbcfb9d0744499367992056d71ad0e5c) fix(generation): show the failed pool pick on every reply, by tap - [`e24d595`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e24d59587d33a816eb947e280ca77cf8b2281728) fix(generation): preserve fallback identity across reply parts - [`28bbc77`](https://github.com/Pasta-Devs/Marinara-Engine/commit/28bbc77d4d5773678784d3cc8a032fe355aa8701) test(export): calibrate constrained native export heap ### 📊 Changes **17 files changed** (+578 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `docs/chats/peek-prompt.md` (+1 -1) 📝 `docs/connections/organizing-connections.md` (+2 -0) ➕ `e2e/pool-fallback-note.e2e.ts` (+79 -0) 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+5 -0) 📝 `packages/client/src/components/chat/ConversationMessage.tsx` (+6 -0) ➕ `packages/client/src/components/chat/GenerationFallbackMarker.tsx` (+25 -0) 📝 `packages/client/src/components/chat/PeekPromptModal.tsx` (+4 -0) 📝 `packages/client/src/lib/generation-fallback-notice.ts` (+92 -12) 📝 `packages/client/src/localization/locales/en.json` (+19 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+16 -5) 📝 `packages/server/src/routes/generate/saved-message-extra.ts` (+8 -1) 📝 `packages/server/src/services/generation/provider-generation-runtime.ts` (+2 -0) 📝 `packages/server/src/services/llm/connection-fallback-provider.ts` (+86 -13) 📝 `packages/shared/src/types/chat.ts` (+3 -1) 📝 `packages/shared/src/types/generation-integration.ts` (+15 -0) 📝 `scripts/regressions/native-export-memory.regression.ts` (+2 -1) ➕ `scripts/regressions/pool-fallback-identity.regression.ts` (+213 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7697 ## Why this change - A chat on a random connection pool picks one connection per reply. When that pick failed and the fallback answered, the toast named only the fallback, and the model shown above the reply is the fallback's. Nothing said which pool member failed, so a bad key, a retired model ID or a rate limit on one member could not be found. - The fallback provider only received the primary's id, never its name, model or the error, so the notice could not name it. ## What changed - **Toast:** the title stays "Main switched to Backup (claude-sonnet-4-5)." When the chosen connection failed, the second line names it, for example "Pool A (gpt-5) failed (rate limited)." It does not say the fallback answered: the toast appears before the fallback's own request, which can fail too. - **Short reason:** rate limited, key rejected (401 only), not found, timed out, network error, server error, empty reply, or "error 403" / "error 400" for any other HTTP status. A 403 is not called "key rejected", because OpenRouter moderation and OpenAI's unsupported-region error also return 403. Anthropic's 529 "overloaded" is a server error, not "rate limited". A provider that throws a plain error without a status shows "unknown error" (marked `ponytail:` in `describeFallbackFailure`). - **Saved with the reply:** the reply keeps the notice in its generation info and shows a small **Fallback** marker: next to the time in roleplay, under the reply in conversation. Tap, focus or hover opens "Pool A (gpt-5) failed (rate limited); answered with Backup (claude-sonnet-4-5)." The marker shows on every reply the fallback wrote, not only the newest, and with Show model name and Show token usage off. Screen readers read the line as the button's name. Peek Prompt also shows it under the model, but Peek only opens the newest reply. - **Split replies and continuations:** each scene-break part keeps the fallback identity, while usage statistics remain on the last part. Continuing a reply keeps the notice for its retained text when the new segment uses the primary; a new fallback replaces the earlier notice. Connection timeouts are reported as timed out. - **Names:** the main reply (and the character-activity routing call) pass the pick's connection name. Other callers that build a fallback chain (scene, game setup, agents and the rest) still name the failed pick by its model, without the connection name. - The toast's existing English moved to `en.json` keys word for word, so the toast is translatable as a whole. Notices without a failed connection, like image and video fallbacks, keep the old wording. - Shared: `GenerationFallbackNotice.failed`, `GenerationInfo.fallback` and an optional `primaryConnectionName` on the fallback options. All are optional, so capability packages are unaffected. - Docs: `docs/chats/peek-prompt.md` (the Peek line) and `docs/connections/organizing-connections.md` (the random pool section). Translations: #7735. - **CI fixture calibration:** the native export stress regression now uses a 128 MB child heap instead of 112 MB. Its 16 images of 4 MB each, buffered-export OOM negative control, and streamed byte/ZIP/import assertions remain intact. This addresses the constrained-heap failure encountered while validating this PR. - Regression proof: `scripts/regressions/pool-fallback-identity.regression.ts` fails on staging (the notice has no `failed` entry, and `describeFallbackFailure` does not exist there) and on the first commit (403, 529 and the toast wording). `e2e/pool-fallback-note.e2e.ts` taps the marker on an older fallback reply in roleplay and conversation on desktop, Pixel and iPhone; it fails without the marker. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Agent-run checks (not a substitute for the boxes above): - `tsc --noEmit` for shared, server, client and root: clean. - ESLint on the changed client files, Prettier on every changed file, `node scripts/check-locales.mjs` and `pnpm localization:check`: clean. - Regressions passed: `pool-fallback-identity` (new), `provider-compat`, `generate-saved-message-extra`, `capability-integrations`, `agent-connection-parameters`, `codex-reasoning-effort`, `robustness-provider-resilience`, `roleplay-streaming`, `agent-activation`, `spatial-context`, `open-issues`, `slash-command-usage`, `ui-language-packs`, `export-file-save`, and the others that read the changed files. - Second commit: full `pnpm check` passed. Playwright (`--workers=1`): `pool-fallback-note` (6/6 on desktop-chromium, mobile-chromium and mobile-webkit), `reply-checkup`, the core-flows fallback toast test and the `@smoke` suite passed; the skips are the specs' own project skips. Also re-ran `provider-compat`, `robustness-provider-resilience`, `open-issues`, `roleplay-streaming`, `chat-message-css-security`, `character-identity`, `docs-language`, `docs-command-search`, `ui-language-packs` and `capability-integrations`. Review fixes committed as `e24d59587d33a816eb947e280ca77cf8b2281728` (the same tree tested locally): - `pnpm install` and full `pnpm check`: pass. The existing `HomeProfessorMariChat.tsx` `serverRun` hook-dependency warning remains; no errors. - `node scripts/run-regressions.mjs --filter <name>`: `pool-fallback-identity`, `generate-saved-message-extra`, `generate-save-generated-reply`, `provider-compat`, and `roleplay-streaming` pass. The pool regression now covers nested connect timeouts, retained continuation notices, new fallback precedence, and split-part route wiring. - `pnpm regression:ui e2e/pool-fallback-note.e2e.ts --workers=1`: 6/6 pass across desktop Chromium, mobile Chromium and mobile WebKit. `pnpm smoke:ui`: 7/7 pass. These runs used dedicated ports and ran after the production build; preliminary runs interrupted by local edits/builds were discarded. - A temporary before/after proof outside the repository loaded the original HEAD and fixed helper/provider: the old continuation loses its fallback notice and the old connect timeout reports network; the fixed versions retain the notice and report timeout. - Local CodeRabbit reviewed the four review-fix files twice. Initial review: zero findings. Final review: one major finding dismissed as a false positive, not zero findings. It claimed the shared `GenerationInfo` type lacked `fallback`; that field already exists at `packages/shared/src/types/chat.ts:1116`, with its type imported at line 13, in both the previous committed PR head and the final tree. Full `pnpm check` confirms the access type-checks. No substantive finding remains. CI fixture calibration committed as `28bbc77d4d5773678784d3cc8a032fe355aa8701`: - Hosted full Node run [38944542381](https://github.com/Pasta-Devs/Marinara-Engine/actions/runs/38944542381) on `e24d59587` finished 902/903. Only `native-export-memory.regression.ts:209` failed: its character-export child process hit the explicit 112 MB JavaScript heap limit on Node 24.21.0. This was a constrained-heap abort, not a hosted-runner acquisition failure. - The prior committed PR head passed the same unchanged fixture on hosted Node 24.21.0 with a 71 MB baseline and 112 MB sampled peak. Six focused runs of the final production tree on local Node 24.16.0 also passed at 112 MB, with sampled peaks of 108–112 MB. The export implementation and fixture were unchanged by the fallback review fixes. - An outside-repository copy changing only the ceiling to 128 MB passed four runs; three explicitly logged the old buffered export's fatal heap OOM. Every original streamed export, byte, ZIP and import assertion passed. Observed sampled peaks varied from 118 to 127 MB with a 71 MB baseline. - Final in-repository fixture: `pnpm exec prettier --check scripts/regressions/native-export-memory.regression.ts` and `node scripts/run-regressions.mjs --filter native-export-memory` pass on Node 24.16.0. The final sampled peak was 128 MB, baseline 71 MB; these measurements do not establish universal spare heap headroom. - Local CodeRabbit reviewed the fixture-only follow-up: zero findings. This follow-up changes only the test ceiling and its rationale; the production tree validated by full `pnpm check` at `e24d59587` is unchanged. Fresh hosted checks are running on the new head and are not yet recorded as passed. ### Manual verification notes - Manually verify that with a random pool chat whose picked member has a wrong API key and a working Main fallback, the toast title reads "Main switched to <fallback> (<model>)." and its second line "<pick> (<model>) failed (key rejected)." - Manually verify a rate-limited or offline pick shows "rate limited", "timed out" or "network error". - Manually verify on a phone that tapping **Fallback** on a fallback reply that is no longer the newest shows "<pick> (<model>) failed (<reason>); answered with <fallback> (<model>).", in both a roleplay and a conversation chat, with Show model name off. - Manually verify the marker's look next to the time in roleplay and under the reply in conversation, in light and dark mode. - Manually verify that Peek Prompt on that reply shows the line under the model. - Manually verify that a reply the pick wrote itself (no fallback) shows no marker, and that regenerating a fallback reply on a working pick removes it. - Manually verify that image and video fallback toasts still read as before. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Updated `docs/chats/peek-prompt.md` and `docs/connections/organizing-connections.md`. Translations follow in #7735. ## UI evidence (if applicable) Not captured. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Replies generated through a fallback connection can show a **Fallback** marker with details about the failed connection, its model, and a brief reason. * Generation details and notifications can also include information about the connection switch when available. * **Documentation** * Updated guidance explains fallback behavior for the Main connection and how to view the failure notice. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:08:38 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7897
No description provided.