Skip to content

fix(api): 保留熔断触发原因并优先映射上游状态码 - #6921

Merged
qin-ctx merged 1 commit into
mainfrom
fix/circuit-breaker-http-status-20261102
Nov 2, 2026
Merged

qin-ctx merged 1 commit into
mainfrom
fix/circuit-breaker-http-status-20261102

Conversation

@qin-ctx

@qin-ctx qin-ctx commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Description

修复查询 embedding 熔断后,find 将上游额度耗尽、服务不可用和超时统一返回为 500 / INTERNAL 的问题。熔断拒绝保留触发它的原始错误,由现有 HTTP 映射继续返回对应的 429 / RESOURCE_EXHAUSTED、503 / UNAVAILABLE 或 504 / DEADLINE_EXCEEDED。

具体例子:发送 POST /api/v1/search/find,请求体为 {"query":"test"}。上游返回 429 / AccountQuotaExceeded 并触发熔断后,再次发送同一请求:

  • Before: HTTP 500,error.code = INTERNAL,error.message = Internal server error。
  • After: HTTP 429,error.code = RESOURCE_EXHAUSTED,error.details.upstream_status_code = 429,保留上游额度错误信息。

同时修正错误识别优先级:结构化状态码优先于关键词;文本状态码必须有 HTTP、status 或 error 等明确上下文,不再把请求 ID 中的 401 或 429 tokens 当成状态码。

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

Related #6139:处理其中熔断后丢失上游错误语义的问题。

Related #6141:该提案将熔断统一映射为 503;本 PR 保留触发熔断的原始错误类别。

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • 熔断器记录触发打开状态的异常,通过异常因果链传给后续被拒绝的请求;探测失败时更新原因,调用成功时清除。
  • 复用统一 HTTP 错误映射,避免在 find 路由增加特殊分支;结构化状态码不再被缺少 API key 的关键词覆盖,删除无上下文的数字匹配。
  • 改写现有契约测试,覆盖熔断前后状态一致、恢复探测、原因更新、未知错误和多凭据聚合;没有新增测试函数或测试文件。

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

通过扩展现有测试补充回归覆盖:

  • 错误映射与熔断测试:100 passed;排除的 2 个旧分类断言在基线同样失败,仍期待 401/403 为 permanent,而当前实现为 auth。
  • embedding 队列的熔断及重新入队相关测试:5 passed。
  • 通过实际 find HTTP 路由和 AccountEmbeddingProvider,注入上游 429、503、504:首次失败与随后被熔断的请求分别返回相同状态,每组只调用一次模拟上游。
  • ruff check 和 git diff --check 通过。

复现命令:

python -m pytest tests/server/test_error_mapping.py tests/unit/test_circuit_breaker.py tests/utils/test_circuit_breaker.py -q --no-cov -k 'not test_classify_permanent_errors and not test_classify_chained_exception'
python -m pytest tests/storage/test_collection_schemas.py -k 'breaker or requeue' -q --no-cov

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

不适用。

Additional Notes

引入时间已核对父提交和调用链:

没有新增 API 或配置,也不改变熔断阈值、等待时间和队列处理策略。

避免 find 在 embedding 熔断后将上游 429、503、504 错误降为通用 500。
状态码优先于关键词,且不再从请求 ID 或普通数字推断 HTTP 状态。
@qin-ctx
qin-ctx merged commit a7e11fb into main Nov 2, 2026
11 checks passed
@qin-ctx
qin-ctx deleted the fix/circuit-breaker-http-status-20261102 branch November 2, 2026 12:40
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Nov 2, 2026
qin-ctx added a commit that referenced this pull request Nov 18, 2026
避免 find 在 embedding 熔断后将上游 429、503、504 错误降为通用 500。
状态码优先于关键词,且不再从请求 ID 或普通数字推断 HTTP 状态。

(cherry picked from commit a7e11fb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants