Mask upstream errors from downstream users - #5444
Conversation
WalkthroughThis PR implements an upstream error masking policy that classifies provider errors as upstream, applies a downstream policy to mask them as HTTP 503 for external clients, sanitizes user-visible logs while preserving admin details, and systematically marks all relay provider errors across OpenAI, Claude, Gemini, and other handlers. ChangesUpstream Error Masking and Classification
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/upstream-error-503-logmask.md (1)
52-55: 💤 Low valueConsolidate repetitive sentence structure for better readability.
Three successive sentences in the file list all begin with "Adds", which reduces readability. Consider rephrasing to vary the sentence structure.
- `types/error.go` - Adds `upstreamError` marker on `NewAPIError`. - - Adds `ApplyDownstreamNewAPIErrorPolicy`. - - Adds `MarkAsUpstreamError` and `IsUpstreamError`. + - Defines `ApplyDownstreamNewAPIErrorPolicy`, `MarkAsUpstreamError`, and `IsUpstreamError` functions.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/upstream-error-503-logmask.md` around lines 52 - 55, The three consecutive bullet sentences that each begin with "Adds" are repetitive; update the description for `types/error.go` to vary sentence structure by combining related items and using alternative verbs—e.g., "Introduces an `upstreamError` marker on `NewAPIError` and adds helper functions `MarkAsUpstreamError` and `IsUpstreamError`," and then mention "implements `ApplyDownstreamNewAPIErrorPolicy`" as a separate clause—so the list reads smoothly and avoids three successive "Adds" starters while still referencing `NewAPIError`, `ApplyDownstreamNewAPIErrorPolicy`, `MarkAsUpstreamError`, and `IsUpstreamError`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@docs/upstream-error-503-logmask.md`:
- Around line 52-55: The three consecutive bullet sentences that each begin with
"Adds" are repetitive; update the description for `types/error.go` to vary
sentence structure by combining related items and using alternative verbs—e.g.,
"Introduces an `upstreamError` marker on `NewAPIError` and adds helper functions
`MarkAsUpstreamError` and `IsUpstreamError`," and then mention "implements
`ApplyDownstreamNewAPIErrorPolicy`" as a separate clause—so the list reads
smoothly and avoids three successive "Adds" starters while still referencing
`NewAPIError`, `ApplyDownstreamNewAPIErrorPolicy`, `MarkAsUpstreamError`, and
`IsUpstreamError`.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cfe795dd-b523-4b01-86d8-a693461fcd95
📒 Files selected for processing (23)
controller/relay.godocs/upstream-error-503-logmask.mdmodel/log.gomodel/log_test.gorelay/channel/ali/image.gorelay/channel/ali/rerank.gorelay/channel/claude/relay-claude.gorelay/channel/gemini/relay-gemini.gorelay/channel/jimeng/image.gorelay/channel/minimax/image.gorelay/channel/openai/chat_via_responses.gorelay/channel/openai/relay-openai.gorelay/channel/openai/relay_responses.gorelay/channel/openai/relay_responses_compact.gorelay/channel/palm/relay-palm.gorelay/channel/tencent/relay-tencent.gorelay/channel/zhipu/relay-zhipu.gorelay/channel/zhipu_4v/image.goservice/error.goservice/error_test.goservice/violation_fee.gotypes/error.gotypes/error_policy_test.go
Summary
Verification
Summary by CodeRabbit
Release Notes
New Features
Documentation
Tests