mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1426
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 22, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2804
Originally assigned to: @SpicyMarinara on GitHub.
Summary
In Game Mode, when the Game Setup Wizard is shown for an existing campaign, clicking Cancel (or back) on the wizard performs an unconfirmed
deleteChat.mutate(activeChatId)that TRUE-hard-deletes the entire campaign — chat row plus allgameStateSnapshots,gameCheckpoints,agentRuns,agentMemory,chatImages, and the on-disk gallery directory. There is no soft-delete or trash, so the campaign is irrecoverable from the app.The wizard is shown whenever
needsCreation || sessionStatus === "setup"is true (GameSurface.tsx:7968), and the same condition gates the delete on Cancel (GameSurface.tsx:8010). The user perceives this as their game "resetting to the setup screen," then "Cancel" silently destroys the campaign instead of just dismissing the wizard.This issue is filed for the residual trap that survives the v2.0.1 hotfix PR #2790. #2790 fixes the specific client-cache corruption (#2801) that armed this trap via the Spotify-agent-removal path, but it does not touch the Cancel handler, so the unconfirmed auto-delete remains armed for every other path that can yield
chatMeta.gameId === undefinedorgameSessionStatus === "setup".Symptom & DATA-LOSS impact
Steps to reproduce
Two independent armings of the same trap:
A. Stale/absent gameId path (the #2801 family — fixed by #2790, but other cache-staleness paths remain):
6b22be3b), open a Game Mode campaign that hasgameIdin metadata (e.g. a 1.6.x-origin campaign carried into 2.0.0).updateMeta.mutateAsync({ activeAgentIds }),ChatSettingsDrawer.tsx:1888,1924).useChatdetail-cachestaleTime, the surface flips to the Game Setup Wizard because the optimistic metadata merge droppedgameId.B.
sessionStatus === "setup"path (fully independent of #2801 and #2790):gameIdAND persisted game state whose metadata leftgameSessionStatus === "setup"(e.g. a prior setup that failed/was interrupted,GameSurface.tsx:6918defaults to that value).sessionStatus === "setup",GameSurface.tsx:7968) even thoughneedsCreationis false.needsCreation || sessionStatus === "setup"is true → unconfirmed hard delete of a campaign that has a real game and state.To verify the trap in isolation: force
chatMeta.gameIdundefined orgameSessionStatus === "setup"while a real game exists, render the wizard, and click Cancel.Root cause (file:line — TRUE delete, not orphan)
packages/client/src/components/game/GameSurface.tsx:7952—const needsCreation = !chatMeta.gameId;(negative signal: any absence ofgameIdis treated as "this is a brand-new game to create").GameSurface.tsx:6918—sessionStatus = chatMeta.gameSessionStatus || "active".GameSurface.tsx:7968— wizard renders whenisSetupActive || needsCreation || sessionStatus === "setup".GameSurface.tsx:8009-8016—onCancelruns, whenneedsCreation || sessionStatus === "setup",useChatStore.getState().setActiveChatId(null); deleteChat.mutate(activeChatId);with no confirmation dialog and no emptiness/just-created check.chatMetaisparseChatMetadata(chat.metadata)from theuseChatcache (ChatArea.tsx:639-643, fed as a prop).parseChatMetadata(chat-display.ts:10-21) returns a non-array object as-is, so a corrupted/object-shaped or partial metadata yieldsgameId === undefined.useDeleteChat(use-chats.ts:374-420) →DELETE /chats/:id(chats.routes.ts:949-970) →storage.remove(chats.storage.ts:506-518) cascadesagentRuns/agentMemory/gameCheckpoints/gameStateSnapshots/chatImages,rmSyncs the gallery dir, and deletes the chat row. No soft-delete. This is a genuine irrecoverable hard delete, not an orphan.How
chatMeta.gameIdgoes undefined in the released #2801 path (for context):metadatais stored as a JSON string (schema/chats.ts:29text("metadata"), not json mode;getById/listdo raw selects with no parse).useUpdateChatMetadata.onMutate(use-chats.ts:510-518) doesmetadata: { ...existing.metadata, ...metadata }, spreading a string into numeric-indexed keys and droppinggameId;onSuccess(use-chats.ts:536){ ...data.metadata, ...existing.metadata }re-overlays the corrupted object and does not heal;useChatstaleTime60s keeps the corrupt cache live. The server never receives corrupted metadata — PATCH (chats.routes.ts:535-570) →patchMetadata(chats.storage.ts:388-410) merges only sent keys onto fresh DB metadata — which is why a refresh before Cancel heals it.Relationship to #2801 and #2790
gameId, makingneedsCreationtrue.useUpdateChatMetadatainuse-chats.ts, addingnormalizeChatMetadataValue()which JSON-parses a string base before merging, plusmergeMetadataForVersion()/syncCachedChat().onMutatenow builds metadata from the parsed base + new keys;onSuccess/onErroruse the version-aware merge. This removes the string-spread that droppedgameId, so the #2801 corruption no longer occurs and the specific Spotify-agent-removal repro (path A) should stop reproducing. (#2790 also adds a defensiveparseExtrain the DELETE route and cosmetic create/delete error toasts.) Verified at PR diff: use-chats.ts rewrite hunks addnormalizeChatMetadataValue(~PR L5391+), onMutate/onSuccess/onError rewritten (~PR L5598+).GameSurface.tsxhunks contain zero changes toonCancel/needsCreation/deleteChat(verified: the only match in those hunks is a cosmeticsessionStatusline). The DELETE route still callsstorage.removeunconditionally, andchats.storage.ts remove()(L506-518) is untouched (the PR's chats.storage.ts hunks are at L63/L390/L426 only). So:gameId/sessionStatus-gated auto-delete-on-Cancel remains armed.gameIdcan be transiently/legitimately absent for reasons besides #2801: a stale or legacy list-cache row, an in-flight create beforegameIdpersists, any future merge regression, or any path that yieldschatMetawithoutgameId.sessionStatus === "setup"arming (path B) is entirely independent of #2801/#2790 and is not addressed at all.Suggested fix
Defense-in-depth on the delete trap (independent of the cache fix):
GameSurface.tsx:8009-8016), especially when the chat has messages or persisted game state. Cancel should default to just dismissing the wizard, not deleting.gameStateSnapshotsAND a created-in-session flag — instead of the negative!chatMeta.gameId. Never auto-delete whensessionStatus === "setup"but a realgameId/state exists.gameIdfrom a trusted source (refetched server chat, orparseChatMetadataof the raw metadata string) before computingneedsCreation, so a stale/corrupt cache can't drive a destructive decision.storage.remove(chats.storage.ts:506-518) a soft-delete/trash with recovery, OR refuse to hard-delete a game chat that has messages orgameStateSnapshotswithout an explicitforceflag.User mitigation until fixed (2.0.1+): if a campaign flips to the setup wizard after an agent or settings change, refresh the page immediately and do NOT click Cancel — refreshing heals the cache. Avoid removing agents from existing campaigns until on 2.0.1+.
Recovery note: where deletion already occurred, it is a TRUE hard delete (chat row +
gameStateSnapshots+gameCheckpoints+chatImages+ gallery files) and is recoverable ONLY from a filesystem/SQLite backup taken before the deletion — not from within the app.Affected files
packages/client/src/components/game/GameSurface.tsx(onCancel/needsCreation/sessionStatus — the trap)packages/client/src/hooks/use-chats.ts(useUpdateChatMetadata corruption — #2790 fixes the corruption but not the trap; useDeleteChat)packages/client/src/components/chat/ChatArea.tsx(chatMeta prop source)packages/client/src/lib/chat-display.ts(parseChatMetadata returns object as-is)packages/client/src/components/chat/ChatSettingsDrawer.tsx(agent-toggle trigger)packages/server/src/routes/chats.routes.ts(DELETE route)packages/server/src/services/storage/chats.storage.ts(remove() hard-delete cascade — soft-delete candidate)Validation checklist
6b22be3b): remove Spotify agent from a campaign withgameId, observe wizard flip within 60s, confirm Cancel hard-deletes the campaign.gameSessionStatus === "setup"on a campaign with a validgameIdand state, render the wizard, click Cancel, confirm the campaign is still hard-deleted with no confirmation.chatMeta.gameIdforced undefined (non-#2801 cache-staleness simulation): wizard Cancel deletes.storage.removeeither soft-deletes/recovers or refuses to hard-delete a game chat with messages/gameStateSnapshotswithoutforce.useUpdateChatMetadata(#2790) gameId-preservation across agent toggles and metadata edits.AI-investigated note
This issue was investigated and root-caused by an AI agent reading the released 2.0.0 code at tip
6b22be3b(verified still present at HEADecc32dbe; #2790 is NOT merged) and the open #2790 diff (gh pr diff 2790 --repo Pasta-Devs/Marinara-Engine). All file:line citations were verified against the actual source (accurate within ~1–2 lines). Mechanism: a TRUE user-triggered server-side hard delete via an unconfirmedgameId/sessionStatus-gated auto-delete on the Game Setup Wizard's Cancel handler. #2790 removes the #2801 cache corruption that arms this on the Spotify-agent path but leaves the delete trap itself armed. Maintainers should confirm the suggested fix before merge.@SpicyMarinara commented on GitHub (Jun 22, 2026):
Claiming this for a focused fix. I’ll patch the Game Setup Wizard cancel path so it cannot silently hard-delete existing campaigns, validate the repro path against current staging, and open a draft PR back to staging.