[PR #7837] [MERGED] fix(release): wait for connections before the new-chat gate; no 404 for owners without an avatar #7959

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

📋 Pull Request Information

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

Base: staging ← Head: fix/ready-client-minor-fixes


📝 Commits (5)

  • 29d1605 fix(release): wait for the connection list before Home opens the connection gate
  • 2cf27e8 fix(release): answer null, not 404, for an owner without an avatar
  • 90b6bef Merge staging into client release fixes, retain Tripo test removal
  • 76bb909 fix(chat): keep new-chat launch guarded until creation completes
  • 74023dd fix(chat): await current connections before starting a chat

📊 Changes

9 files changed (+316 additions, -55 deletions)

View changed files

📝 e2e/avatar-generation.e2e.ts (+2 -2)
📝 e2e/avatar-setup.e2e.ts (+18 -1)
➕ e2e/home-new-chat-connections-loading.e2e.ts (+212 -0)
📝 packages/client/src/hooks/use-avatar-models.ts (+4 -2)
📝 packages/client/src/hooks/use-connections.ts (+12 -9)
📝 packages/client/src/hooks/use-start-new-chat-mode.ts (+47 -32)
📝 packages/server/src/routes/avatar-models.routes.ts (+5 -3)
📝 packages/shared/src/types/avatars.ts (+2 -1)
📝 scripts/regressions/avatar-models.regression.ts (+14 -5)

📄 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

No issue exists for either problem. Both were found during the release-readiness pass before the next release. An issue should be opened if one is wanted for tracking.

Why this change

  • New-chat gate race (also in v2.5.0). On a slow host (Termux, the APK, phones), tapping Conversation, Roleplay or Game on Home before the connection list has loaded opens the "Set Up Roleplay / Choose a connection" gate even though a connection exists. The hook read the list straight from the cache and could not tell "still loading" from "no connections". This was reproduced twice in a row in production at 390px.
  • Avatar 404 console noise (new in this release). GET /api/avatar-models/:ownerType/:ownerId answered 404 for a character or persona with no avatar yet. The browser logged Failed to load resource: 404 every time such an owner was picked on the 2D or 3D Avatars setup page, which looks like an error to anyone reading the console or a support log.

What changed

  • use-start-new-chat-mode.ts: before deciding between the gate and the setup wizard, the hook now waits for the connection list with queryClient.fetchQuery(connectionListQuery). Taps while the list loads or the new chat saves are ignored, so a second tap cannot make a second chat. A finally releases the guard after either a successful launch, an empty-list gate or a failed request. A list that fails to load still counts as no connections, as before, so the gate keeps working when there really are none.
  • use-connections.ts: the list query's options (key, fetcher, 10 s deadline, retry rule) moved into an exported connectionListQuery so useConnections and the hook share them. useConnections behaves the same. This file was not in the lane's expected list; sharing the options here is the way to reuse the same key and fetcher.
  • avatar-models.routes.ts: GET answers JSON null (200) for an existing owner without an avatar and keeps 404 for an owner that does not exist. The route doc comment, the avatarModelPath doc in packages/shared/src/types/avatars.ts, and the fetchAvatarModel / useAvatarModel docs are updated. fetchAvatarModel still maps 404 to null, so a deleted owner still reads as "no avatar". AvatarStage.tsx and AvatarAgentSetup.tsx needed no change because both already go through fetchAvatarModel / useAvatarModel and treat null as "none". Marinara-Agents does not call this route.
  • New e2e e2e/home-new-chat-connections-loading.e2e.ts: it holds GET /api/connections until after the tap and also holds the first POST /api/chats after the list loads. Further taps during both waits must send no duplicate save. It then checks that the New Roleplay wizard opens, that no gate appears and that exactly one chat is made. The negative control holds an empty list and checks that the gate opens with "No connections found" and no chat is made.
  • Tests that are outdated because this PR changes the answer on purpose:
    • scripts/regressions/avatar-models.regression.ts and e2e/avatar-setup.e2e.ts expected 404 for "nothing saved yet". They now expect 200 with a null body. The regression also checks the JSON content type and adds 404 checks for a missing character and persona. The 404 check after the character is deleted in avatar-setup.e2e.ts stays.
    • e2e/avatar-generation.e2e.ts reads a null body safely while it polls.
    • e2e/avatar-setup.e2e.ts now also fails if the 2D or 3D setup page logs a failed avatar request.

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

Earlier whole-PR validation at 76bb909d4e1503a213f21667d10076ad9c44f9b5 (macOS arm64, Node 24.16.0, pnpm 10.34.5, isolated worktree and disposable data):

  • pnpm install --frozen-lockfile --prefer-offline --store-dir <existing shared store>: exit 0; no lockfile change.
  • pnpm check: exit 0, including localization, formatting, lint/type checks and production build. One pre-existing HomeProfessorMariChat.tsx:380 hook-dependency warning remains.
  • node scripts/run-regressions.mjs --filter scripts/regressions/avatar-models.regression.ts: 1/1 passed. avatar-contract.regression.ts and frozen-server-client-timeouts.regression.ts were run through the same runner separately: 1/1 passed each.
  • pnpm exec playwright test e2e/home-new-chat-connections-loading.e2e.ts e2e/avatar-setup.e2e.ts --grep 'new roleplay|2D Avatars shows|3D Avatars links' --project=desktop-chromium --project=mobile-chromium --project=mobile-webkit --workers=1: 12/12 passed. This covers the held-list and held-save positive case, empty-list negative case, and 2D/3D setup without failed avatar requests in all three browser projects.
  • pnpm exec playwright test --grep '@smoke|Cancel stops the picture being made|3D Avatars points to VRoid Studio|A model made earlier with Tripo|Connections no longer offers Tripo' --project=desktop-chromium --workers=1: 11/11 passed, including all seven desktop smoke cases, null-safe avatar-generation polling and the three replacement Tripo-removal cases.
  • Browser runs used private client ports 5188/5189 and API ports 7981/7982. These are browser emulation results; no native Android/APK/Termux device run is claimed.
  • coderabbit review --committed --base origin/staging: the initial substantive review found one valid issue: the guard ended before the first chat save. The held-save negative control reproduced a second POST on 90b6bef4a; the guard now spans the full launch. The substantive post-fix review completed across all nine changed files with one minor suggestion, which was dismissed as an intentional non-regression: staging already converted missing query data through (connections ?? []) and opened the connection gate, while this PR preserves that fallback with .catch(() => []). Letting the fetch rejection propagate would instead reach HomeNewChatLauncher's catch, which assumes the create mutation already showed a toast and otherwise swallows the error. Redesigning connection-error UX is outside this PR. No additional code change was made for that suggestion.

Final-head stale-cache follow-up at 74023dde9efd8523d74af53d3eef9b8c65f92abf (same macOS arm64 environment, isolated worktree/disposable data):

  • The hosted review at 76bb909d4 found one valid stale-cache issue: ensureQueryData immediately returned cached rows while the mounted connection observer was refetching. The hook now uses fetchQuery(connectionListQuery), which waits for stale data to refresh and joins the observer's pending request. The existing error fallback and full-launch duplicate guard are unchanged.
  • The actual installed TanStack Query 5.103.0 runtime was checked using the actual production connectionListQuery options (five-minute stale time), in both directions: cached empty to configured, and cached configured to empty. The old call returned cached rows immediately; the new call waited for the single held request.
  • Both new browser negative controls failed against unchanged 76bb909d4: stale empty data opened the wrong connection gate, and stale configured data sent a premature chat save. Both pass with the final fix. The existing two Home launch assertions were retained; the two new cases also check that repeated taps do not make duplicate saves and that no second connection request is made.
  • pnpm check: exit 0, including localization, formatting, lint/types and the production build; the same pre-existing hook-dependency warning remains.
  • pnpm exec playwright test -c playwright.config.ts e2e/home-new-chat-connections-loading.e2e.ts --project=desktop-chromium --project=mobile-chromium --project=mobile-webkit --workers=1 (run serially as desktop and mobile groups on private ports): 12/12 passed.
  • pnpm smoke:ui: 7/7 passed. pnpm smoke:production: 3/3 passed across desktop Chromium, mobile Chromium and mobile WebKit.
  • The preceding full hosted review at 76bb909d4 was audited, including its entire body and inline comments: one actionable finding was accepted and fixed; no outside-diff or nitpick items were present. The earlier local fallback suggestion remains the documented dismissal above. Final-head local incremental review, substantive hosted follow-up and required GitHub checks are separate merge gates; pending/rate-limited statuses are not reported as passed.

Earlier negative controls: the avatar-models regression failed against staging with actual: 404, expected: 200; the held-list home case failed against the staging hook in desktop and mobile Chromium because the connection gate opened; and the 3D setup case failed against staging with three avatar 404 console errors. Each passed with this PR.

Conflict resolution: merged staging c248baa9e into this PR and kept staging's deletion of the obsolete e2e/avatar-vrm-generation.e2e.ts Tripo-maker test. Its only PR change was a missing-avatar assertion inside a removed paid-generation flow, so it has no corresponding assertion to move to the replacement spec. The active missing-avatar contract remains covered by avatar-models.regression.ts and avatar-setup.e2e.ts; the replacement avatar-vrm-tripo-removed.e2e.ts also passed above. No production behavior was added during the merge.

Manual verification notes

  • Manually verify on a phone, the APK or Termux, right after opening the app, that tapping Roleplay on Home opens the New Roleplay wizard rather than "Set Up Roleplay / Choose a connection". Then check that a quick second tap does not leave an extra empty chat in the sidebar.
  • Manually verify that with no connections at all, Home's Conversation, Roleplay and Game buttons still open the gate with "No connections found".
  • Manually verify that the omnibar's "New conversation/roleplay/game" commands still start a chat.
  • Manually verify in the browser console that picking a character or persona with no avatar on the 2D Avatars and 3D Avatars setup pages logs no 404, and that importing or saving an avatar for that owner still works.

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)

No user-facing docs or UI copy change.

UI evidence (if applicable)

Behaviour only, no visual change. Before this change, tapping Roleplay while the connection list was still loading opened the "Set Up Roleplay" gate showing "No connections found", even though a connection existed. After it, the New Roleplay setup wizard opens.

Summary by CodeRabbit

  • Bug Fixes
    • Avatar setup now handles owners with no saved avatar without displaying an error. Requests for unknown owners still return an error.
    • Starting a roleplay while connections are loading now waits for the connection list before choosing the next step.
    • Repeated taps during connection checks or chat creation no longer create duplicate chats. When no connections are available, the connection setup gate is shown.

🔄 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/7837 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/ready-client-minor-fixes` --- ### 📝 Commits (5) - [`29d1605`](https://github.com/Pasta-Devs/Marinara-Engine/commit/29d1605d55be09d3d03f4c7caeb80499cd2f60b9) fix(release): wait for the connection list before Home opens the connection gate - [`2cf27e8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2cf27e815899f5a088a18f33e9c744f7504e8245) fix(release): answer null, not 404, for an owner without an avatar - [`90b6bef`](https://github.com/Pasta-Devs/Marinara-Engine/commit/90b6bef4ac7d52de2a37e214b8968a90cd9e501d) Merge staging into client release fixes, retain Tripo test removal - [`76bb909`](https://github.com/Pasta-Devs/Marinara-Engine/commit/76bb909d4e1503a213f21667d10076ad9c44f9b5) fix(chat): keep new-chat launch guarded until creation completes - [`74023dd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/74023dde9efd8523d74af53d3eef9b8c65f92abf) fix(chat): await current connections before starting a chat ### 📊 Changes **9 files changed** (+316 additions, -55 deletions) <details> <summary>View changed files</summary> 📝 `e2e/avatar-generation.e2e.ts` (+2 -2) 📝 `e2e/avatar-setup.e2e.ts` (+18 -1) ➕ `e2e/home-new-chat-connections-loading.e2e.ts` (+212 -0) 📝 `packages/client/src/hooks/use-avatar-models.ts` (+4 -2) 📝 `packages/client/src/hooks/use-connections.ts` (+12 -9) 📝 `packages/client/src/hooks/use-start-new-chat-mode.ts` (+47 -32) 📝 `packages/server/src/routes/avatar-models.routes.ts` (+5 -3) 📝 `packages/shared/src/types/avatars.ts` (+2 -1) 📝 `scripts/regressions/avatar-models.regression.ts` (+14 -5) </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 No issue exists for either problem. Both were found during the release-readiness pass before the next release. An issue should be opened if one is wanted for tracking. ## Why this change - **New-chat gate race (also in v2.5.0).** On a slow host (Termux, the APK, phones), tapping Conversation, Roleplay or Game on Home before the connection list has loaded opens the "Set Up Roleplay / Choose a connection" gate even though a connection exists. The hook read the list straight from the cache and could not tell "still loading" from "no connections". This was reproduced twice in a row in production at 390px. - **Avatar 404 console noise (new in this release).** `GET /api/avatar-models/:ownerType/:ownerId` answered 404 for a character or persona with no avatar yet. The browser logged `Failed to load resource: 404` every time such an owner was picked on the 2D or 3D Avatars setup page, which looks like an error to anyone reading the console or a support log. ## What changed - `use-start-new-chat-mode.ts`: before deciding between the gate and the setup wizard, the hook now waits for the connection list with `queryClient.fetchQuery(connectionListQuery)`. Taps while the list loads or the new chat saves are ignored, so a second tap cannot make a second chat. A `finally` releases the guard after either a successful launch, an empty-list gate or a failed request. A list that fails to load still counts as no connections, as before, so the gate keeps working when there really are none. - `use-connections.ts`: the list query's options (key, fetcher, 10 s deadline, retry rule) moved into an exported `connectionListQuery` so `useConnections` and the hook share them. `useConnections` behaves the same. This file was not in the lane's expected list; sharing the options here is the way to reuse the same key and fetcher. - `avatar-models.routes.ts`: GET answers JSON `null` (200) for an existing owner without an avatar and keeps 404 for an owner that does not exist. The route doc comment, the `avatarModelPath` doc in `packages/shared/src/types/avatars.ts`, and the `fetchAvatarModel` / `useAvatarModel` docs are updated. `fetchAvatarModel` still maps 404 to `null`, so a deleted owner still reads as "no avatar". `AvatarStage.tsx` and `AvatarAgentSetup.tsx` needed no change because both already go through `fetchAvatarModel` / `useAvatarModel` and treat `null` as "none". Marinara-Agents does not call this route. - New e2e `e2e/home-new-chat-connections-loading.e2e.ts`: it holds `GET /api/connections` until after the tap and also holds the first `POST /api/chats` after the list loads. Further taps during both waits must send no duplicate save. It then checks that the New Roleplay wizard opens, that no gate appears and that exactly one chat is made. The negative control holds an empty list and checks that the gate opens with "No connections found" and no chat is made. - Tests that are outdated because this PR changes the answer on purpose: - `scripts/regressions/avatar-models.regression.ts` and `e2e/avatar-setup.e2e.ts` expected 404 for "nothing saved yet". They now expect 200 with a `null` body. The regression also checks the JSON content type and adds 404 checks for a missing character and persona. The 404 check after the character is deleted in `avatar-setup.e2e.ts` stays. - `e2e/avatar-generation.e2e.ts` reads a `null` body safely while it polls. - `e2e/avatar-setup.e2e.ts` now also fails if the 2D or 3D setup page logs a failed avatar request. ## 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` Earlier whole-PR validation at `76bb909d4e1503a213f21667d10076ad9c44f9b5` (macOS arm64, Node 24.16.0, pnpm 10.34.5, isolated worktree and disposable data): - `pnpm install --frozen-lockfile --prefer-offline --store-dir <existing shared store>`: exit 0; no lockfile change. - `pnpm check`: exit 0, including localization, formatting, lint/type checks and production build. One pre-existing `HomeProfessorMariChat.tsx:380` hook-dependency warning remains. - `node scripts/run-regressions.mjs --filter scripts/regressions/avatar-models.regression.ts`: 1/1 passed. `avatar-contract.regression.ts` and `frozen-server-client-timeouts.regression.ts` were run through the same runner separately: 1/1 passed each. - `pnpm exec playwright test e2e/home-new-chat-connections-loading.e2e.ts e2e/avatar-setup.e2e.ts --grep 'new roleplay|2D Avatars shows|3D Avatars links' --project=desktop-chromium --project=mobile-chromium --project=mobile-webkit --workers=1`: 12/12 passed. This covers the held-list and held-save positive case, empty-list negative case, and 2D/3D setup without failed avatar requests in all three browser projects. - `pnpm exec playwright test --grep '@smoke|Cancel stops the picture being made|3D Avatars points to VRoid Studio|A model made earlier with Tripo|Connections no longer offers Tripo' --project=desktop-chromium --workers=1`: 11/11 passed, including all seven desktop smoke cases, null-safe avatar-generation polling and the three replacement Tripo-removal cases. - Browser runs used private client ports 5188/5189 and API ports 7981/7982. These are browser emulation results; no native Android/APK/Termux device run is claimed. - `coderabbit review --committed --base origin/staging`: the initial substantive review found one valid issue: the guard ended before the first chat save. The held-save negative control reproduced a second POST on `90b6bef4a`; the guard now spans the full launch. The substantive post-fix review completed across all nine changed files with one minor suggestion, which was dismissed as an intentional non-regression: staging already converted missing query data through `(connections ?? [])` and opened the connection gate, while this PR preserves that fallback with `.catch(() => [])`. Letting the fetch rejection propagate would instead reach `HomeNewChatLauncher`'s catch, which assumes the create mutation already showed a toast and otherwise swallows the error. Redesigning connection-error UX is outside this PR. No additional code change was made for that suggestion. Final-head stale-cache follow-up at `74023dde9efd8523d74af53d3eef9b8c65f92abf` (same macOS arm64 environment, isolated worktree/disposable data): - The hosted review at `76bb909d4` found one valid stale-cache issue: `ensureQueryData` immediately returned cached rows while the mounted connection observer was refetching. The hook now uses `fetchQuery(connectionListQuery)`, which waits for stale data to refresh and joins the observer's pending request. The existing error fallback and full-launch duplicate guard are unchanged. - The actual installed TanStack Query 5.103.0 runtime was checked using the actual production `connectionListQuery` options (five-minute stale time), in both directions: cached empty to configured, and cached configured to empty. The old call returned cached rows immediately; the new call waited for the single held request. - Both new browser negative controls failed against unchanged `76bb909d4`: stale empty data opened the wrong connection gate, and stale configured data sent a premature chat save. Both pass with the final fix. The existing two Home launch assertions were retained; the two new cases also check that repeated taps do not make duplicate saves and that no second connection request is made. - `pnpm check`: exit 0, including localization, formatting, lint/types and the production build; the same pre-existing hook-dependency warning remains. - `pnpm exec playwright test -c playwright.config.ts e2e/home-new-chat-connections-loading.e2e.ts --project=desktop-chromium --project=mobile-chromium --project=mobile-webkit --workers=1` (run serially as desktop and mobile groups on private ports): 12/12 passed. - `pnpm smoke:ui`: 7/7 passed. `pnpm smoke:production`: 3/3 passed across desktop Chromium, mobile Chromium and mobile WebKit. - The preceding full hosted review at `76bb909d4` was audited, including its entire body and inline comments: one actionable finding was accepted and fixed; no outside-diff or nitpick items were present. The earlier local fallback suggestion remains the documented dismissal above. Final-head local incremental review, substantive hosted follow-up and required GitHub checks are separate merge gates; pending/rate-limited statuses are not reported as passed. Earlier negative controls: the avatar-models regression failed against staging with `actual: 404, expected: 200`; the held-list home case failed against the staging hook in desktop and mobile Chromium because the connection gate opened; and the 3D setup case failed against staging with three avatar 404 console errors. Each passed with this PR. Conflict resolution: merged staging `c248baa9e` into this PR and kept staging's deletion of the obsolete `e2e/avatar-vrm-generation.e2e.ts` Tripo-maker test. Its only PR change was a missing-avatar assertion inside a removed paid-generation flow, so it has no corresponding assertion to move to the replacement spec. The active missing-avatar contract remains covered by `avatar-models.regression.ts` and `avatar-setup.e2e.ts`; the replacement `avatar-vrm-tripo-removed.e2e.ts` also passed above. No production behavior was added during the merge. ### Manual verification notes - Manually verify on a phone, the APK or Termux, right after opening the app, that tapping Roleplay on Home opens the New Roleplay wizard rather than "Set Up Roleplay / Choose a connection". Then check that a quick second tap does not leave an extra empty chat in the sidebar. - Manually verify that with no connections at all, Home's Conversation, Roleplay and Game buttons still open the gate with "No connections found". - Manually verify that the omnibar's "New conversation/roleplay/game" commands still start a chat. - Manually verify in the browser console that picking a character or persona with no avatar on the 2D Avatars and 3D Avatars setup pages logs no 404, and that importing or saving an avatar for that owner still works. ## 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) No user-facing docs or UI copy change. ## UI evidence (if applicable) Behaviour only, no visual change. Before this change, tapping Roleplay while the connection list was still loading opened the "Set Up Roleplay" gate showing "No connections found", even though a connection existed. After it, the New Roleplay setup wizard opens. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Avatar setup now handles owners with no saved avatar without displaying an error. Requests for unknown owners still return an error. * Starting a roleplay while connections are loading now waits for the connection list before choosing the next step. * Repeated taps during connection checks or chat creation no longer create duplicate chats. When no connections are available, the connection setup gate is shown. <!-- 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:09:10 +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#7959
No description provided.