flipped-aurora/gin-vue-admin · error
调用上游大模型流式服务失败: %w
Error message
调用上游大模型流式服务失败: %w
What it means
This error is wrapped and returned by LLMAutoStream in server/service/system/auto_code_llm.go when the HTTP request to the upstream LLM streaming (SSE) service fails. It wraps the underlying transport error with %w, so the root cause (DNS failure, TLS handshake, connection refused/reset, context cancellation/deadline) is preserved in the chain. Note client.Timeout is intentionally unset (-1); the stream lifecycle is governed by the passed ctx, so context deadlines and cancellations surface here.
Source
Thrown at server/service/system/auto_code_llm.go:86
if responseMode == "" {
payload["response_mode"] = "streaming"
}
res, err := request.HttpRequestWithContextAndTimeout(
ctx,
path,
http.MethodPost,
map[string]string{
"Accept": "text/event-stream",
"Accept-Encoding": "identity", // 禁止 gzip,避免 SSE 流被压缩导致缓冲卡住
"Cache-Control": "no-cache",
},
nil,
payload,
-1, // 不设置 client.Timeout,SSE 流的生命周期由 ctx 控制
)
if err != nil {
return nil, fmt.Errorf("调用上游大模型流式服务失败: %w", err)
}
return res, nil
}
func buildLLMAutoPath(llm common.JSONMap) (string, error) {
if global.GVA_CONFIG.AutoCode.AiPath == "" {
return "", errors.New("请先前往插件市场个人中心获取 AiPath 并填写到 config.yaml 中")
}
mode := strings.TrimSpace(fmt.Sprintf("%v", llm["mode"]))
if mode == "" {
return "", errors.New("llmAuto 缺少 mode 参数")
}
return strings.ReplaceAll(global.GVA_CONFIG.AutoCode.AiPath, "{FUNC}", mode), nil
}
func cloneLLMAutoJSONMap(src common.JSONMap) common.JSONMap {View on GitHub (pinned to 3136500ef3)
Solutions
- Unwrap the returned error (errors.Unwrap / %v) to identify the exact transport cause (connection refused, DNS, TLS, context deadline).
- Verify global.GVA_CONFIG.AutoCode base URL/AiPath points to the correct upstream LLM streaming endpoint and curl it from the server host.
- Check server egress: proxy env vars (HTTP_PROXY/HTTPS_PROXY), firewall rules, DNS resolution for the upstream host.
- If the cause is context deadline exceeded, extend the ctx timeout passed into LLMAutoStream or investigate the early cancellation.
- If the provider endpoint changed or is down, update the endpoint config or retry with backoff.
Example fix
// before
res, err := svc.LLMAutoStream(ctx, payload)
if err != nil {
return err // opaque failure
}
// after
res, err := svc.LLMAutoStream(ctx, payload)
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
return fmt.Errorf("LLM stream timed out, retry or extend deadline: %w", err)
}
return fmt.Errorf("LLM auto stream failed: %w", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
import (
"net/http"
"time"
)
func upstreamReachable(baseURL string) error {
client := &http.Client{Timeout: 5 * time.Second}
resp, err := client.Get(baseURL)
if err != nil {
return fmt.Errorf("LLM upstream unreachable: %w", err)
}
defer resp.Body.Close()
return nil
} Try / catch
res, err := svc.LLMAutoStream(ctx, payload)
if err != nil {
switch {
case errors.Is(err, context.Canceled):
return nil, fmt.Errorf("LLM stream cancelled by caller")
case errors.Is(err, context.DeadlineExceeded):
return nil, fmt.Errorf("LLM stream timed out; extend deadline or retry")
default:
return nil, fmt.Errorf("LLM stream transport failure: %w", err)
}
} Prevention
- Health-check the LLM endpoint at startup or via readiness probe before enabling AI codegen features.
- Keep AutoCode base URL/AiPath in per-environment config and validate on boot.
- Set explicit ctx deadlines with headroom for slow LLM first-token latency.
- Always log the full wrapped error chain to distinguish DNS/TLS/timeout causes.
- Implement retry with backoff and a degraded user-facing mode for provider outages.
When it happens
Trigger: Calling LLMAutoStream when the upstream LLM endpoint (base URL / AiPath from global.GVA_CONFIG.AutoCode) is unreachable or misconfigured, DNS resolution fails, TLS handshake fails, the connection is refused or reset during the request, or the ctx passed to LLMAutoStream is cancelled or exceeds its deadline before the HTTP call completes.
Common situations: Dev/staging environments without egress access to the LLM provider; wrong AutoCode base URL/AiPath after migrating environments; corporate proxy or firewall blocking the request; upstream LLM provider outage or endpoint change; callers passing a too-short ctx timeout; API provider switched without updating config.
Related errors
- 上游大模型流式服务返回非 2xx: status=%d content-type=%s read-body-err=%w
- LLM request failed
- LLM stream request timed out
- result.Msg
- 上游大模型流式服务返回非 2xx: status=%d content-type=%s read-body-err=%w
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/1044484370af72db.
Report an issue: GitHub.