fix(api): reject /agent-chat early when agent_id is missing
AgentQA used to trust request.AgentEnabled even when resolveAgent() returned nil (no agent_id, or unresolvable id) — the request reached the async goroutine, AgentQA service errored with 'custom agent configuration is required', and the user saw a broken SSE stream with no actionable error. Most likely root cause is a stale frontend settings store where isAgentEnabled stayed true after selectedAgentId got blanked (typically a cross-tenant switch where the previously selected agent isn't visible in the new tenant). The frontend fix lives in selectAgent() syncing both flags, but the handler shouldn't trust that contract. Add an early 400 with a clear message before executeQA dispatches. Logs the actual request.AgentID (sanitized) so future stuck-state reports are diagnosable from a single log line.
This commit is contained in:
@@ -529,6 +529,25 @@ func (h *Handler) AgentQA(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// Sanity gate: agent mode requires a resolved CustomAgent. If we got
|
||||
// here with agent_enabled=true but agent_id missing/unresolvable, the
|
||||
// AgentQA service will fail deep inside the async goroutine with a
|
||||
// generic "custom agent configuration is required" error and the user
|
||||
// just sees a broken stream. Reject early with a clear 400 so the
|
||||
// frontend can recover (e.g. fall back to quick-answer). Most likely
|
||||
// cause is a stale localStorage settings blob where selectedAgentId
|
||||
// got blanked but isAgentEnabled stayed true — usually after a
|
||||
// cross-tenant switch where the previously selected agent is no
|
||||
// longer visible.
|
||||
if agentModeEnabled && reqCtx.customAgent == nil {
|
||||
logger.Warnf(reqCtx.ctx,
|
||||
"Agent mode requested without a resolvable agent_id, rejecting; session=%s, request.AgentID=%q",
|
||||
reqCtx.sessionID, secutils.SanitizeForLog(request.AgentID))
|
||||
c.Error(errors.NewBadRequestError(
|
||||
"agent_id is required when agent mode is enabled"))
|
||||
return
|
||||
}
|
||||
|
||||
// Route to appropriate handler based on agent mode
|
||||
if agentModeEnabled {
|
||||
h.executeQA(reqCtx, qaModeAgent, true)
|
||||
|
||||
Reference in New Issue
Block a user