fix: 修复自动 compact 阈值推导回退与模型元数据校验#316
Conversation
- fallback when resolver returns zero/negative without error - add regression tests for zero/negative resolver outputs - align compact/config docs with implicit-threshold behavior Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
- cache derived auto compact threshold per run using provider/model/auto_compact key - recompute only when key changes to avoid repeated resolver snapshot lookups in hot path - simplify run flow by extracting session lock binding and self-healing prompt injection helpers - add runtime tests for cache hit and key-change recompute behavior Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
…hold fix(runtime): cache auto-compact threshold within run
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
fix: resolve test failure from runtime merge markers
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
/review |
|
/simplify |
CompletedImplemented and pushed follow-up fixes for the unresolved review comments that were worth applying:
Simplify PassAttempted a dedicated simplifier sub-agent run, but it failed due to upstream Verification
Git
Not Done
|
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
|
/review |
| } | ||
|
|
||
| models, err := catalogs.ListProviderModelsSnapshot(ctx, input) | ||
| if err != nil { |
There was a problem hiding this comment.
ResolveAutoCompactThreshold currently swallows catalog snapshot errors and returns fallback with nil error. That prevents runtime from distinguishing a transient resolver failure from a stable fallback case, so autoCompactThresholdForState may cache the fallback threshold for the rest of the run even when the catalog recovers on the next turn. Consider returning the snapshot error here (while still including fallback in the resolution) so runtime can skip caching on error, matching the intent in run.go.
| } | ||
|
|
||
| models, err := catalogs.ListProviderModelsSnapshot(ctx, input) | ||
| if err != nil { |
There was a problem hiding this comment.
ListProviderModelsSnapshot errors are swallowed and returned as fallback with nil error. That makes runtime treat this as cacheable success, so a transient snapshot/catalog failure on early turns can lock the run to fallback threshold even after recovery. Consider returning the resolver error (while still carrying fallback threshold) so runtime can skip caching on failure.
| } | ||
|
|
||
| models, err := catalogs.ListProviderModelsSnapshot(ctx, input) | ||
| if err != nil { |
There was a problem hiding this comment.
ListProviderModelsSnapshot 出错后直接返回 fallback 且 error=nil,会让上层 autoCompactThresholdForState 认为这是可缓存成功结果。这样若首轮是临时 catalog/snapshot 故障,后续轮次即使恢复也可能继续命中 fallback 缓存。建议保留 fallback 数值用于本轮兜底,但同时向上返回非 nil error(或返回可区分的状态),让 runtime 跳过该次结果缓存。
|
/simplify |
完成情况已按触发评论执行:先检查历史评论中的未解决项,再做简化处理,并已提交推送到当前 PR 分支( 本次处理
验证
提交信息
|
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
背景
context.auto_compact.input_token_threshold <= 0的隐式模式下,provider/catalog 查询失败会把自动压缩静默降成0,没有走保底阈值。provider.yaml.models缺少 fail-fast 校验,错误配置会被悄悄吞掉。本次修改
internal/config/state新增自动 compact 阈值解析器,provider 选择、catalog 输入或 snapshot 查询失败时统一回退到fallback_input_token_threshold。models增加id、context_window、max_output_tokens和重复模型 ID 的校验,错误配置在加载阶段直接失败。/etc/passwd这类绝对路径的安全判定漏洞。验证
go test ./internal/config/... ./internal/runtime ./internal/app ./internal/gateway/handlers ./internal/tools/bash说明
go test ./...仍会被当前主线internal/tui/infra的既有平台测试问题阻塞,本 PR 没有扩大范围处理那部分历史问题。