mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2791] [Issue]: New/Delete conversation intermittently fail silently + per-chat guard/lock leaks wedge a chat (refresh/restart fixes) — useCreateChat no onError, abortControllers + activeGenerations leak #1415
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#1415
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/2791
Summary
Three user-reported symptoms — (A) the New Conversation button intermittently does nothing, (B) delete conversation intermittently fails (the row reappears), and (C) some users see the engine "wedge" (cannot create convos / open characters / crashes-or-needs-refresh / device heat) — trace to multiple independent faults, not one whole-process crash.
onErrorhandling at all, and delete rolls back silently with no toast. When the underlying request 5xx's (or the chat is mid-generation server-side), the user gets a silent no-op or a row that vanishes-then-reappears with no feedback. A refresh "fixes" it because the next request succeeds.abortControllersguard leak that blocks all future generations for a chat until the page is reloaded (the Map is not persisted — this is the literal mechanism behind "refresh fixes it").activeGenerationslock leak that returns a permanent409 generation-already-in-progressfor one chat until the backend restarts.500on corrupt metadata, leaving stuck chats undeletable.The retry/heat is explained by the client retrying
useChatsup to 10× with backoff on 5xx (use-chats.ts:158-163) plus error-state churn — an aggravating factor, not a root cause.Symptom & UX impact
409); the chat may also be undeletable. Heavy retry traffic and re-renders cause CPU/battery ("device heat"). Refreshing the page clears the client-side guard (but not the server lock).Steps to reproduce
A (silent create failure):
POST /chatsreturn 5xx).B (silent delete rollback):
DELETE /chats/:idreturn 5xx (e.g. corruptmetadatasoJSON.parsethrows — see root cause).C-client (abortControllers guard leak):
finallycleanup body ofuseGenerate(e.g. a cache-write helper throwing) so execution never reaches the cleanup atuse-generate.ts:2341-2342.use-generate.ts:926) until a page reload (the Map atchat.store.ts:219is wiped on reload).C-server (activeGenerations 409 leak):
connections.getWithKey(orchats.listMessages/createMessage) throw during a send.409 "A generation is already in progress for this chat"on every subsequent send until the backend restarts.Root cause
A —
useCreateChathas noonError; call sites pass onlyonSuccesspackages/client/src/hooks/use-chats.ts:349-372—useCreateChat()defines onlyonSuccess. A failedPOST /chatsrejects with nothing surfaced. All call sites compound it:packages/client/src/components/LAYOUT/ChatSidebar.tsx:526(handleNewChat) —createChat.mutate(..., { onSuccess })only.ChatSidebar.tsx:1083-1093(the + buttonhandleNewChatFromTab→handleNewChat, and again at:1292) — nodisabled/pending/error state, so users can double-fire and never see failure.packages/client/src/hooks/use-start-chat-from-character.ts:31—createChat.mutate(..., { onSuccess })only. This is also why "opening a character does nothing" — it silently no-ops on any failure; no server crash is required for this symptom.B —
useDeleteChatrolls back silentlyuse-chats.ts:374-420—onMutateoptimistically removes the row (390-393);onError(398-411) restorescontext.previousbut emits no toast. The user sees a row reappear with no explanation.C-client — in-memory
abortControllersguard never reset on a throwing finallyuse-generate.ts:926skips a generation ifuseChatStore.getState().abortControllers.has(params.chatId).use-generate.ts:2342(setAbortController(params.chatId, null)) and:2341(clearPerChatState), which sit at the end of thefinallyblock (starts:2202).awaits refresh helpers before the cleanup:refreshVisibleGameStateAfterGeneration(:2215) andrefreshMessagesAuthoritatively(:2311,:2318,:2326). A synchronous throw from any cache-write step in that region skips cleanup → guard stays set.abortControllersis a plain in-memoryMap(packages/client/src/stores/chat.store.ts:219), not persisted, so a page reload empties it — which is exactly why "refresh fixes it."activeGenerateLocksSet (use-generate.ts:745), is correctly released in a tightfinallyat:937, so it is NOT the leak. The leak is specifically theabortControllersMap.C-server —
activeGenerationslock leaked by pre-trysetup awaitspackages/server/src/routes/generate.routes.ts::1242(activeGenerations.set(input.chatId, ...)).trythat guaranteesreleaseActiveGeneration()begins later (~:1466).try, several awaits run unprotected:chats.listMessages(:1277),chats.createMessage(:1287),connections.getWithKey(:1353and:1369). The handled early-returns do callreleaseActiveGeneration()(e.g.:1342,:1350,:1363,:1372), but a thrown error from any of these awaits is not caught by that path → the lock leaks → permanent409for that chat until restart.C-delete — DELETE route doesn't abort/cleanup and can 500 on bad metadata
packages/server/src/routes/chats.routes.ts:949-970:deletesactiveGenerations[id], never clears chat activity → a wedged chat (server lock held) stays wedged after a delete attempt.JSON.parseat:953and:959with no try/catch → corruptmetadatathrows → the route 500s → delete fails (feeds symptom B).Shared vs distinct
Not one shared root cause. A and B are client UX (missing
onError) plus, for the wedge, the clientabortControllersguard leak. C is a combination of independent per-chat faults: the serveractiveGenerations409 leak and the clientabortControllersguard leak. They should be fixed together but are independent bugs.What this is NOT (corrected from earlier investigation)
process.exit(1)on unhandled rejection is not the demonstrated cause. Fastify route-handler throws do not becomeunhandledRejection:app.tsregisterssetErrorHandler(errorHandler)which converts any handler throw into a 4xx/5xx HTTP response and never re-throws. So the generate route, agent pipeline, and SSE-write handlers cannot reachindex.ts:57→process.exit(1).poll/evaluateChat/scheduleDelayedGenerationhave try/catch/finally; sidecar bootstrap has.catch; childerror/exithandlers are internally try/caught), so none produces a floating rejection.use-autonomous-messaging.tsis the client poller and cannot crash the server.index.ts:52-61as defensive hardening only, not the fix.Suggested fix
Recommend splitting into two focused PRs (client UX vs server lock/delete) since these are independent faults.
PR 1 — Client UX (fixes A and B, plus the wedge guard leak)
useCreateChatonErrortoast (use-chats.ts:349):And add an
onErrorto each.mutate(...)call site (ChatSidebar.tsx:526,use-start-chat-from-character.ts:31) so the failure surfaces even with the local callback form.2. Disable the + button while pending (
ChatSidebar.tsx:1083and:1292):disabled={createChat.isPending}and a busy affordance, to stop silent double-fires.3.
useDeleteChatonErrortoast (use-chats.ts:398): keep the rollback, addshowError("Couldn't delete the conversation. It has been restored.").4. Harden the
useGeneratefinally (use-generate.ts:2202): guarantee the guard clears even if the refresh awaits throw. Cheapest fix — run the ownership cleanup in its own try/finally, or move it to the very top of the outer finally:(Guard the inner cleanup with the
stillOwnercheck as today so a superseded generation doesn't stomp the active one.)PR 2 — Server lock + delete (fixes the 409 wedge and undeletable chats)
trythrow (generate.routes.ts:1242-1466): either moveactiveGenerations.setinside the big protectivetry, or wrap the setup region from:1242through:1466so any throw callsreleaseActiveGeneration()in afinally/catch. Prefer moving thesetinto the try so registration and release share one scope.chats.routes.ts:949-970): beforestorage.remove, abort any in-flight generation,delete activeGenerations[id], and clear chat activity. Guard the metadata parse so corrupt JSON can't 500 the delete:Optional — defensive hardening (NOT the cure)
index.ts:57: prefer log-and-continue onunhandledRejectiononly; keep exit-or-graceful-restart on a trueuncaughtException(continuing after a real uncaught exception can leave corrupt state). Pair with ano-floating-promiseslint sweep rather than re-wrapping the already-guarded background paths.Affected files
packages/client/src/hooks/use-chats.ts(useCreateChat349-372;useDeleteChat374-420;useChatsretry 158-163)packages/client/src/hooks/use-generate.ts(guard 926; lock release 937; finally 2202-2342)packages/client/src/stores/chat.store.ts(in-memoryabortControllersMap, 219)packages/client/src/components/LAYOUT/ChatSidebar.tsx(create call site 526; + button 1083/1292)packages/client/src/hooks/use-start-chat-from-character.ts(create call site 31)packages/server/src/routes/generate.routes.ts(lock 1242; pre-try awaits 1277/1287/1353/1369; protective try ~1466)packages/server/src/routes/chats.routes.ts(DELETE 949-970; raw JSON.parse 953/959)packages/server/src/index.ts(process.exit handlers 52-61) — optional hardening onlyValidation
POST /chats, clicking New Conversation shows an error toast and the + button is disabled while pending.DELETE /chats/:idshows a toast and the restored row is explained.metadataset to invalid JSON can still be deleted (no 500).useGeneratefinally refresh path; confirm the chat can still generate afterward without a page reload.connections.getWithKey) throw; confirm the chat does NOT get stuck on409and a subsequent send succeeds.activeGenerationsentry.pnpm check(TypeScript + ESLint) clean.console.*added in server code; client toasts use the existing error helper.unhandledRejectionnow logs-and-continues while a trueuncaughtExceptionstill exits/graceful-restarts.AI-investigated against released 2.0.0; verify each trace and repro before fixing.
@kolacheee commented on GitHub (Jun 22, 2026):
Cross-reference: the separately-reported repeating
[memory-recall] Local embeddings are unavailable…log spam from the same "conversation bugs out" report is tracked in #2796 (a distinct, lower-severity fault). It is a correlated symptom, not the cause of the wedge described here.@SpicyMarinara commented on GitHub (Jun 22, 2026):
Addressed, but gonna let the Codex make sure double.
@SpicyMarinara commented on GitHub (Jun 22, 2026):
Addressed in PR #2790 / commit acab1fba: added create/delete failure feedback, guarded duplicate new-chat submits, released client/server generation locks on setup failures, aborted active generations on delete, and made delete metadata parsing safe.