Skip to content

fix(pricing): isolate structured OpenRouter quotes during automatic sync - #791

Merged
LIghtJUNction merged 1 commit into
mainfrom
fix/openrouter-structured-pricing-20261011
Oct 11, 2026
Merged

LIghtJUNction merged 1 commit into
mainfrom
fix/openrouter-structured-pricing-20261011

Conversation

@LIghtJUNction

Copy link
Copy Markdown
Member

LMM API Pull Request

变更说明 / Summary

OpenRouter 的模型目录已出现 pricing.overrides 数组。原同步程序将整个 pricing 解码为 map[string]string,一条结构化报价就会使整个渠道同步失败,报 cannot unmarshal array ... pricing ... string。

现在先保留每个模型的原始报价,再逐模型校验。普通字符串报价继续走现有自动同步;结构化字段、非字符串价格和无效报价对象仅跳过所属模型,并在 test_results.skipped_models 返回原因。仍拒绝无法表示的收费维度,避免把分档价格导入成更便宜的基础价。整份损坏的 JSON 仍报错。

新增回归覆盖数组、对象、数字、null、无效报价对象,以及真实 fetch handler:有效模型仍产生价格差异、被跳过模型不产生价格差异、获取同步预览不写入价格配置。没有修改生产价格,也没有合并或部署。

与上游的关系 / Upstream relationship

  • LMM API 独有变更 / LMM API-specific change
  • 上游尚未合并的修复或功能 / Change not yet merged upstream
  • 同步或移植上游变更 / Upstream sync or backport
  • 不适用(文档、CI、仓库维护等)/ Not applicable

上游参考 / Upstream reference:

OpenRouter 官方模型目录:https://openrouter.ai/api/v1/models
官方接口说明:https://openrouter.ai/docs/api/api-reference/models/list-all-models-and-their-properties

关联 Issue / Related issue

无新 Issue。已检查现有 OpenRouter PR 和相关 Issue;#417 的缺失/非有限价格拒绝行为保持不变。

变更类型 / Type of change

  • Bug 修复 / Bug fix
  • 新功能 / Feature
  • 重构或性能优化 / Refactor or performance
  • 前端或交互 / Frontend or UX
  • 部署、CI 或构建 / Deployment, CI, or build
  • 文档或仓库维护 / Documentation or maintenance

验证 / Verification

验证基线 de2c439f26446792d4a605b2b91fa2b84777e284 加本 PR 的两文件改动;提交 8b045f45f3ddd83e009478cf729d0c9d07c14afc。数据库测试使用隔离 SQLite fixture,所有命令清除 SQL_DSN、LOG_SQL_DSN、REDIS_CONN_STRING。仅本地执行,未触发远程 CI。

cwd: apps/api-go
command: env -u SQL_DSN -u LOG_SQL_DSN -u REDIS_CONN_STRING go test ./controller -run 'Test(OpenRouter|RatioSync)' -count=1
result: PASS (2.495s)

command: env -u SQL_DSN -u LOG_SQL_DSN -u REDIS_CONN_STRING go vet ./...
result: PASS

cwd: repository root
command: env -u SQL_DSN -u LOG_SQL_DSN -u REDIS_CONN_STRING mise exec bun@1.3.14 -- just build
result: PASS (Go and web artifacts; bundle size check passed)

command: git diff --check
result: PASS; both changed Go files also pass gofmt

command: env -u SQL_DSN -u LOG_SQL_DSN -u REDIS_CONN_STRING mise exec bun@1.3.14 -- just check
result: FAIL at format-check:go; existing formatting in controller/subscription.go and service/file_service_rt18_test.go

cwd: apps/api-go
command: env -u SQL_DSN -u LOG_SQL_DSN -u REDIS_CONN_STRING go test ./...
result: FAIL in existing controller/middleware/router tests listed below

全量测试的以下失败均在原基线重新运行并复现:

  • TestAssistantAdminOperationContractsMatchSources
  • TestRT17ModelParserContinuity
  • TestRT17PlaygroundGroupParserContinuity
  • TestBI10RealRoutesRejectRotatedPAT
  • TestRT17RelayCatalogRawIdentityBoundaries

未更改这些无关测试和格式问题。just check 在格式步骤停止,后续 web lint/typecheck/tests 与部署检查未通过该命令执行;本次未改 web 或部署代码。

截图或日志 / Screenshots or logs

2026-10-11 对官方公开目录的 458 份模型数据做本地离线回放:原版复现 json: cannot unmarshal array into Go struct field .data.1.pricing.overrides of type string;修复版正常返回,249 个模型生成可同步的普通报价,其余保持已有校验或逐模型跳过。这个回放和 handler 测试均未调用生产写价接口。

提交检查 / Checklist

  • 我已搜索本仓库的 Issues 和 PRs,确认没有重复工作。
  • 此 PR 只包含与当前目标相关的改动,未混入格式化或其他无关变更。
  • 我已说明该变更对当前产品流程或兼容行为的影响,并保留必要的来源、版权和许可证信息。
  • 我已检查兼容性;如有破坏性变化,已在说明中明确列出迁移方式。
  • 我已补充或更新相关测试,并在上方记录实际验证结果;如未测试,已说明原因。
  • 我已更新受影响的文档、示例配置和多语言文案(如适用;本次不涉及)。
  • 代码、日志、截图和提交记录中不包含真实 API Key、Cookie、Token、密码、DSN 或其他敏感信息。

@LIghtJUNction
LIghtJUNction marked this pull request as ready for review October 11, 2026 14:20
Copilot AI balanced review requested due to automatic review settings October 11, 2026 14:20
@LIghtJUNction
LIghtJUNction merged commit 648c58b into main Oct 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-10-11T14:30:21.421944Z 8b045f4 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@LIghtJUNction
LIghtJUNction deleted the fix/openrouter-structured-pricing-20261011 branch November 5, 2026 07:31
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