Skip to content

follow-up(pricing): CalculateByPriceID 增加跨模型 ModelID 一致性校验 #577

Description

@coderabbitai

背景

PR #575(fix(pricing): recalc uses historical price snapshot via attempt.ModelPriceID)在审查过程中识别出以下潜在问题,作为后续改进事项单独跟踪。

PR 链接:#575
相关审查讨论:https://github.com/awsl-project/maxx/pull/575(review thread,cross-model sanity check 段落)

问题描述

CalculateByPriceID 目前按 attempt.ModelPriceID 反查历史价格快照后,不校验所查到的 ModelPrice.ModelID 是否与 attempt.ResponseModel 一致。

若数据库中出现以下情形,重算将静默使用错误模型的价格,而不会报错或降级:

  • attempt.ModelPriceID 与实际响应模型不匹配(数据状态异常)

该风险早于本 PR 存在,且在当前活跃定价路径中同样有对应的潜在隐患,因此被有意推迟到独立 PR 修复。

期望行为

CalculateByPriceID 内(或调用层),对反查结果的 ModelID 与预期模型进行比对;不匹配时返回可被调用方识别的信号(如新增参数 wantModelID string,或返回特定错误类型),由调用方决定是否降级或报告。

影响范围

  • internal/pricing/calculator.goCalculateByPriceID 签名及实现
  • internal/pricing/attempt.go:调用侧适配
  • 相关测试 fakes / stub-repo 需同步更新参数

备注

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions