mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2741] [Issue]: Stop/abort cannot cancel background, autonomous & retry-agent generations; regenerate-during-stream silently rejected #1382
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#1382
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 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2741
Originally assigned to: @SpicyMarinara on GitHub.
Summary
The client's cancellation surface only reaches the currently-active, foreground chat.
stopGenerationkeys solely on the global single-valuedstreamingChatId, so a generation running for a background chat (started, then navigated away) or an autonomous/scheduled send cannot be cancelled — the upstream LLM, agents, and persistence run to completion as a zombie (conversation mode does not abort on passive disconnect). The/retry-agentsflow creates anAbortControllerbut never calls.abort()and never stores it where the stop button can reach it.chatStore.reset()replaces the controller map without aborting in-flight controllers. The same-chat regenerate/swipe path has deadprev.abort()code that never runs because the concurrency guard already returned. Separately, the autonomous scheduler dispatchesvoid evaluateChat(chat)with no concurrency limit.Sub-bug 1: stopGeneration can't cancel background/autonomous gens (HIGH, abort-failure)
stopGenerationreadsstreamingChatId(set only whenisActiveChat()is true) and abortsabortControllers.get(streamingChatId)+ POSTs{chatId: streamingChatId}. A background chat's controller is in the map butstreamingChatIdis the active/other chat, so it's never aborted; the autonomous variant registers no controller and passes no signal at all, so it's wholly unstoppable. Conversation-mode passive disconnect intentionally does not abort, so the work continues.chat.store.ts:346-359;use-generate.ts:939(registers controller) vs956-957(setStreaming gated by isActiveChat); autonomoususe-background-autonomous.ts:168(no signal). Servergenerate-route-utils.ts:195-197(conversation passive disconnect = no abort).Sub-bug 2: /retry-agents has no user cancel (LOW, other)
retryAgentscreatesnew AbortController()and passes its signal tostreamEvents, but.abort()is never called and the controller is not stored in a ref/store; the catch handles AbortError but nothing produces it. Only tab close (serverreply.raw 'close') halts it.use-generate.ts:2444/2469-2483/2724-2745; server abort only on socket closeretry-agents-route.ts:2896-2900.Sub-bug 3: reset() drops controllers without aborting (LOW, leak)
reset()reassignsabortControllers: new Map()without iterating to.abort(). The live generation keeps its own controller, the fetch isn't cancelled, and itsfinally(stillOwnernow false) writes into a reset/cleared cache. Only trigger is the destructive expunge/clear-all path.chat.store.ts:639-669(reset),346-359(stopGeneration only active chat); finallyuse-generate.ts:2294.Sub-bug 4: dead same-chat 'abort previous' code (LOW, other)
generate()returns false whenabortControllers.has(chatId), soconst prev = abortControllers.get(chatId)is always undefined andif (prev) prev.abort()is unreachable. Same-chat regenerate/swipe during a stream is silently dropped (console.warn only), despite the comment claiming it aborts-and-replaces. Intentional concurrency protection, but misleading dead code.use-generate.ts:926-934.Sub-bug 5: autonomous scheduler unbounded fan-out (LOW, leak)
poll()doesvoid evaluateChat(chat)for every eligible chat with no semaphore; eachevaluateChatmayapp.injecta full/api/generate(buffered into memory). N eligible chats => N concurrent real generations, risking provider rate limits/429s/memory. Heavily gated by per-chat cooldowns, so blast radius is workload-dependent.server-autonomous-scheduler.service.ts:275-291(poll,283void dispatch),123-137(app.inject /api/generate).Suggested Fix
stopGenerationcancel the chat the user intends: pass an explicitchatIdfrom the stop button (or abortabortControllers.get(activeChatId)as well) and POST that chatId to/abort; for a global stop, iterateabortControllersand abort each./retry-agentsa stored controller (ref or store keyed by chatId) wired to the stop control; the server already aborts on socket close, so.abort()will propagate.reset(),for (const c of state.abortControllers.values()) c.abort();before replacing the map.933-934lines and document same-chat rejection, OR relax the guard to abort+supersede the prior controller.Root-cause throughline
Cancellation was modeled around a single active foreground stream (
streamingChatId), but the app actually runs generations for background chats, autonomous sends, and retry-agent batches concurrently — none of which are reachable from that single-valued state — so the stop button and store reset silently miss them, leaving zombie upstream work that conversation-mode passive-disconnect was deliberately designed not to cancel.Verification checklist (leave all UNCHECKED)
pnpm checkAffected files
packages/client/src/stores/chat.store.tspackages/client/src/hooks/use-generate.tspackages/client/src/hooks/use-background-autonomous.tspackages/server/src/routes/generate/retry-agents-route.tspackages/server/src/services/conversation/server-autonomous-scheduler.service.tsAudit provenance
Found by a multi-agent static audit of the streaming/SSE subsystem (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified) against the merged
stagingtree. Severity: HIGH.@SpicyMarinara commented on GitHub (Jun 21, 2026):
Addressed on PR #2747. stopGeneration now accepts an explicit chatId, falls back through active/current/all tracked controllers, and reset aborts every tracked generation before clearing state. Retry-agent streams and background autonomous client streams now register AbortControllers in the shared per-chat map and pass their signals to streamEvents. The dead same-chat abort branch was removed after the existing concurrency guard, and the server autonomous scheduler now caps concurrent evaluations. Deferred full pnpm validation until the end of the issue sweep, per maintainer request.