Skip to content

fix: 修复自动 compact 阈值推导回退与模型元数据校验#316

Merged
phantom5099 merged 9 commits into
1024XEngineer:mainfrom
wynxing:main
Apr 16, 2026
Merged

fix: 修复自动 compact 阈值推导回退与模型元数据校验#316
phantom5099 merged 9 commits into
1024XEngineer:mainfrom
wynxing:main

Conversation

@wynxing

@wynxing wynxing commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

背景

本次修改

  • internal/config/state 新增自动 compact 阈值解析器,provider 选择、catalog 输入或 snapshot 查询失败时统一回退到 fallback_input_token_threshold
  • 调整 runtime 的阈值消费逻辑,resolver 失败时不再把 implicit 模式静默关闭。
  • 为 custom provider models 增加 idcontext_windowmax_output_tokens 和重复模型 ID 的校验,错误配置在加载阶段直接失败。
  • 补齐 config/state/runtime/provider loader 相关测试,并同步更新 context compact、配置与 provider 文档。
  • 顺手修复了 Windows 下 review path 对 /etc/passwd 这类绝对路径的安全判定漏洞。

验证

  • go test ./internal/config/... ./internal/runtime ./internal/app ./internal/gateway/handlers ./internal/tools/bash

说明

  • 本地 Windows 环境下 go test ./... 仍会被当前主线 internal/tui/infra 的既有平台测试问题阻塞,本 PR 没有扩大范围处理那部分历史问题。

wynxing and others added 7 commits April 15, 2026 22:16
- 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
@wynxing

wynxing commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

/review

fennoai[bot]

This comment was marked as outdated.

@wynxing

wynxing commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

/simplify

fennoai[bot]

This comment was marked as outdated.

fennoai[bot]

This comment was marked as outdated.

fennoai[bot]

This comment was marked as outdated.

fennoai[bot]

This comment was marked as outdated.

fennoai[bot]

This comment was marked as outdated.

@fennoai

fennoai Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Completed

Implemented and pushed follow-up fixes for the unresolved review comments that were worth applying:

  • Runtime: fixed auto-compact threshold caching so resolver error fallback is not cached for the whole run. This allows later turns to retry resolver and recover from transient snapshot/catalog failures.
    • Updated: internal/runtime/run.go
    • Added regression test: TestAutoCompactThresholdForStateDoesNotCacheResolverErrorFallback in internal/runtime/runtime_test.go
  • Docs: aligned fallback conditions with implementation by adding ContextWindow <= reserve_tokens case and removed duplicated Auto Compact explanation section to reduce drift risk.
    • Updated: docs/guides/configuration.md

Simplify Pass

Attempted a dedicated simplifier sub-agent run, but it failed due to upstream 502. I completed a manual simplification/cleanup pass locally on the touched files.

Verification

  • go test ./internal/runtime

Git

  • Commit: 27ae095
  • Pushed to PR head branch: Yumiue:main

Not Done

  • Did not implement cross-run threshold memoization (larger scope; not a correctness blocker for this PR).

View job run

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
@wynxing

wynxing commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Found 1 issue worth addressing in the auto-compact threshold fallback path.

}

models, err := catalogs.ListProviderModelsSnapshot(ctx, input)
if err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Focused review complete.

One noteworthy issue remains in the auto-compact fallback/error path.

}

models, err := catalogs.ListProviderModelsSnapshot(ctx, input)
if err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

发现 1 个需要关注的问题(其余子代理反馈均为重复或无问题):

  • auto_compact 阈值解析在 snapshot 查询失败时吞掉 error,导致 runtime 可能把 fallback 结果当作成功解析并缓存,无法在同一 run 内重试恢复后的目录数据。

}

models, err := catalogs.ListProviderModelsSnapshot(ctx, input)
if err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ListProviderModelsSnapshot 出错后直接返回 fallback 且 error=nil,会让上层 autoCompactThresholdForState 认为这是可缓存成功结果。这样若首轮是临时 catalog/snapshot 故障,后续轮次即使恢复也可能继续命中 fallback 缓存。建议保留 fallback 数值用于本轮兜底,但同时向上返回非 nil error(或返回可区分的状态),让 runtime 跳过该次结果缓存。

@wynxing

wynxing commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

/simplify

@fennoai

fennoai Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

完成情况

已按触发评论执行:先检查历史评论中的未解决项,再做简化处理,并已提交推送到当前 PR 分支(Yumiue:main)。

本次处理

  • 修复了未解决 review 点(internal/config/state/auto_compact_threshold.go):
    • ListProviderModelsSnapshot 失败时,返回“fallback 阈值 + 非 nil error”,避免 runtime 将这类瞬时失败当作可缓存成功结果。
  • 同步更新测试(internal/config/state/auto_compact_threshold_test.go):
    • TestResolveAutoCompactThresholdFallsBackWhenSnapshotLookupFails 现在断言会返回非 nil error,同时阈值仍为 fallback。
  • 按要求执行 code-simplifier 子代理:
    • 第一次调用因上游 502 失败,第二次成功。
    • 对测试文件进行了无行为变化的简化(提取公共断言 helper,减少重复样板)。

验证

  • go test ./internal/config/state ./internal/runtime

提交信息

  • Commit: 0abd7ec
  • 已推送:git push fork HEAD:main

View job run

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
@phantom5099 phantom5099 merged commit 8e9dd87 into 1024XEngineer:main Apr 16, 2026
2 checks passed
@fennoai fennoai Bot mentioned this pull request Apr 24, 2026
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.

feat(context): 自动基于模型最大上下文长度推导 auto compact 阈值

3 participants