mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2740] [Issue]: Client disconnect not propagated to upstream LLM in game-mode & embedding paths — zombie generations burn tokens until internal timeout #1380
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#1380
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/2740
Originally assigned to: @SpicyMarinara on GitHub.
Summary
The game-mode text-generation routes are buffered JSON endpoints whose options never carry a disconnect-aware
AbortSignal, sorunGameChatCompletecan only abort on its internalGAME_GENERATION_TIMEOUT_MS(4 min; up to ~8 min for scene-wrap's streamed retry). The codebase already has the correct helper —createResponseAbortSignal(reply, timeoutMs, label)wiresreply.raw.on('close')->controller.abort— but it is used by exactly one site (/generate-assets). Separately,BaseLLMProvider.embed()has nosignalparameter, so a Stop/disconnect during pre-generation memory-recall embedding cannot cancel the in-flight embeddings request (up to a 5-min embedding timeout). All of these are token/cost/connection leaks: the user navigates away and the expensive upstream call keeps running.Sub-bug 1: /game/setup world-gen is a zombie on disconnect (HIGH, leak)
/setupbuildssetupOptions = gameGenOptions(...)with nosignal(gameGenOptionsonly forwardsoverrides.signal, never passed), so insiderunGameChatCompleteparentSignal = options.signalis undefined and only the 4-min timer can abort. Noreply.raw.on('close')listener exists in the handler. WithbodyTimeout:0on the agent, transport won't cancel either. On bad-JSON retry the run repeats for another 4 min.game.routes.ts:3627(handler),3841-3862(setupOptions, no signal),3879(call),1738(parentSignalundefined),1748(timeout),1802-1830(unusedcreateResponseAbortSignal),7812(only usage).Sub-bug 2: Other game LLM routes share the gap (HIGH, leak)
runGameChatComplete/runGameChatStreamcall site builds options without a reply-bound signal and registers no close listener. The provider layer honors a signal end-to-end, so wiring one would propagate the abort.4287/4491/5014/5290/5608/5970/6726/7054;7045-7053/7065(scene-wrap has a second full streamed run on empty content).Sub-bug 3: embed() cannot be aborted (LOW, leak)
embed(texts, model)has nosignal; the only abort wired into its fetch isAbortSignal.timeout(timeoutMs). TheMemoryRecallEmbeddingSource.embedinterface and all call sites omit a signal, so the generation'sabortController.signalnever reaches the embeddings request. On Stop/disconnect the embedding request runs until its own (default 5-min) timeout.base-provider.ts:634(signature),648(only timeout signal); interfacememory-recall.ts:64; callsmemory-recall-embedding.ts:83/127,memory-recall.ts:77.Suggested Fix
const signal = createResponseAbortSignal(reply, GAME_GENERATION_TIMEOUT_MS, label)and thread it into the options ({ ...overrides, signal }) sorunGameChatComplete'sparentSignalaborts onreply.raw'close' (this also folds in the existing timeout, matching/generate-assets).signal?: AbortSignaltoembed()and toMemoryRecallEmbeddingSource.embed, combine it with the timeout viaAbortSignal.any([AbortSignal.timeout(timeoutMs), callerSignal]), and thread the generation'sabortController.signalfrom the call sites.Root-cause throughline
Disconnect propagation was implemented once (
createResponseAbortSignalfor/generate-assets) but never applied to the buffered game text routes or the embedding path, so the generation's abort signal stops at the route boundary and every abandoned setup/conclude/scene/recall keeps an upstream LLM or embeddings request running to its internal timeout.Verification checklist (leave all UNCHECKED)
pnpm checkAffected files
packages/server/src/routes/game.routes.tspackages/server/src/services/llm/base-provider.tspackages/server/src/services/conversation/memory-recall.tspackages/server/src/services/conversation/memory-recall-embedding.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. Game text-generation routes now thread a reply-bound abort signal into setup, session recap/conclusion/regeneration/progression, party recruit, map generation, party turn, scene-wrap (including streamed retry), and direct lorebook-keeper regeneration. Memory-recall and semantic lorebook embedding calls now accept an optional AbortSignal and generation-time calls pass the active generation abort controller through to configured/local embedding providers. Deferred full pnpm validation until the end of the issue sweep, per maintainer request.