[PR #5718] [MERGED] fix(client): stop hanging forever against a frozen server (#5657, #5658, #5659) #6898

Closed
opened 2026-10-23 04:14:42 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5718
Author: @kolacheee
Created: 9/1/2026
Status: ✅ Merged
Merged: 9/1/2026
Merged by: @kolacheee

Base: staging ← Head: fix/5657-5658-frozen-server-client


📝 Commits (3)

  • 93926e6 fix(client): stop hanging forever against a frozen server (#5657, #5658, #5659)
  • 6b1a379 fix(client): close the review gaps in the frozen-server handling
  • 7e14aee fix(client): unreachable overrides time-sensitive telemetry in the diagnostics copy

📊 Changes

11 files changed (+321 additions, -27 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/TROUBLESHOOTING.md (+7 -1)
📝 packages/client/src/App.tsx (+14 -2)
📝 packages/client/src/components/chat/ChatArea.tsx (+35 -12)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+21 -4)
📝 packages/client/src/hooks/use-chats.ts (+11 -2)
📝 packages/client/src/hooks/use-connections.ts (+5 -2)
📝 packages/client/src/lib/api-client.ts (+37 -0)
📝 packages/client/src/lib/support-diagnostics.ts (+17 -4)
📝 packages/client/src/localization/locales/en.json (+3 -0)
➕ scripts/regressions/frozen-server-client-timeouts.regression.ts (+170 -0)

📄 Description

Linked issue

Closes #5657, closes #5658, closes #5659.

Why this change

A frozen host — the Android/Termux cached-app-freezer state triaged in #5660 — accepts TCP connections but never answers them. Against that state the client degraded in three compounding ways: the chat-open fetch had no deadline, so "Opening chat…" spun forever and the error branch never ran (#5657); checkVersion fired a bare /api/health fetch on every visibility change with no in-flight guard, leaking one permanently-pending request per tab-switch until the browser's ~6-per-host connection pool saturated and dragged down even the requests that do carry timeouts (#5658); and the Support Diagnostics health query pended forever, which kept the copy button disabled with no explanation, and a settled-but-failed query rendered an indistinguishable "Unavailable" (#5657). The TROUBLESHOOTING page also misdirected Termux users to install the Termux:API add-on for termux-wake-lock and had no entry for the freeze signature (#5659).

What changed

  • api-client.ts: new requestTimeoutSignal(timeoutMs, upstream?) — a hand-rolled deadline signal (deliberately not AbortSignal.any, for older WebViews) that aborts with a TimeoutError DOMException reason while honouring an upstream signal — and isRequestTimeoutError, a strict classifier that never mistakes React Query's own cancellation for a frozen server.
  • Chat open (#5657): useChat composes a 15s deadline with React Query's cancellation; a timeout is not retried (retrying only multiplies the hang) and renders an explicit "Server unreachable" state with a Termux-foregrounding hint instead of the endless spinner.
  • Version check (#5658): in-flight guard + 10s AbortSignal.timeout (same primitive the keep-alive heartbeat already uses), released in finally on every outcome.
  • Support Diagnostics (#5657): the health query carries a 10s deadline (re-enabling the copy button that was disabled forever behind health.isPending) and the copied server field reads "Unreachable (request timed out)" so support reports carry the signal.
  • Docs (#5659): TROUBLESHOOTING gains a "Marinara stops responding until Termux is brought to the foreground" section describing the freeze signature exactly as the app now presents it, and the termux-wake-lock line is corrected — the command ships in core termux-tools, no add-on needed.

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

Manual verification notes

  • pnpm lint, the production build, and pnpm localization:check are green locally; format:check fails repo-wide on this Windows checkout (pre-existing autocrlf CRLF — the touched files were run through Prettier directly).
  • A two-lens adversarial review ran against the first cut and verified the core mechanism against the installed React Query source (fresh AbortController per fetch; only RQ's own CancelledError counts as cancellation, so the TimeoutError rejection reliably reaches the error state; the composed-signal unmount path is correctly not classified as a timeout). It confirmed six gaps, all fixed in the second commit — most notably that useConnections (the other leg of the copy-button gate) had no deadline and could re-create the stuck-disabled button on a cold-cache boot, and that the unreachable chat state was sticky after the server thawed (now has a Try again button, since focus-refetch is globally off).
  • New regression scripts/regressions/frozen-server-client-timeouts.regression.ts passes: it exercises the deadline/cancellation contract for real (timeout carries the TimeoutError reason; upstream abort wins and is never classified as a timeout; no late TimeoutError overwrite after cancellation; strict classification) plus source pins on all four wiring sites and the locale keys.
  • Please verify in the browser (the issue's own repro): kill -STOP the server, then (a) open a chat — after ~15s the explicit "Server unreachable" state should replace the spinner; (b) flip tab visibility several times with the network panel open — exactly one pending /api/health at a time; (c) Settings → Advanced → Copy Support Diagnostics — button enabled after the timeout, fields read "Unreachable (request timed out)". kill -CONT recovers.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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)

CHANGELOG updated under [Unreleased] → Fixed. docs/TROUBLESHOOTING.md changed — this rides the pending batched [docs-i18n] catch-up together with #5604 (next planned PR in this arc) rather than a per-PR mirror.

UI evidence (if applicable)

The "Server unreachable" chat state and the diagnostics "Unreachable (request timed out)" line are the visible changes — screenshots worth taking during the kill -STOP manual pass.

Summary by CodeRabbit

  • Bug Fixes

    • Added timeout handling for chat, health, version, and connection requests.
    • Frozen or unreachable servers now show a clear error state instead of loading indefinitely.
    • Added a “Try again” option when opening a chat fails.
    • Support diagnostics now identify timed-out servers accurately and restore the copy action.
  • Documentation

    • Updated troubleshooting guidance for frozen Termux processes and background operation.

🔄 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/5718 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/1/2026 **Status:** ✅ Merged **Merged:** 9/1/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/5657-5658-frozen-server-client` --- ### 📝 Commits (3) - [`93926e6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/93926e69c0acf63a6f0d0bd880cb701d1ed831b1) fix(client): stop hanging forever against a frozen server (#5657, #5658, #5659) - [`6b1a379`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6b1a379b59997e4c2b3d1a234cdb51d486f6ba3e) fix(client): close the review gaps in the frozen-server handling - [`7e14aee`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7e14aeef4141e4972e88b8789e98003bcd41d153) fix(client): unreachable overrides time-sensitive telemetry in the diagnostics copy ### 📊 Changes **11 files changed** (+321 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/TROUBLESHOOTING.md` (+7 -1) 📝 `packages/client/src/App.tsx` (+14 -2) 📝 `packages/client/src/components/chat/ChatArea.tsx` (+35 -12) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+21 -4) 📝 `packages/client/src/hooks/use-chats.ts` (+11 -2) 📝 `packages/client/src/hooks/use-connections.ts` (+5 -2) 📝 `packages/client/src/lib/api-client.ts` (+37 -0) 📝 `packages/client/src/lib/support-diagnostics.ts` (+17 -4) 📝 `packages/client/src/localization/locales/en.json` (+3 -0) ➕ `scripts/regressions/frozen-server-client-timeouts.regression.ts` (+170 -0) </details> ### 📄 Description ## Linked issue Closes #5657, closes #5658, closes #5659. ## Why this change A frozen host — the Android/Termux cached-app-freezer state triaged in #5660 — accepts TCP connections but never answers them. Against that state the client degraded in three compounding ways: the chat-open fetch had no deadline, so "Opening chat…" spun forever and the error branch never ran (#5657); `checkVersion` fired a bare `/api/health` fetch on every visibility change with no in-flight guard, leaking one permanently-pending request per tab-switch until the browser's ~6-per-host connection pool saturated and dragged down even the requests that *do* carry timeouts (#5658); and the Support Diagnostics health query pended forever, which kept the copy button disabled with no explanation, and a settled-but-failed query rendered an indistinguishable "Unavailable" (#5657). The TROUBLESHOOTING page also misdirected Termux users to install the Termux:API add-on for `termux-wake-lock` and had no entry for the freeze signature (#5659). ## What changed - **`api-client.ts`**: new `requestTimeoutSignal(timeoutMs, upstream?)` — a hand-rolled deadline signal (deliberately not `AbortSignal.any`, for older WebViews) that aborts with a `TimeoutError` DOMException reason while honouring an upstream signal — and `isRequestTimeoutError`, a strict classifier that never mistakes React Query's own cancellation for a frozen server. - **Chat open (#5657)**: `useChat` composes a 15s deadline with React Query's cancellation; a timeout is not retried (retrying only multiplies the hang) and renders an explicit **"Server unreachable"** state with a Termux-foregrounding hint instead of the endless spinner. - **Version check (#5658)**: in-flight guard + 10s `AbortSignal.timeout` (same primitive the keep-alive heartbeat already uses), released in `finally` on every outcome. - **Support Diagnostics (#5657)**: the health query carries a 10s deadline (re-enabling the copy button that was disabled forever behind `health.isPending`) and the copied server field reads **"Unreachable (request timed out)"** so support reports carry the signal. - **Docs (#5659)**: TROUBLESHOOTING gains a "Marinara stops responding until Termux is brought to the foreground" section describing the freeze signature exactly as the app now presents it, and the `termux-wake-lock` line is corrected — the command ships in core `termux-tools`, no add-on needed. ## 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` ### Manual verification notes - `pnpm lint`, the production build, and `pnpm localization:check` are green locally; `format:check` fails repo-wide on this Windows checkout (pre-existing autocrlf CRLF — the touched files were run through Prettier directly). - A two-lens adversarial review ran against the first cut and verified the core mechanism against the installed React Query source (fresh AbortController per fetch; only RQ's own `CancelledError` counts as cancellation, so the `TimeoutError` rejection reliably reaches the error state; the composed-signal unmount path is correctly *not* classified as a timeout). It confirmed six gaps, all fixed in the second commit — most notably that `useConnections` (the *other* leg of the copy-button gate) had no deadline and could re-create the stuck-disabled button on a cold-cache boot, and that the unreachable chat state was sticky after the server thawed (now has a **Try again** button, since focus-refetch is globally off). - New regression `scripts/regressions/frozen-server-client-timeouts.regression.ts` passes: it exercises the deadline/cancellation contract for real (timeout carries the `TimeoutError` reason; upstream abort wins and is never classified as a timeout; no late `TimeoutError` overwrite after cancellation; strict classification) plus source pins on all four wiring sites and the locale keys. - **Please verify in the browser** (the issue's own repro): `kill -STOP` the server, then (a) open a chat — after ~15s the explicit "Server unreachable" state should replace the spinner; (b) flip tab visibility several times with the network panel open — exactly one pending `/api/health` at a time; (c) Settings → Advanced → Copy Support Diagnostics — button enabled after the timeout, fields read "Unreachable (request timed out)". `kill -CONT` recovers. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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) CHANGELOG updated under **[Unreleased] → Fixed**. `docs/TROUBLESHOOTING.md` changed — this rides the pending batched `[docs-i18n]` catch-up together with #5604 (next planned PR in this arc) rather than a per-PR mirror. ## UI evidence (if applicable) The "Server unreachable" chat state and the diagnostics "Unreachable (request timed out)" line are the visible changes — screenshots worth taking during the `kill -STOP` manual pass. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Added timeout handling for chat, health, version, and connection requests. * Frozen or unreachable servers now show a clear error state instead of loading indefinitely. * Added a “Try again” option when opening a chat fails. * Support diagnostics now identify timed-out servers accurately and restore the copy action. * **Documentation** * Updated troubleshooting guidance for frozen Termux processes and background operation. <!-- 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-23 04:14:42 +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#6898
No description provided.