mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2688] [Issue]: Agent error/abort/timeout gaps — error path leaks in-flight agent calls; no per-agent timeout can hang the turn #1334
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#1334
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 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2688
Originally assigned to: @SpicyMarinara on GitHub.
Summary
Two agent resource-handling gaps can leak or hang the generation turn: (1) when the main generation throws after parallel agents were launched, the route never calls
abortController.abort(), so detached in-flight agent LLM streams keep running and charging tokens; (2) agent provider calls have no per-call timeout, so a stalled mid-stream agent response (first byte received, then hangs) can block the whole turn indefinitely.Expected behavior
Actual behavior
(1) Phase-2 parallel agents are launched fire-and-forget and awaited later. The whole turn runs inside a
try; itscatchsends an SSE error and thefinallycallsreleaseActiveGeneration()andreply.raw.end()but never callsabortController.abort().agentContext.signalisabortController.signal, so the only way to cancel in-flight agent streams is to abort that controller. The/abortroute and the client-disconnect (onClose) path do callabort(); the thrown-error teardown path is the gap. Because the agent phase usesPromise.allSettledit never rejects, so this is a silent token/resource leak rather than a crash.(2) Agent provider calls pass no per-call timeout. The shared undici agent sets a 5-minute headers timeout (time-to-first-byte) but
bodyTimeout:0(no body timeout). Once an agent stream starts, no timeout fires if it stalls mid-body; agents rely entirely oncontext.signal, which is only aborted on explicit/abortor active-mode disconnect.How it breaks the pipeline
Code trace (staging @
b826f8f4):packages/server/src/routes/generate.routes.ts— parallel agents launched fire-and-forget (:6599), awaited later (:6767); turntryat:1306;catchat~:10328andfinallyat~:10336-10344callreleaseActiveGeneration()/reply.raw.end()but notabortController.abort().agentContext.signal = abortController.signal(:4092).abort()is called inonClose(:1286) and the/abortroute (~:10367).chatCompletecalls pass only{ model, temperature, maxTokens, stream, signal }(agent-executor.ts:333-344,:467-474,:696-707); shared undicibodyTimeout:0(base-provider.ts). A hung post-processing agent blocks the await atgenerate.routes.ts:~7050and holds the generation lock; a hung parallel agent blocks the await at~:6767.Steps to reproduce
bodyTimeoutis 0, and there's no agent-level timeout, so the agentchatCompletenever resolves and the turn cannot complete.Suggested fix
finally(orcatch), callabortController.abort()beforereleaseActiveGeneration()so detached parallel/post agent calls are cancelled on error — mirroring theabort()already done inonCloseand/abort.AbortSignal.timeout(...)combined withcontext.signalviaAbortSignal.any([...])) so a single stalled agent can't stall the whole turn.Environment
b826f8f4)Additional context
Found via a systematic multi-agent audit of the agent subsystem. (1) is a silent token/resource leak on the error path; (2) is an unbounded-hang risk. Part of a set of agent-pipeline issues filed together.
Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:
@SpicyMarinara commented on GitHub (Jun 21, 2026):
Fixed in branch
codex/spicy-issue-sweep-2026-06-21.What changed:
Final repo checks will run after the full issue sweep.