Merge pull request #48: improve upstream diagnostics

This commit is contained in:
Jason Xu committed 2026-10-07 19:34:34 +08:00
commit baa9a615c5
2 files changed
+11

No files matched your search

+1
View File
@@ -401,6 +401,7 @@ func (g *Gateway) prepareRouteBodies(from wire.Protocol, route models.Route, inp
// preferred tier. Do not reject a request before the preferred
// upstream has even been tried; that tier is attempted only if
// the request actually falls back.
g.logger.Debug("skipping fallback tier with incompatible request shape", "component", "conversion", "event", "fallback_tier_skipped", "model", jsonutil.StringAt(input, "model"), "tier", tier, "protocol", protocol, "error", err)
continue
}
return nil, fmt.Errorf("prepare %s upstream request: %w", tier, err)
+10
View File
@@ -74,6 +74,16 @@ func (g *Gateway) doUpstream(ctx context.Context, route models.Route, bodies map
// Restore the body so downstream error handling still sees the original
// payload when no retry happens below.
resp.Body = io.NopCloser(bytes.NewReader(errBody))
// Log a capped snippet of the upstream error body so the 400 class is
// visible without dumping full payloads. Bodies stay out of attempt
// records; the hub redactor scrubs configured secrets from log output.
if len(errBody) > 0 {
snippet := string(errBody)
if len(snippet) > 240 {
snippet = snippet[:240]
}
g.logger.Info("upstream error returned or retried", "component", "upstream", "event", "upstream_error_body", "request_id", ids.Request, "model", route.ID, "status", resp.StatusCode, "snippet", snippet)
}
if !isStaleReasoningReference(errBody) {
return resp, effectiveRoute, nil
}