Skip to content

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

Closed
wynxing wants to merge 4 commits into
1024XEngineer:mainfrom
wynxing:codex/issue-294-auto-compact-threshold
Closed

fix: 修复自动 compact 阈值推导回退与模型元数据校验#309
wynxing wants to merge 4 commits into
1024XEngineer:mainfrom
wynxing:codex/issue-294-auto-compact-threshold

Conversation

@wynxing

@wynxing wynxing commented Apr 15, 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 没有扩大范围处理那部分历史问题。

@codecov

codecov Bot commented Apr 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.94872% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/app/bootstrap.go 12.50% 6 Missing and 1 partial ⚠️
internal/config/state/auto_compact_threshold.go 94.59% 1 Missing and 1 partial ⚠️
internal/runtime/run.go 96.15% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

fennoai[bot]

This comment was marked as outdated.

@wynxing

wynxing commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator Author

/simplify

@fennoai

fennoai Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

处理结果

已完成 /simplify 请求中提到的三项未解决 review 问题,并将修改推送到当前 PR 分支 Yumiue:codex/issue-294-auto-compact-threshold(commit: 3055d8f)。

已修复项

  • internal/runtime/run.go
    • 修复 autoCompactThreshold:仅当 resolver 返回 threshold > 0 且无错误时才采用;否则回退到 fallbackAutoCompactThreshold(cfg)
  • internal/runtime/runtime_test.go
    • 新增 2 条回归测试,覆盖 resolver 在 err == nil 时返回 0 / 负值的场景,确保会走 fallback。
  • docs/context-compact.md
    • auto_compact.input_token_threshold 描述修正为默认 0(自动推导),失败回退 fallback_input_token_threshold(默认 100000)。
  • docs/guides/configuration.md
    • context 字段总览补充 context.auto_compact.reserve_tokenscontext.auto_compact.fallback_input_token_threshold

Simplifier 检查

已调用 code-simplifier 子代理复核,上述改动已是最小且清晰实现,无需进一步简化。

验证

  • go test ./internal/runtime 通过。

未处理项:无(仅按本次触发评论范围执行)。

View job run

- 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>
@phantom5099

Copy link
Copy Markdown
Collaborator

/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.

完成多维度审查并去重后,我保留 1 个值得处理的问题。

Comment thread internal/runtime/run.go Outdated
Compact: agentcontext.CompactOptions{
DisableMicroCompact: cfg.Context.Compact.MicroCompactDisabled,
AutoCompactThreshold: autoCompactThreshold(cfg),
AutoCompactThreshold: s.autoCompactThreshold(ctx, cfg),

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.

prepareTurnSnapshot() 每轮都会调用 s.autoCompactThreshold(ctx, cfg)。在隐式阈值模式下,这会进入 resolver 并触发 ListProviderModelsSnapshot(),从 catalog store 读取快照(可能是磁盘 JSON 读+反序列化)再合并模型描述,属于热路径上的重复开销。建议把该阈值按 provider+model+相关 auto_compact 配置 做 run 内缓存,只有这些输入变化时才重新解析。

@wynxing

wynxing commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator Author

/simplify

@fennoai

fennoai Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

处理结果

已按本次 /simplify 要求完成:检查未解决 review、修复值得修复项、执行简化、提交并推送。

本次修复与简化

  • 处理未解决 review(internal/runtime/run.go 热路径重复解析阈值)
    • 将隐式自动 compact 阈值解析改为 单次 Run 内缓存(按 provider + model + auto_compact 关键配置 作为缓存键)。
    • prepareTurnSnapshot() 改为消费 run-state 缓存版本,避免每轮重复 resolver/catalog 查询。
  • 增补测试
    • 新增缓存命中测试:同 key 下 resolver 仅调用一次。
    • 新增缓存失效测试:key 变化后重新解析。
  • code-simplifier 复核后采纳的简化
    • 提取 bindSessionLock,移除 Run 中会话锁绑定重复分支。
    • 提取 withSelfHealingReminder,收敛自愈提示词拼接逻辑。

验证

  • go test ./internal/runtime 通过。

提交与推送

未完成项:无。

View job run

xgopilot and others added 2 commits April 15, 2026 15:24
- 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>
@phantom5099

Copy link
Copy Markdown
Collaborator

/code 修复编译报错

@fennoai

fennoai Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

处理结果

已修复本分支编译报错并完成验证,问题是 internal/runtime/run.go 中残留了未清理的合并冲突标记(<<<<<<< / >>>>>>>)导致语法错误。

本次改动

  • 清理 internal/runtime/run.go 冲突标记并恢复可编译状态。
  • 保留系统提示词拼接逻辑:重复调用循环提醒优先;否则走无进展提醒注入(复用 withSelfHealingReminder)。

验证结果

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

提交与推送

未执行项:无。

View job run

@fennoai fennoai Bot mentioned this pull request Apr 15, 2026
@fennoai fennoai Bot deleted the codex/issue-294-auto-compact-threshold branch April 16, 2026 00:13
@wynxing

wynxing commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

/code 解决测试失败

@fennoai

fennoai Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

处理结果

已按“解决测试失败”完成修复并推送到当前 PR 工作分支。

修复内容

  • 修复 internal/runtime/run.go 中遗留的冲突标记(<<<<<<< / >>>>>>>)导致的编译错误。
  • 调整系统提醒注入逻辑为互斥优先级:
    • 先注入重复循环提醒;
    • 若已注入重复提醒,则跳过无进展提醒(符合现有测试约束)。
  • 新增 withSelfHealingRepeatReminder 辅助函数,并保持中文注释说明。

验证结果

  • go test ./internal/runtime 通过
  • go test ./... 通过

提交与推送

未完成项:无。

View job run

@wynxing wynxing closed this Apr 16, 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