Skip to content

perf(proxy): 缩短预派发路由决策开销 - #284

Merged
g1331 merged 8 commits into
masterfrom
perf/proxy-routing-latency
Aug 21, 2026
Merged

perf(proxy): 缩短预派发路由决策开销#284
g1331 merged 8 commits into
masterfrom
perf/proxy-routing-latency

Conversation

@g1331

@g1331 g1331 commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Summary

将 autoresearch 分支中验证有效的路由决策优化整理为正式工程实现,删除实验专用 harness,不改变现有路由协议、候选筛选或认证公共 API。

Related Issue

无。

Type of Change

  • Refactoring
  • Documentation update
  • Tests
  • Breaking change

Changes

  • 为成功的 API Key bcrypt 校验增加进程内有界短 TTL 缓存;缓存只跳过重复 bcrypt,数据库中的 active、过期、用户状态和授权检查仍逐请求执行。缓存指纹使用进程随机密钥保护的 WebCrypto HMAC-SHA-256,不保存明文密钥。
  • 增加已归一化模型规则匹配入口,避免代理路由和下游模型目录重复构建规则状态。
  • 增加不分配完整数组的上游 capability 成员判断,保留 legacy codex_responses 映射。
  • 补齐 API Key、模型规则和 capability 的回归测试。
  • 更新请求生命周期与客户端 Key 文档。
  • 未保留 autoresearch.shscripts/benchmarks/* 等实验临时文件。

Benchmark Evidence

  • autoresearch 固定离线基线:routing_decision_us=199376
  • 原始最佳实验实现:routing_decision_us=203routing_decision_p95_us=303
  • 为通过 CodeQL 的最终正式实现改用 WebCrypto keyed fingerprint 后,临时加载同一基准复测:routing_decision_us=252routing_decision_p95_us=379api_key_verify_us=56final_candidate_count=35
  • 最终结果仍比基线低约 99.87%;基准包含固定 API Key、模型规则、能力候选过滤、授权过滤和负载均衡选路,最终候选数量与选中结果保持稳定。基准文件未进入正式分支。

Test Plan

  • pnpm test:run --maxWorkers=1:245 个文件通过,3645 个测试通过,1 个跳过。
  • pnpm exec tsc --noEmit:通过。
  • pnpm lint:通过。
  • pnpm format:check:通过。
  • pnpm buildDB_TYPE=postgres):通过;仅有现有 Turbopack NFT tracing warning。
  • 正式分支临时加载并运行性能 benchmark:通过,临时文件已移除。
  • GitHub Actions PR CI:Quality、Production Build、Migration Consistency、Proxy Stability、Playwright E2E、GitHub Actions、CodeQL、Verify Status 全部通过。

Changelog

仓库没有手写 CHANGELOG 文件;本 PR 使用 perftestdocsfix(security) Conventional Commit 前缀,由 git-cliff 在 release 时生成变更记录。

Additional Notes

没有新增依赖、数据库迁移或公共 API 破坏性变更。

Comment thread src/lib/utils/auth.ts Fixed
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.42105% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.50%. Comparing base (3568d71) to head (248f3ef).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #284      +/-   ##
==========================================
- Coverage   72.52%   72.50%   -0.03%     
==========================================
  Files         245      245              
  Lines       14488    14519      +31     
  Branches     4829     4836       +7     
==========================================
+ Hits        10508    10527      +19     
- Misses       2596     2605       +9     
- Partials     1384     1387       +3     
Flag Coverage Δ
verify 72.50% <68.42%> (-0.03%) ⬇️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/lib/utils/auth.ts Fixed
Comment thread src/lib/utils/auth.ts Fixed
@g1331
g1331 merged commit 1838f00 into master Aug 21, 2026
14 checks passed
@g1331
g1331 deleted the perf/proxy-routing-latency branch August 21, 2026 12:59
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