mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #53] [MERGED] fix: abort backend generation when user clicks Stop #4423
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#4423
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?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/53
Author: @LukaTheHero
Created: 4/3/2026
Status: ✅ Merged
Merged: 4/3/2026
Merged by: @SpicyMarinara
Base:
main← Head:fix/abort-signal-propagation📝 Commits (1)
4acfde0fix: abort backend generation when user clicks Stop📊 Changes
5 files changed (+109 additions, -2 deletions)
View changed files
📝
packages/client/src/stores/chat.store.ts(+7 -0)📝
packages/server/src/routes/generate.routes.ts(+63 -1)📝
packages/server/src/services/llm/providers/anthropic.provider.ts(+10 -0)📝
packages/server/src/services/llm/providers/google.provider.ts(+10 -0)📝
packages/server/src/services/llm/providers/openai.provider.ts(+19 -1)📄 Description
Fixes a bug where clicking Stop in the UI would remove the reply from the chat but the backend (e.g. KoboldCPP) would continue generating tokens until completion, blocking the slot.
Problem
When a user stops generation:
req.raw.on("close")event doesn't reliably fire for SSE connectionsThis affects all local backends that don't automatically stop when the TCP connection drops. Cloud providers (OpenAI, Anthropic) also continued consuming tokens unnecessarily.
Solution
Explicit abort endpoint (
/api/generate/abort)POST /api/extra/abortto KoboldCPP-compatible backends to free the slotProvider-level reader cancellation
reader.cancel()on the active stream readerremoveEventListenerinfinallyblocks to prevent memory leaksFiles Changed
packages/client/src/stores/chat.store.ts—stopGeneration()now calls/api/generate/abortpackages/server/src/routes/generate.routes.ts— new/abortendpoint + active generation trackingpackages/server/src/services/llm/providers/openai.provider.ts— reader cancellation on abortpackages/server/src/services/llm/providers/anthropic.provider.ts— reader cancellation on abortpackages/server/src/services/llm/providers/google.provider.ts— reader cancellation on abortTesting
Tested with KoboldCPP — clicking Stop now immediately shows "Generation Aborted" in KoboldCPP's terminal and frees the slot for new requests.
Also tested other generations my fix didn't effect anything. but if something were to fail somehow Only potential edge case would be:
The /api/extra/abort call goes to whatever baseUrl the connection is configured with. For cloud providers like https://api.openai.com/v1, it would try to hit https://api.openai.com/api/extra/abort — which doesn't exist. But since the fetch has .catch(() => {}), it silently fails with a 404 and nothing happens. No impact.
Bottom line: The worst case for any provider is a single failed HTTP request that gets silently swallowed. Normal generation flow is completely untouched — these changes only activate when the user clicks Stop.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.