fix(ws): detach agent runs from HTTP request context

Agent runs were tied to the HTTP request context, so navigating away
cancelled the LLM stream. Now uses context.WithoutCancel() to survive
page navigation while preserving explicit chat.abort support.
This commit is contained in:
viettranx committed 2026-03-19 19:01:19 +07:00
1 parent 78ffc57a8e
commit b1b7bfbe69
1 file changed
+5 -2
+5 -2
View File
@@ -122,8 +122,11 @@ func (m *ChatMethods) handleSend(ctx context.Context, client *gateway.Client, re
sessionKey = sessions.SessionKey(params.AgentID, "ws-"+client.ID())
}
// Inject user_id into context for downstream stores/tools
runCtxBase := ctx
// Detach from HTTP request context so agent runs survive page navigation/reconnect.
// WithoutCancel preserves all context values (locale, user ID, etc.)
// but HTTP request cancellation no longer propagates.
// Explicit abort via chat.abort still works through the per-run cancel().
runCtxBase := context.WithoutCancel(ctx)
if userID != "" {
runCtxBase = store.WithUserID(runCtxBase, userID)
}