diff --git a/internal/gateway/methods/chat.go b/internal/gateway/methods/chat.go index 6cda9c1d..7c0bab22 100644 --- a/internal/gateway/methods/chat.go +++ b/internal/gateway/methods/chat.go @@ -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) }