[GH-ISSUE #2887] [Issue]: Professor Mari "Restart" button silently deletes chat history before failing, causing delayed data loss #1468

Closed
opened 2026-10-21 05:36:02 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @spacyH on GitHub (Jun 27, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2887

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The "Restart" button in the Professor Mari home chat (HomeProfessorMariChat.tsx) deletes all chat messages from the database before calling the server-side reset endpoint. When the server call subsequently fails, the user sees an error toast ("Professor Mari could not restart her notes."), but the destruction has already occurred. The messages appear to remain in the UI due to stale React state, only vanishing later when a refetch reveals the post-deletion reality.

This creates a deeply confusing experience where the data loss appears to happen randomly and is disconnected from the user action that caused it.

[NOTE: The initial investigation & recommendations were made by Prof. Mari, then reviewed & refined by Cursor (Composer 2.5) and me.]

Expected behavior

  • The restart operation should be atomic — either all steps succeed or no destructive action is taken.
  • If the server reset fails, chat history should be preserved.
  • The error toast should only appear when the operation actually failed, meaning no partial destruction should have occurred.
  • If any step fails after partial work, the UI should immediately reflect database reality (no stale messages masking deletion).

Actual behavior

Chat messages are irreversibly deleted from the database even when the restart operation fails. The data loss is delayed in its visible effect because stale React state continues to render the deleted messages until a refetch occurs.

Steps to reproduce

  1. Open the Professor Mari home chat
  2. Accumulate a conversation history (several messages back and forth)
  3. Click the "Restart" button (or send the /restart command)
  4. Observe that restart runs as two separate HTTP requests in sequence (not one atomic operation):
    • Request A: POST /chats/{chatId}/messages/bulk-delete — commits message deletion as soon as the server returns success (HTTP 204)
    • Request B: POST /professor-mari/workspace/reset — only sent after Request A completes
  5. If Request B fails for any reason after Request A has already succeeded:
    • Observe the error toast: "Professor Mari could not restart her notes."
    • Messages appear to still be present in the UI (stale local state; deletion already committed)
  6. Trigger a message refetch — for example:
    • Send another message (which calls loadMessages() after the send completes), or
    • Navigate away and back so the component remounts and reloads history, or
    • Refresh the app
  7. All messages that existed at the time of the restart click are gone (any messages created after step 3 may survive as new DB rows)

Why bulk-delete can succeed while reset fails

This is not a case of "the network works for one endpoint but not the other" in a mysterious way. Both requests usually hit the same server. The problem is ordering: the client performs an irreversible delete first, then attempts the reset. Any failure on the second step leaves you in a broken state.

Plausible failure modes for Request B after Request A has already committed:

Failure on reset (Request B) Bulk-delete (Request A) already done?
Server error during abort() or clearHistory() (e.g. filesystem mkdir/writeFile failure) Yes — messages already gone from DB
HTTP 500 / timeout on the reset route Yes
Server process restart or crash between the two requests Yes
Client tab closed or navigation mid-sequence after A returns Yes
Genuine network loss after A completes but before B finishes Yes

So the bug does not require exotic network partitioning. It requires only: delete committed, then something goes wrong before the rest of restart finishes. In practice, server-side errors on the workspace reset path are at least as likely as a network flake on the second call.

Note: The 2-second workspace status poll does not refetch chat messages. It only updates workspace activity state. The delayed wipe is caused by explicit loadMessages() calls or component remounts, not by status polling.

Environment

  • Marinara Engine version: 2.0.5
  • Install type: docker
  • OS + version: macOS 26 with Orbswarm container engine
  • Browser or app shell: Arc for macOS

Root Cause

  • Component: packages/client/src/components/chat/HomeProfessorMariChat.tsx
  • Server route: POST /professor-mari/workspace/reset (packages/server/src/routes/professor-mari-workspace.routes.ts)
  • Server service: ProfessorMariWorkspaceService.reset() (packages/server/src/services/professor-mari/workspace-agent.service.ts)
  • Chat affected: Professor Mari home chat resolved via GET /chats/internal/professor-mari (metadata marker internalAssistant: "professor-mari"). The synthetic welcome message uses id __professor_mari_home_welcome__; that is not the persisted chat id.

In HomeProfessorMariChat.tsx, the handleRestart function executes steps in a destructive order:

Step 1: GET /chats/internal/professor-mari     → resolve chat     ✅ succeeds
Step 2: GET /chats/{chatId}/messages           → fetch all msgs   ✅ succeeds
Step 3: POST .../messages/bulk-delete          → DELETE ALL MSGS  ✅ succeeds  ← 💀 DATA GONE
Step 4: POST /professor-mari/workspace/reset   → server reset     ❌ THROWS
Step 5: setMessages([]) + invalidate queries   ⛔ never reached (after throw)

Step 3 (bulk message deletion) runs before Step 4 (server reset). When Step 4 throws, the catch block in runRestart fires and the error toast is shown — but the messages are already deleted from the database.

Step 5 (clearing local UI state) is positioned after the throwing line, so it never executes. The component keeps rendering messages from local useState, not React Query, masking the damage until loadMessages() runs again.

Two different "histories" (important distinction)

Restart clears two separate stores, and conflating them leads to incomplete fixes:

Store What it holds Cleared by
Chat messages Visible conversation in the UI Client bulk-delete
Workspace journal Mari command/approval history on disk Server reset({ clearHistory: true })

The server reset() with clearHistory: true only wipes the workspace journal file. It does not delete chat messages. The client bulk-delete is required for a full "empty chat" restart — the bug is that it runs too early, not that it exists.

Relevant server-side code

The server-side reset() is well-behaved on its own — it only clears the workspace journal when asked:

// packages/server/src/services/professor-mari/workspace-agent.service.ts
async reset(options?: { clearHistory?: boolean }) {
  await this.abort();
  this.lastError = null;
  if (options?.clearHistory === true) await getMariDbService(this.app.db).clearHistory();
}

clearHistory() writes an empty workspace history file; it does not touch the chats/messages tables. The bug is entirely in the client-side ordering.

Additional notes

  • The /restart chat command triggers the same handleRestart / runRestart path and has the same bug.
  • Creating or updating a Mari skill also calls reset() but without clearHistory, so it does not trigger this specific data-loss path.
  • The server-side clearHistory() method itself is not at fault — the issue is the client deleting messages before the server call.
  • No journal entries are written during the client-side deletion, making recovery impossible after the fact.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @spacyH on GitHub (Jun 27, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2887 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The "Restart" button in the Professor Mari home chat (`HomeProfessorMariChat.tsx`) deletes all chat messages from the database **before** calling the server-side reset endpoint. When the server call subsequently fails, the user sees an error toast ("Professor Mari could not restart her notes."), but the destruction has already occurred. The messages appear to remain in the UI due to stale React state, only vanishing later when a refetch reveals the post-deletion reality. This creates a deeply confusing experience where the data loss appears to happen randomly and is disconnected from the user action that caused it. _[NOTE: The initial investigation & recommendations were made by Prof. Mari, then reviewed & refined by Cursor (Composer 2.5) and me.]_ ## Expected behavior - The restart operation should be atomic — either all steps succeed or no destructive action is taken. - If the server reset fails, chat history should be preserved. - The error toast should only appear when the operation actually failed, meaning no partial destruction should have occurred. - If any step fails after partial work, the UI should immediately reflect database reality (no stale messages masking deletion). ## Actual behavior Chat messages are irreversibly deleted from the database even when the restart operation fails. The data loss is delayed in its visible effect because stale React state continues to render the deleted messages until a refetch occurs. ## Steps to reproduce 1. Open the Professor Mari home chat 2. Accumulate a conversation history (several messages back and forth) 3. Click the "Restart" button (or send the `/restart` command) 4. Observe that restart runs as **two separate HTTP requests in sequence** (not one atomic operation): - **Request A:** `POST /chats/{chatId}/messages/bulk-delete` — commits message deletion as soon as the server returns success (HTTP 204) - **Request B:** `POST /professor-mari/workspace/reset` — only sent after Request A completes 5. If Request B fails for any reason after Request A has already succeeded: - Observe the error toast: "Professor Mari could not restart her notes." - Messages **appear** to still be present in the UI (stale local state; deletion already committed) 6. Trigger a message refetch — for example: - Send another message (which calls `loadMessages()` after the send completes), or - Navigate away and back so the component remounts and reloads history, or - Refresh the app 7. **All messages that existed at the time of the restart click are gone** (any messages created after step 3 may survive as new DB rows) ### Why bulk-delete can succeed while reset fails This is **not** a case of "the network works for one endpoint but not the other" in a mysterious way. Both requests usually hit the same server. The problem is **ordering**: the client performs an irreversible delete first, then attempts the reset. Any failure on the second step leaves you in a broken state. Plausible failure modes for Request B after Request A has already committed: | Failure on reset (Request B) | Bulk-delete (Request A) already done? | |------------------------------|---------------------------------------| | Server error during `abort()` or `clearHistory()` (e.g. filesystem `mkdir`/`writeFile` failure) | Yes — messages already gone from DB | | HTTP 500 / timeout on the reset route | Yes | | Server process restart or crash between the two requests | Yes | | Client tab closed or navigation mid-sequence after A returns | Yes | | Genuine network loss **after** A completes but **before** B finishes | Yes | So the bug does not require exotic network partitioning. It requires only: **delete committed, then something goes wrong before the rest of restart finishes.** In practice, server-side errors on the workspace reset path are at least as likely as a network flake on the second call. > **Note:** The 2-second workspace status poll does **not** refetch chat messages. It only updates workspace activity state. The delayed wipe is caused by explicit `loadMessages()` calls or component remounts, not by status polling. ## Environment - Marinara Engine version: 2.0.5 - Install type: docker - OS + version: macOS 26 with Orbswarm container engine - Browser or app shell: Arc for macOS ## Root Cause - **Component**: `packages/client/src/components/chat/HomeProfessorMariChat.tsx` - **Server route**: `POST /professor-mari/workspace/reset` (`packages/server/src/routes/professor-mari-workspace.routes.ts`) - **Server service**: `ProfessorMariWorkspaceService.reset()` (`packages/server/src/services/professor-mari/workspace-agent.service.ts`) - **Chat affected**: Professor Mari home chat resolved via `GET /chats/internal/professor-mari` (metadata marker `internalAssistant: "professor-mari"`). The synthetic welcome message uses id `__professor_mari_home_welcome__`; that is not the persisted chat id. In `HomeProfessorMariChat.tsx`, the `handleRestart` function executes steps in a destructive order: ``` Step 1: GET /chats/internal/professor-mari → resolve chat ✅ succeeds Step 2: GET /chats/{chatId}/messages → fetch all msgs ✅ succeeds Step 3: POST .../messages/bulk-delete → DELETE ALL MSGS ✅ succeeds ← 💀 DATA GONE Step 4: POST /professor-mari/workspace/reset → server reset ❌ THROWS Step 5: setMessages([]) + invalidate queries ⛔ never reached (after throw) ``` Step 3 (bulk message deletion) runs **before** Step 4 (server reset). When Step 4 throws, the catch block in `runRestart` fires and the error toast is shown — but the messages are already deleted from the database. Step 5 (clearing local UI state) is positioned **after** the throwing line, so it never executes. The component keeps rendering messages from local `useState`, not React Query, masking the damage until `loadMessages()` runs again. ### Two different "histories" (important distinction) Restart clears **two separate stores**, and conflating them leads to incomplete fixes: | Store | What it holds | Cleared by | |-------|---------------|------------| | **Chat messages** | Visible conversation in the UI | Client `bulk-delete` | | **Workspace journal** | Mari command/approval history on disk | Server `reset({ clearHistory: true })` | The server `reset()` with `clearHistory: true` only wipes the workspace journal file. It does **not** delete chat messages. The client bulk-delete is required for a full "empty chat" restart — the bug is that it runs too early, not that it exists. ### Relevant server-side code The server-side `reset()` is well-behaved on its own — it only clears the workspace journal when asked: ```ts // packages/server/src/services/professor-mari/workspace-agent.service.ts async reset(options?: { clearHistory?: boolean }) { await this.abort(); this.lastError = null; if (options?.clearHistory === true) await getMariDbService(this.app.db).clearHistory(); } ``` `clearHistory()` writes an empty workspace history file; it does not touch the chats/messages tables. The bug is entirely in the **client-side ordering**. ## Additional notes - The `/restart` chat command triggers the same `handleRestart` / `runRestart` path and has the same bug. - Creating or updating a Mari skill also calls `reset()` but **without** `clearHistory`, so it does not trigger this specific data-loss path. - The server-side `clearHistory()` method itself is not at fault — the issue is the client deleting messages before the server call. - No journal entries are written during the client-side deletion, making recovery impossible after the fact. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:36:02 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@SpicyMarinara commented on GitHub (Jun 28, 2026):

Hm, that's strange. When I click Restart on Professor Mari's chat, all the messages instantly vanish and I get the toast notification that it was restarted. I'm also on Mac, though I did not install via Docker, obviously. I'll investigate the issue, but all looks good on my end and others are reporting it works correctly, too.

<!-- gh-comment-id:4825497179 --> @SpicyMarinara commented on GitHub (Jun 28, 2026): Hm, that's strange. When I click Restart on Professor Mari's chat, all the messages instantly vanish and I get the toast notification that it was restarted. I'm also on Mac, though I did not install via Docker, obviously. I'll investigate the issue, but all looks good on my end and others are reporting it works correctly, too.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 28, 2026):

Fixed in the local staging branch: Professor Mari home-chat restart now requires /professor-mari/workspace/reset to succeed before it deletes chat messages, so a failed reset cannot silently remove chat history and leave stale UI behind. Added the #2887 changelog note.\n\nValidation: pnpm --filter @marinara-engine/client lint

<!-- gh-comment-id:4825521204 --> @SpicyMarinara commented on GitHub (Jun 28, 2026): Fixed in the local staging branch: Professor Mari home-chat restart now requires /professor-mari/workspace/reset to succeed before it deletes chat messages, so a failed reset cannot silently remove chat history and leave stale UI behind. Added the #2887 changelog note.\n\nValidation: pnpm --filter @marinara-engine/client lint
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#1468
No description provided.