[GH-ISSUE #4637] [Issue]: Professor Mari permanently unresponsive after agentic task completes — stuck sending/isBusy deadlock gates all recovery paths (Android/Termux) #2535

Closed
opened 2026-10-21 05:49:44 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @kolacheee on GitHub (Aug 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4637

Originally assigned to: @SpicyMarinara on GitHub.

Summary

After a Professor Mari agentic/workspace task completes, the UI can become permanently unresponsive — suggestion chips, the command input, and starting a new session are all dead — requiring a full app reload. Root cause: the sending/isBusy flag chain can get stuck after the stream has already finished, because post-completion cleanup awaits have no timeout/abort/resume protection, and every in-app path that could recover is itself gated on !isBusy — a true deadlock. Reported on Android via Termux (v2.4.1, agentic run); the code is unchanged on current staging.

Original report: "Android, via Termux. V2.4.1. Agentic with prof Mari. Prof Mari unresponsive after task completed. Need to exit app and load again before you can select suggestion, type new command, or start new session."

Expected behavior

Once a task completes (reply + suggestions visible), Mari returns to idle: chips clickable, input enabled, restart available. Any post-run cleanup that stalls should be bounded and must never wedge the UI.

Actual behavior

All three reported controls hang off one expression — const isBusy = sending || hasActiveGeneration || workspaceActive (packages/client/src/components/chat/HomeProfessorMariChat.tsx:2380):

  • suggestion chips disabled={isBusy} (:3740 floating, :4388 embedded)
  • composer textarea + send disabled={isBusy} (:3837/:3841, :4495/:4499), and handleSubmit early-returns on isBusy (:3604)
  • new session: runRestart begins if (isBusy) return; (:2950) and the Restart button is disabled={isBusy} (:4295)
  • chat switching is also gated with a "wait for Professor Mari to finish" toast (:3164-3166)

The trap: after sendWorkspaceMessage finishes streaming (its finally at :3469-3474 clears workspaceActive/activity — so the reply and chips are on screen and the Stop button disappears), handleSubmit is still inside its sending = true window (:3618) running three unprotected plain awaits: await loadMessages(chat.id) (:3628), await refreshWorkspaceStatus() (:3632), await invalidateWorkspaceData() (:3633 — invalidateQueries({refetchType: "all"}), which awaits every query refetch app-wide). setSending(false) only runs in the finally at :3649, after all of them. apiFetch has no timeout (api-client.ts:204-224).

If any of those requests hangs, sending is stuck true forever:

  • A new loadMessages call would abort the hung one (messageLoadAbortRef, :2439-2441) — but every caller (submit :3604, restart :2950, chat select :3164, regenerate :3513) early-returns on isBusy. The stuck flag gates every path that could clear it.
  • The Stop button is not rendered at all — it requires (workspaceActive || hasActiveGeneration) (:4283), both already false.
  • The 15s visibility/interval refresh (:2591-2600) only updates display-only workspace status; it never touches sending.

Result: a completed task with visible-but-dead chips and a dead composer. Only a reload discards the hung promise. (Same unprotected pattern in handleRegenerateMessage: setSending :3530, loadMessages :3555/:3560, finally :3564.)

Why Android/Termux hits this

  1. Tab freeze mid-fetch. Android freezing the page can leave an in-flight fetch promise that never settles nor rejects after resume — the exact platform pathology this repo already documents for reader.read() in api-client.ts:457-461. PR #3941 (#3940) armored the stream reads against this; the post-completion plain fetches got no equivalent protection.
  2. The Termux server is a prime freeze target. The moment a run completes the server goes idle, and Android's app-freezer/phantom-process management can freeze it just as the client issues its post-run loadMessages — TCP connects from the kernel backlog, no response ever arrives, and fetch waits forever.

Confirmed sibling entry points into the same deadlock

  • waitForWorkspaceRunToSettle (the #3941 recovery path, :108-130, entered at :3461-3468) issues its status GET (:113) with no AbortSignal and no per-request timeout — a stalled GET wedges workspaceActive instead, with activity stuck on "Finishing in the background…". (Its 30-minute deadline WORKSPACE_SETTLE_MAX_WAIT_MS, :103/:111, is only checked between iterations.)
  • The resume watchdog in api-client.ts permanently disarms after one settled read (wasHidden = false reset at :508) and is not armed for visible-at-start streams — a later half-open stream hangs the final reader.read() unguarded, wedging workspaceActive.
  • The workspace stream route ends without a terminal sentinel (professor-mari-workspace.routes.ts:148-153), so the client depends entirely on a clean stream close to reach its terminal handling.

Steps to reproduce

Deterministic desktop simulation (the real-world trigger is probabilistic backgrounding):

  1. Open Home / Professor Mari, run an agentic task.
  2. In DevTools, throttle or block the GET /chats/:id/messages request that fires right after the stream completes (Network → block URL / offline at the right moment), so loadMessages never settles.
  3. Observe: reply + suggestion chips render, but chips/input/restart are all disabled indefinitely; no Stop button; only reload recovers.

Real-world repro (per the report): run a long agentic task on Android (Termux server), background or lock the phone around completion, return.

Environment

  • Marinara Engine version: reported on 2.4.1; code verified unchanged on staging 2.4.2 (93738d9b1)
  • Install type: Termux (server on-device) + Android browser client
  • OS + version: Android
  • Browser or app shell: mobile browser / PWA

Logs, screenshots, or video

Verified by code trace (six independent confirmation passes over the trigger sequences; key lines quoted above and re-checked by hand against staging).

Additional context

Relation to #4628: distinct root cause. The completion-burst theory (unthrottled render wedging the phone) was explicitly refuted — the user seeing the completed task and chips proves paint finished. #4628 is only an accessory here: its post-completion main-thread stall widens the window in which backgrounding lands mid-await. Relation to #3940/#3941: the user has that fix (merge commit 96b5d5bbe is in v2.4.1); this bug lives in the paths #3941 did not cover.

Suggested layered fix (any of 1–3 unwedges; together they're robust):

  1. Shrink the sending critical section: clear sending as soon as the send stream settles; run the post-run refetches (loadMessages / refreshWorkspaceStatus / invalidateWorkspaceData) as best-effort background cleanup outside the gating window (or bound them with AbortSignal.timeout).
  2. Bound the settle poll: pass an abortable, time-bounded signal to the status GET in waitForWorkspaceRunToSettle (e.g. AbortSignal.any([signal, AbortSignal.timeout(10_000)])), treating a timeout like a failed poll iteration.
  3. Don't disarm the stream watchdog: latch "was ever hidden" instead of resetting on the first settled read, so a stream that was backgrounded keeps its inactivity guard (the server's 15s SSE keepalive makes prolonged silence provable death).
  4. Server: emit a terminal sentinel before ending the workspace stream so the client can distinguish completion from a dropped connection.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Aug 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4637 Originally assigned to: @SpicyMarinara on GitHub. ## Summary After a Professor Mari agentic/workspace task completes, the UI can become permanently unresponsive — suggestion chips, the command input, and starting a new session are all dead — requiring a full app reload. Root cause: the `sending`/`isBusy` flag chain can get stuck **after** the stream has already finished, because post-completion cleanup awaits have no timeout/abort/resume protection, and **every in-app path that could recover is itself gated on `!isBusy`** — a true deadlock. Reported on Android via Termux (v2.4.1, agentic run); the code is unchanged on current staging. > Original report: *"Android, via Termux. V2.4.1. Agentic with prof Mari. Prof Mari unresponsive after task completed. Need to exit app and load again before you can select suggestion, type new command, or start new session."* ## Expected behavior Once a task completes (reply + suggestions visible), Mari returns to idle: chips clickable, input enabled, restart available. Any post-run cleanup that stalls should be bounded and must never wedge the UI. ## Actual behavior All three reported controls hang off one expression — `const isBusy = sending || hasActiveGeneration || workspaceActive` (`packages/client/src/components/chat/HomeProfessorMariChat.tsx:2380`): - suggestion chips `disabled={isBusy}` (:3740 floating, :4388 embedded) - composer textarea + send `disabled={isBusy}` (:3837/:3841, :4495/:4499), and `handleSubmit` early-returns on `isBusy` (:3604) - new session: `runRestart` begins `if (isBusy) return;` (:2950) and the Restart button is `disabled={isBusy}` (:4295) - chat switching is also gated with a "wait for Professor Mari to finish" toast (:3164-3166) **The trap:** after `sendWorkspaceMessage` finishes streaming (its `finally` at :3469-3474 clears `workspaceActive`/activity — so the reply and chips are on screen and the Stop button disappears), `handleSubmit` is still inside its `sending = true` window (:3618) running three **unprotected plain awaits**: `await loadMessages(chat.id)` (:3628), `await refreshWorkspaceStatus()` (:3632), `await invalidateWorkspaceData()` (:3633 — `invalidateQueries({refetchType: "all"})`, which awaits every query refetch app-wide). `setSending(false)` only runs in the `finally` at :3649, *after* all of them. `apiFetch` has no timeout (`api-client.ts:204-224`). If any of those requests hangs, `sending` is stuck true forever: - A new `loadMessages` call would abort the hung one (`messageLoadAbortRef`, :2439-2441) — but every caller (submit :3604, restart :2950, chat select :3164, regenerate :3513) early-returns on `isBusy`. **The stuck flag gates every path that could clear it.** - The Stop button is not rendered at all — it requires `(workspaceActive || hasActiveGeneration)` (:4283), both already false. - The 15s visibility/interval refresh (:2591-2600) only updates display-only workspace status; it never touches `sending`. Result: a *completed* task with visible-but-dead chips and a dead composer. Only a reload discards the hung promise. (Same unprotected pattern in `handleRegenerateMessage`: setSending :3530, loadMessages :3555/:3560, finally :3564.) ### Why Android/Termux hits this 1. **Tab freeze mid-fetch.** Android freezing the page can leave an in-flight `fetch` promise that never settles nor rejects after resume — the exact platform pathology this repo already documents for `reader.read()` in `api-client.ts:457-461`. PR #3941 (#3940) armored the **stream reads** against this; the post-completion plain fetches got no equivalent protection. 2. **The Termux server is a prime freeze target.** The moment a run completes the server goes idle, and Android's app-freezer/phantom-process management can freeze it just as the client issues its post-run `loadMessages` — TCP connects from the kernel backlog, no response ever arrives, and fetch waits forever. ### Confirmed sibling entry points into the same deadlock - `waitForWorkspaceRunToSettle` (the #3941 recovery path, :108-130, entered at :3461-3468) issues its status GET (:113) with **no AbortSignal and no per-request timeout** — a stalled GET wedges `workspaceActive` instead, with activity stuck on "Finishing in the background…". (Its 30-minute deadline `WORKSPACE_SETTLE_MAX_WAIT_MS`, :103/:111, is only checked *between* iterations.) - The resume watchdog in `api-client.ts` **permanently disarms after one settled read** (`wasHidden = false` reset at :508) and is not armed for visible-at-start streams — a later half-open stream hangs the final `reader.read()` unguarded, wedging `workspaceActive`. - The workspace stream route ends without a terminal sentinel (`professor-mari-workspace.routes.ts:148-153`), so the client depends entirely on a clean stream close to reach its terminal handling. ## Steps to reproduce Deterministic desktop simulation (the real-world trigger is probabilistic backgrounding): 1. Open Home / Professor Mari, run an agentic task. 2. In DevTools, throttle or block the `GET /chats/:id/messages` request that fires **right after** the stream completes (Network → block URL / offline at the right moment), so `loadMessages` never settles. 3. Observe: reply + suggestion chips render, but chips/input/restart are all disabled indefinitely; no Stop button; only reload recovers. Real-world repro (per the report): run a long agentic task on Android (Termux server), background or lock the phone around completion, return. ## Environment - Marinara Engine version: reported on 2.4.1; code verified unchanged on staging 2.4.2 (93738d9b1) - Install type: Termux (server on-device) + Android browser client - OS + version: Android - Browser or app shell: mobile browser / PWA ## Logs, screenshots, or video Verified by code trace (six independent confirmation passes over the trigger sequences; key lines quoted above and re-checked by hand against staging). ## Additional context **Relation to #4628:** distinct root cause. The completion-burst theory (unthrottled render wedging the phone) was explicitly refuted — the user *seeing* the completed task and chips proves paint finished. #4628 is only an accessory here: its post-completion main-thread stall widens the window in which backgrounding lands mid-await. **Relation to #3940/#3941:** the user has that fix (merge commit 96b5d5bbe is in v2.4.1); this bug lives in the paths #3941 did not cover. Suggested layered fix (any of 1–3 unwedges; together they're robust): 1. **Shrink the `sending` critical section**: clear `sending` as soon as the send stream settles; run the post-run refetches (`loadMessages` / `refreshWorkspaceStatus` / `invalidateWorkspaceData`) as best-effort background cleanup outside the gating window (or bound them with `AbortSignal.timeout`). 2. **Bound the settle poll**: pass an abortable, time-bounded signal to the status GET in `waitForWorkspaceRunToSettle` (e.g. `AbortSignal.any([signal, AbortSignal.timeout(10_000)])`), treating a timeout like a failed poll iteration. 3. **Don't disarm the stream watchdog**: latch "was ever hidden" instead of resetting on the first settled read, so a stream that was backgrounded keeps its inactivity guard (the server's 15s SSE keepalive makes prolonged silence provable death). 4. **Server**: emit a terminal sentinel before ending the workspace stream so the client can distinguish completion from a dropped connection. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:49:44 +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#2535
No description provided.