Skip to content

fix(ops): 默认忽略 count_tokens 404 错误#735

Merged
Wei-Shaw merged 2 commits intoWei-Shaw:mainfrom
alfadb:fix/count-tokens-default-ignore
Mar 3, 2026
Merged

fix(ops): 默认忽略 count_tokens 404 错误#735
Wei-Shaw merged 2 commits intoWei-Shaw:mainfrom
alfadb:fix/count-tokens-default-ignore

Conversation

@alfadb
Copy link
Contributor

@alfadb alfadb commented Mar 3, 2026

背景

PR #657 修复了 count_tokens 端点在上游不支持时返回 404 而非伪造 200 的行为。这是正确的修复,但导致高频 404 错误日志在运维监控中显示,造成不必要的干扰(详见 #657 (comment))。

根因

count_tokens 返回 404 是预期业务行为(上游不支持 endpoint,客户端应 fallback 到本地 tokenizer 估算),不应被视为错误。

修复方案

IgnoreCountTokensErrors 默认值从 false 改为 true

改动

  • backend/internal/service/ops_settings.go: IgnoreCountTokensErrors 默认值改为 true

测试

  • 默认行为:count_tokens 404 错误不再记录到运维监控
  • 用户仍可通过配置显式启用该错误记录(如需调试)

将 IgnoreCountTokensErrors 默认值从 false 改为 true。

count_tokens 返回 404 是预期业务行为(上游不支持 endpoint,
客户端应 fallback 到本地 tokenizer 估算),不应被视为错误。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

该 PR 旨在降低运维监控中的噪音:将 count_tokens 上游不支持导致的 404 视为预期业务行为,默认不再记录为 ops 错误。

Changes:

  • OpsAdvancedSettings.IgnoreCountTokensErrors 的默认值从 false 改为 true
  • 为该默认行为补充了行内说明注释

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

AggregationEnabled: false,
},
IgnoreCountTokensErrors: false,
IgnoreCountTokensErrors: true, // count_tokens 404 是预期行为,默认忽略
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

这里仅修改 defaultOpsAdvancedSettings() 的默认值;但 GetOpsAdvancedSettings() 在设置项已存在时只做 Unmarshal + normalize,不会把新默认值写回/合并到已有配置里。因此对已经持久化了旧配置(或缺失该字段的旧 JSON)的环境,这个“默认值改为 true”可能不会生效,仍然会继续上报 count_tokens 404。建议在读取时与 defaultCfg 做合并(尤其是缺字段时),或加一次性迁移/回写逻辑来更新现有配置。

Copilot uses AI. Check for mistakes.
AggregationEnabled: false,
},
IgnoreCountTokensErrors: false,
IgnoreCountTokensErrors: true, // count_tokens 404 是预期行为,默认忽略
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

IgnoreCountTokensErrors 当前在 ops_error_logger 中是按路径直接跳过所有 /count_tokens 的错误日志,而不仅仅是 404。这里的注释写“404 是预期行为”会误导,并且把默认值改为 true 可能会屏蔽 count_tokens 的真实异常(如 5xx)。建议要么把注释改成“忽略所有 count_tokens 错误”,要么将过滤逻辑收窄到仅忽略 404/NotFound。

Suggested change
IgnoreCountTokensErrors: true, // count_tokens 404 是预期行为,默认忽略
IgnoreCountTokensErrors: true, // 忽略所有 /count_tokens 错误(包括 404),默认开启

Copilot uses AI. Check for mistakes.
Remove extra space before inline comment to pass golangci-lint gofmt check.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Wei-Shaw Wei-Shaw merged commit 60350d2 into Wei-Shaw:main Mar 3, 2026
4 checks passed
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.

3 participants