Skip to content

feat: hide upstream error message#1640

Merged
looplj merged 2 commits into
looplj:unstablefrom
LRan1028:unstable
May 11, 2026
Merged

feat: hide upstream error message#1640
looplj merged 2 commits into
looplj:unstablefrom
LRan1028:unstable

Conversation

@LRan1028

@LRan1028 LRan1028 commented May 11, 2026

Copy link
Copy Markdown
image image image

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an "Upstream Error Display" policy, allowing administrators to control whether raw provider errors are shown to API users, hidden, or replaced with custom messages. The implementation includes frontend UI updates, GraphQL schema changes, and backend logic to intercept and transform errors in both standard and streaming chat completions. Review feedback suggests optimizing the backend implementation by caching transformed errors in the stream handler to avoid redundant policy lookups and transformations. Additionally, it was noted that the error detection logic currently relies on fragile string matching and should be replaced with more robust error type checking.

Comment thread internal/server/api/upstream_error_policy.go
Comment thread internal/server/api/upstream_error_policy.go
Comment thread internal/server/api/upstream_error_policy.go
Comment thread internal/server/api/upstream_error_policy.go Outdated
@greptile-apps

greptile-apps Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds an admin-configurable policy for how upstream provider errors are exposed to API users: pass through (default), hide with a generic message, or replace with a custom message. The pipeline layer tags upstream errors with a sentinel UpstreamError wrapper, and the API layer applies the masking policy before serialising the response.

  • New UpstreamError sentinel type (llm/pipeline/upstream_error.go) replaces the previous fragile string-matching approach with a proper struct-based classifier; WrapUpstreamError is idempotent.
  • transformOrchestratorError helper consolidates quota wrapping + policy application + inbound transform into one call, and is now applied uniformly to the chat, video, and Doubao handlers.
  • upstreamErrorStream wrapper intercepts Err() on the SSE stream so mid-stream provider errors are also subject to the policy, not just pre-stream errors.

Confidence Score: 5/5

Safe to merge. The core masking logic is well-guarded: quota errors are excluded at two levels, non-upstream errors are skipped via the UpstreamError sentinel, and all three API handler paths now consistently apply the policy.

The implementation correctly replaced the previous string-based error classification with a struct-based sentinel. Video and Doubao handlers now go through transformOrchestratorError. No data integrity, auth, or correctness regressions are introduced. The only finding is a minor redundant policy read in the streaming error path.

No files require special attention beyond the minor style note on upstream_error_policy.go.

Important Files Changed

Filename Overview
internal/server/api/upstream_error_policy.go New file implementing upstream error masking. Logic is sound: struct-based UpstreamError tag replaces the previous fragile string-matching approach. Minor redundancy: Err() fetches the policy once for a mode guard and then applyUpstreamErrorPolicy fetches it a second time internally.
llm/pipeline/upstream_error.go New UpstreamError sentinel type; WrapUpstreamError is idempotent. Clean and correct.
llm/pipeline/stream.go Errors from DoStream and TransformStream now wrapped with WrapUpstreamError. Middleware errors correctly left unwrapped.
internal/server/api/chat.go Both non-streaming and streaming paths now apply the upstream error policy correctly.
internal/server/biz/system.go Adds UpstreamErrorPolicy struct and constants. normalizeRetryPolicy silently coerces custom+empty-message to hidden mode (flagged in previous review thread).
internal/server/api/chat_test.go Three new tests cover custom message replacement, passthrough no-op, and local ResponseError pass-through.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    REQ[Incoming API Request] --> ORCH[Orchestrator]
    ORCH -->|error| TE[transformOrchestratorError]
    TE --> WQ[wrapQuotaExhaustedAsResponseError]
    WQ --> AUP[applyUpstreamErrorPolicy]
    AUP -->|IsUpstreamError? NO| PASS1[Pass through unchanged]
    AUP -->|IsUpstreamError? YES| MASK[Replace message]
    MASK --> TFE[Inbound.TransformError]
    PASS1 --> TFE
    TFE --> RESP[JSON response]
    ORCH -->|stream| UES[upstreamErrorStream wrapper]
    UES --> ERR[Err called after stream]
    ERR -->|nil| OK[No error]
    ERR -->|non-nil| WAUP[WrapUpstreamError + applyUpstreamErrorPolicy]
    WAUP -->|quota err| PASSQ[Quota: always pass through]
    WAUP -->|hidden/custom| MASKSM[Replace message]
    WAUP -->|passthrough| PASS2[Pass through unchanged]
Loading

Reviews (3): Last reviewed commit: "fix" | Re-trigger Greptile

Comment thread internal/server/biz/system.go
Comment thread internal/server/api/upstream_error_policy.go Outdated
@LRan1028 LRan1028 changed the title 支持隐藏渠道报错 Support hiding channel errors May 11, 2026

@LRan1028 LRan1028 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

@LRan1028 LRan1028 closed this May 11, 2026
@LRan1028 LRan1028 reopened this May 11, 2026
@looplj looplj changed the title Support hiding channel errors feat: hiding upstream error message May 11, 2026
@looplj looplj changed the title feat: hiding upstream error message feat: hie upstream error message May 11, 2026
@looplj looplj changed the title feat: hie upstream error message feat: hide upstream error message May 11, 2026
@looplj looplj merged commit 724bbcc into looplj:unstable May 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants