fix(chat): cancel orphaned generation on client disconnect

Closing the QuickChat browser tab mid-response left the backend agent
running with no listener. The `activeGenerations` slot persisted and the
next message's freshly-opened CLI SessionManager raced against the
lingering agent on the same session file, so the model produced no
output for the new prompt.

- POST /chat/sessions/:id/messages now calls cancelGeneration on
  req.on("close") if the response hasn't ended yet, so disconnects stop
  the agent promptly.
- beginGeneration only aborts the prior controller; it no longer
  disposes the prior agent. Disposing pre-emptively could yank the CLI
  process out from under the new generation's session opened on the
  same file.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-05-05 09:04:14 -07:00
parent 41375736e7
commit b85743db84
3 changed files with 23 additions and 7 deletions

View File

@@ -0,0 +1,5 @@
---
"@runfusion/fusion": patch
---
Fix Quick Chat: messages would silently fail after closing the browser tab mid-response and reopening it. The backend agent kept running with no listener and left a stale `activeGenerations` slot; the next message's freshly-opened CLI session then raced against the lingering agent on the same session file. The `/messages` route now calls `chatManager.cancelGeneration` when the client disconnects before the response ended, and `beginGeneration` only aborts the previous generation's controller instead of pre-emptively disposing its agent (the previous agent's own `finally` handles dispose, so we don't tear down the CLI process under the new agent).