Surface credential sync failures in the management UI - #53
Merged
maiphucgiang merged 1 commit intoOct 4, 2026
Merged
maiphucgiang merged 1 commit into
maiphucgiang merged 1 commit into
Conversation
A failed credential sync only produced a generic "操作失败" message and the dashboard never rendered the recorded reason, so an account whose refresh token was rejected looked identical to a healthy disabled one. - Expose the ledger's last sync error as sync_error in the credential inventory (field was already whitelisted, never populated). - Show last_error_code / last_failure_at and sync_error under 认证健康. - Include the exception type in manual action failures instead of the generic message only.
Reviewer's GuideThe PR carries credential synchronization errors from the backend ledger into the management API and renders both classified recent errors and detailed reasons in the UI, while adding safe exception-type context to manual action failures; disabled health precedence and existing status semantics remain unchanged. Sequence diagram for surfacing credential sync failuressequenceDiagram
participant Ledger as CreditsLedger
participant Management as ManagementAPI
participant UI as CredentialsUI
participant Operator
Ledger->>Management: balance.error
Management->>Management: admin_credential_inventory()
Management-->>UI: sync_error, last_error_code, last_failure_at, health
UI->>UI: lastErrorLabel(last_error_code)
UI-->>Operator: 最近错误 + 时间戳
UI-->>Operator: 失败原因(sync_error)
Sequence diagram for manual action failure feedbacksequenceDiagram
participant Operator
participant Actions as CredentialActions
participant Upstream
Operator->>Actions: run(gateway, action, identity)
Actions->>Upstream: credential sync or refresh
Upstream-->>Actions: Exception
Actions->>Actions: type(error).__name__
Actions-->>Operator: 操作失败(异常类型),保留已有数据
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. The UI now renders balance.error or last_error directly, so a malformed upstream error could expose credential paths, headers, or other sensitive details to management users. Reverting stops future disclosure, but any information already displayed cannot be fully recovered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A credential whose sync or token refresh fails is visually indistinguishable from a healthy disabled account: the dashboard shows 已停用 and manual actions only return a generic "操作失败" message. The failure reason is recorded by the backend but never reaches the UI. This change exposes it.
Real-world reproduction
12153: refresh token failed: 400 Bad Request: invalid_grant: Refresh token issued before the user session started操作失败,保留已有数据;请检查账号状态后重试(
credits: AuthExpiredError: 登录身份过期) was stored in the credits ledger but never surfaced anywhere in the UI.Root cause
Management.admin_credential_inventory(app/gateway_management.py) deriveslast_error_code/last_failure_atfromentry["last_error"], but the credits ledger's detailederror(written byledger.note_errorvia_sync_error) is never exposed. Notesync_erroris already listed in the public credential field whitelist inapp/admin_api.py— it was simply never populated.last_error_code,last_failure_atorsync_error— the Chinese labels exist inweb/src/values.tsx, but no JSX uses them (web/src/pages/Credentials.tsx).app/credential_actions.py).Changes (3 files, +23 / −2)
| File | Change |
|
|
|
|
app/gateway_management.py| Populatesync_errorfrom the ledger'serror(fallback:entry["last_error"]). ||
web/src/pages/Credentials.tsx| Render 最近错误 (friendly labels forhttp_401/http_403/credential_error) with timestamp, plus the detailed 失败原因 under 认证健康. ||
app/credential_actions.py| Include the exception type in manual action failure messages. |Deliberately unchanged:
healthprecedence (disabledstill wins overerror) — the failure reason is shown as supplementary text, so existing status semantics are untouched.Verification
test_credential_*/test_admin_*suites pass (63 tests OK). Full suite: 64/65 files. The one failing file (test_stream_status_contract.py) is flaky on macOS without this change too (random 1–3 failures per run) and covers streaming, not credentials.vp buildsucceeds. Vitest failure list is identical to the unmodified baseline (18 pre-existing environment failures, same list before/after).sync_error; patched service returnssync_error: "credits: AuthExpiredError: 登录身份过期".API evidence
Before (unmodified):
{ "health": "disabled", "last_error_code": "credential_error", "last_failure_at": 1791041902.6 }After (patched):
{ "health": "disabled", "last_error_code": "credential_error", "last_failure_at": 1791041902.6, "sync_error": "credits: AuthExpiredError: 登录身份过期" }Summary by Sourcery
Surface credential synchronization failures and their underlying causes in the management experience.
New Features:
Bug Fixes:
Enhancements: