[PR #3941] [MERGED] fix: recover Professor Mari's reply on tab resume + alert on pending approval #6167

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3941
Author: @Gunterlie
Created: 7/22/2026
Status: ✅ Merged
Merged: 7/22/2026
Merged by: @SpicyMarinara

Base: staging ← Head: mari-task-persistence


📝 Commits (4)

  • 78afdf7 fix: recover Professor Mari's reply on tab resume + alert on pending approval
  • 7a58641 fix: keep Professor Mari's workspace run alive across a passive disconnect
  • e42e14f Merge branch 'staging' into mari-task-persistence
  • 2f9fa22 fix: wait for detached Mari run to settle before reloading

📊 Changes

4 files changed (+110 additions, -3 deletions)

View changed files

📝 packages/client/src/components/chat/HomeProfessorMariChat.tsx (+66 -1)
📝 packages/client/src/hooks/use-generate.ts (+4 -0)
📝 packages/client/src/lib/api-client.ts (+37 -1)
📝 packages/server/src/routes/professor-mari-workspace.routes.ts (+3 -1)

📄 Description

Linked issue

Closes #3940

Why this change

Give Professor Mari a task, then leave — background the tab, lock the phone, switch chats — and on return her work appears frozen. The browser suspends the tab and the SSE socket goes half-open, so reader.read() never settles again. The reply she actually finished (the server keeps generating after a passive client disconnect and saves it) never shows, and no notification fires; only a new command unblocks the zombie stream. Separately, when she finishes and is blocked on your approval, nothing pulls you back if you have stepped away.

What changed

  • api-client.ts — opt-in resume watchdog in streamEvents. New { disconnectOnResume } option: on the first hidden→visible flip mid-stream, reject the pending read with a normal Error. This lets the existing passive-recovery path (isPassiveStreamDisconnect → waitForServerGenerationToSettle → refreshMessagesAuthoritatively) run and refetch the finished reply, and fire its existing "reply ready" notification. Opt-in so background-autonomous streams (which run while hidden by design) are unaffected.
  • use-generate.ts — enable the watchdog on the main /generate stream only (not /generate/retry-agents, which has its own handling).
  • HomeProfessorMariChat.tsx — notify "Professor Mari needs your approval" when a new pending approval appears. Reuses the existing notification helpers (they self-suppress while focused, so a present user just sees the in-app review card). Dedupes by approval id.

No new dependencies, no new settings, no server changes.

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 check was run by the agent and passed (impeccable check + lint + build, exit 0). The following still need a human to verify in a real browser/app — treat the boxes above as a TO-DO list, not proof:

  • Manually verify in browser: start a Roleplay/Conversation generation, background the tab (or switch to another chat) until it finishes server-side, then return — the reply should appear and a "reply ready" notification should fire (with generation notifications enabled + permission granted).
  • Manually verify on mobile / locked screen (PWA + Android native bridge) that the same resume-refetch path fires.
  • Manually verify a false-positive resume (brief tab switch while streaming, connection still alive) degrades gracefully to a post-generation refetch with no error toast and no duplicated/empty message.
  • Manually verify: trigger a Professor Mari workspace change that needs approval, leave the window, and confirm the "needs your approval" notification fires and the review card is present on return. Confirm no notification when the app stays focused.
  • Manually verify no duplicate notifications when multiple approvals arrive or status re-polls.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

No visual changes; behavior only (stream recovery + OS/native notifications).

Summary by CodeRabbit

  • New Features

    • Added notifications for newly pending workspace approvals while Professor Mari is awaiting action.
    • Improved recovery of streamed responses after returning to a backgrounded tab.
  • Bug Fixes

    • Prevented chat and generation requests from hanging after browser tab suspension.
    • Preserved in-progress workspace runs when the client disconnects, allowing results to be retrieved upon return.

🔄 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/3941 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 7/22/2026 **Status:** ✅ Merged **Merged:** 7/22/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `mari-task-persistence` --- ### 📝 Commits (4) - [`78afdf7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/78afdf74e87f9d2eff8d1e46e5311a21752de8e3) fix: recover Professor Mari's reply on tab resume + alert on pending approval - [`7a58641`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7a586417df621561a1fb457e9dc52d686f6bf154) fix: keep Professor Mari's workspace run alive across a passive disconnect - [`e42e14f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e42e14fe5674b5b83d04b586d21247709e72fbd0) Merge branch 'staging' into mari-task-persistence - [`2f9fa22`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2f9fa227ce0b6d4e91e7e309e11fc5437c64715c) fix: wait for detached Mari run to settle before reloading ### 📊 Changes **4 files changed** (+110 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/HomeProfessorMariChat.tsx` (+66 -1) 📝 `packages/client/src/hooks/use-generate.ts` (+4 -0) 📝 `packages/client/src/lib/api-client.ts` (+37 -1) 📝 `packages/server/src/routes/professor-mari-workspace.routes.ts` (+3 -1) </details> ### 📄 Description <!-- Target branch: `staging`. --> ## Linked issue Closes #3940 ## Why this change Give Professor Mari a task, then leave — background the tab, lock the phone, switch chats — and on return her work appears frozen. The browser suspends the tab and the SSE socket goes half-open, so `reader.read()` never settles again. The reply she actually finished (the server keeps generating after a passive client disconnect and saves it) never shows, and no notification fires; only a *new* command unblocks the zombie stream. Separately, when she finishes and is blocked on your approval, nothing pulls you back if you have stepped away. ## What changed - **`api-client.ts` — opt-in resume watchdog in `streamEvents`.** New `{ disconnectOnResume }` option: on the first hidden→visible flip mid-stream, reject the pending read with a normal `Error`. This lets the **existing** passive-recovery path (`isPassiveStreamDisconnect` → `waitForServerGenerationToSettle` → `refreshMessagesAuthoritatively`) run and refetch the finished reply, and fire its existing "reply ready" notification. Opt-in so background-autonomous streams (which run *while* hidden by design) are unaffected. - **`use-generate.ts`** — enable the watchdog on the main `/generate` stream only (not `/generate/retry-agents`, which has its own handling). - **`HomeProfessorMariChat.tsx`** — notify "Professor Mari needs your approval" when a new pending approval appears. Reuses the existing notification helpers (they self-suppress while focused, so a present user just sees the in-app review card). Dedupes by approval id. No new dependencies, no new settings, no server changes. ## 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 check` was run by the agent and passed (impeccable check + lint + build, exit 0). The following still need a human to verify in a real browser/app — treat the boxes above as a TO-DO list, not proof: - Manually verify in browser: start a Roleplay/Conversation generation, background the tab (or switch to another chat) until it finishes server-side, then return — the reply should appear and a "reply ready" notification should fire (with generation notifications enabled + permission granted). - Manually verify on mobile / locked screen (PWA + Android native bridge) that the same resume-refetch path fires. - Manually verify a false-positive resume (brief tab switch while streaming, connection still alive) degrades gracefully to a post-generation refetch with no error toast and no duplicated/empty message. - Manually verify: trigger a Professor Mari workspace change that needs approval, leave the window, and confirm the "needs your approval" notification fires and the review card is present on return. Confirm no notification when the app stays focused. - Manually verify no duplicate notifications when multiple approvals arrive or status re-polls. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) No visual changes; behavior only (stream recovery + OS/native notifications). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added notifications for newly pending workspace approvals while Professor Mari is awaiting action. - Improved recovery of streamed responses after returning to a backgrounded tab. - **Bug Fixes** - Prevented chat and generation requests from hanging after browser tab suspension. - Preserved in-progress workspace runs when the client disconnects, allowing results to be retrieved upon return. <!-- 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:07: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#6167
No description provided.