mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2614] [Issue]: /retry-agents SSE route never aborts upstream agent LLM calls on client disconnect (leak) #1287
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#1287
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 @Romuromylus on GitHub (Jun 18, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2614
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: Medium — leak. The
/retry-agentsSSE route builds noAbortController, registers no client-disconnect listener, and threads no abort signal into the agent LLM calls. If the client disconnects mid-retry, every in-flight tracker/agent provider request continues to completion, burning tokens/time with no cancellation. It also emits SSE via the unguardedsendSseEvent, which can throw on a destroyed socket.Expected behavior
Mirror the main
POST /api/generatehandler: on client disconnect, abort the upstream provider calls and stop writing to the closed socket.Actual behavior
The retry handler starts SSE and runs agent batches with no abort wiring:
Abort is plumbed exclusively via
context.signal→provider.chatComplete({ signal })(agent-executor.ts:343,473,552,706;base-provider.ts:114). Because the retry route leavescontext.signalundefined, every retried agent LLM call runs to upstream completion after a disconnect;executeRetryBatchesruns job groups in parallel (Promise.allSettled), so multiple in-flight requests leak at once. By contrastgenerate.routes.tsbuildsabortController(~812), monkey-patchesreply.raw.writeto no-op after disconnect (~979-987), registersonClose -> abortController.abort()(~989-1007), threadssignalinto its agent context and provider calls, andoff()s the listener in finally. The retry route also uses the unguardedsendSseEvent(sse.ts:14-16, a barereply.raw.writewith no try/catch) for all post-start events, whiletrySendSseEvent(sse.ts:18-24) exists precisely to swallow writes-after-disconnect.Steps to reproduce
Environment
staging @ 56f700cd(v2.0.0)Logs, screenshots, or video
Static source audit, cited to file:line above.
Additional context
Fix sketch. Mirror the main generate route: create
const abortController = new AbortController(), registerreply.raw.on("close", () => abortController.abort()), setagentContext.signal = abortController.signal(and on any pre-generation agent context), switch the post-startsendSseEventcalls totrySendSseEvent(or guardreply.raw.write), andoff()the listener infinally. The reference implementation is the in-repogenerate.routes.tsabort wiring.Regression notes. Not a regression —
main'sretry-agents-route.tshas the same shape (no AbortController/close-listener/context.signal/trySendSseEvent). The retry route never had abort wiring; staging neither broke nor dropped it.Template check
@Romuromylus commented on GitHub (Jun 18, 2026):
Fixed in #2623, merged to
staging(e1132e5b). Closing manually since the PR targetedstagingrather than the default branch.