Skip to content

refactor(context): 引入 MicroCompactConfig 聚合结构,收敛 Builder 构造函数链#447

Closed
Yumiue wants to merge 2 commits into1024XEngineer:mainfrom
Yumiue:refactor/micro-compact-config-aggregation
Closed

refactor(context): 引入 MicroCompactConfig 聚合结构,收敛 Builder 构造函数链#447
Yumiue wants to merge 2 commits into1024XEngineer:mainfrom
Yumiue:refactor/micro-compact-config-aggregation

Conversation

@Yumiue
Copy link
Copy Markdown
Collaborator

@Yumiue Yumiue commented Apr 24, 2026

目标

回应 #416 中关于「context 模块微压缩策略配置复杂」的痛点,引入 MicroCompactConfig 聚合结构,收敛 DefaultBuilder 的 5 个构造函数为统一入口。

改动内容

  • 新增 MicroCompactConfig 聚合结构,打包 Policies/Summarizers/PinChecker 三个接口
  • 新增 NewConfiguredBuilder 统一构造入口,支持可变 SectionSource
  • newPromptSources 改为接受 ...SectionSource 可变参数,nil 自动跳过
  • 旧构造函数保留并标记 Deprecated,委托到新入口
  • 更新 bootstrap.go 和 runtime.go 使用新构造 API
  • 补充 TestNewConfiguredBuilder 覆盖 5 个子场景

关于 #416 其余提案的评估

# 提案 判定 理由
2 增强记忆注入机制 不合理 memo 已通过 SectionSource 统一注入,动态优先级管理属过度设计
3 扩展 session 状态管理 不合理 TaskState(8字段)+TodoItem(完整状态机)已覆盖需求
4 引入事件驱动架构 不合理 已有 RuntimeEventStreamRelayTUI 完整事件链路

关联: #416

- 新增 MicroCompactConfig 结构体,将 MicroCompactPolicySource、
  MicroCompactSummarizerSource、MicroCompactPinChecker 三个接口
  打包为单一配置对象,简化 Builder 构造参数
- 新增 NewConfiguredBuilder 作为统一构造入口,支持可变 SectionSource
- newPromptSources 改为接受 ...SectionSource 可变参数,nil 自动跳过
- 旧构造函数保留并标记 Deprecated,委托到新入口
- 更新 bootstrap.go 和 runtime.go 使用新构造 API
- 补充 TestNewConfiguredBuilder 覆盖 5 个子场景

关联: 1024XEngineer#416
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copy link
Copy Markdown

@fennoai fennoai Bot left a comment

Choose a reason for hiding this comment

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

Completed 4 review passes on changed diff (code quality, performance, security, documentation accuracy). One maintainability finding is included below.

Comment thread internal/context/builder.go Outdated
@@ -22,55 +20,78 @@ func newDefaultBuilder(
summarizers MicroCompactSummarizerSource,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

newDefaultBuilder appears to be unused after introducing NewConfiguredBuilder (no call sites found). Keeping an unreferenced constructor increases maintenance surface and can confuse future call-path tracing. Consider removing it or routing one public constructor through it to keep a single assembly path.

@Yumiue
Copy link
Copy Markdown
Collaborator Author

Yumiue commented Apr 24, 2026

/simplify

@fennoai
Copy link
Copy Markdown

fennoai Bot commented Apr 24, 2026

Result

已完成你在 /simplify 里的要求,并处理了历史评论中的未解决项。

已执行内容:

  • 读取历史评论并评估未解决 review(仅 1 条):internal/context/builder.gonewDefaultBuilder 未被调用。
  • 采纳并修复该问题:删除未使用的 newDefaultBuilder
  • 按要求使用 code-simplifier 复核,并进一步做了等价简化:合并 applyReadTimeContextProjection 中重复的返回路径,保持行为不变。
  • 验证:go test ./... 通过;go test ./internal/context 通过。

提交与推送:

未执行项:

  • 无。

View job run

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 97.36842% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/context/builder.go 96.55% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
@fennoai fennoai Bot deleted the refactor/micro-compact-config-aggregation branch April 24, 2026 13:26
@phantom5099
Copy link
Copy Markdown
Collaborator

@xgopilot 审查性review,先确认有没有完成目标任务,再看看有没有引入新问题或是行为上的退化

@fennoai
Copy link
Copy Markdown

fennoai Bot commented Apr 24, 2026

Review Findings

  1. 中风险:runtime 默认上下文构造语义发生变化,可能引入行为退化
    文件:internal/runtime/runtime.go:181
    该 PR 将 NewWithFactorycontextBuilder == nil 时的默认行为从 NewBuilderWithToolPolicies(toolManager) 改为 NewConfiguredBuilder(MicroCompactConfig{Policies: toolManager, Summarizers: toolManager})
    这会让“仅注入 toolManager、未显式注入 contextBuilder”的调用路径开始启用 summarizer(若 toolManager 实现了 summarizer),从而把原本会被清空的旧工具结果改为摘要文本,属于可见行为变化。
    风险点:可能影响既有 prompt 体积/内容最小化假设;且本 PR 未新增覆盖该默认路径语义变化的 runtime 回归测试。
    建议:若非明确设计变更,恢复旧默认(仅 Policies);若为有意变更,补充 runtime 层回归测试并在 PR 描述中明确标注行为变更。

目标完成度检查

  • 已完成 MicroCompactConfig 聚合结构引入。
  • 已完成 NewConfiguredBuilder 统一构造入口与可变 SectionSource
  • 旧构造函数已保留并委托到新入口(标注 Deprecated)。
  • bootstrap.goruntime.go 已切换到新 API。
  • TestNewConfiguredBuilder 已覆盖 5 个子场景。

结论

  • 目标任务总体已完成。
  • 需要确认并处理上述 runtime 默认构造语义变化,避免无意行为退化。

View job run

@fennoai fennoai Bot mentioned this pull request Apr 24, 2026
@Yumiue Yumiue closed this Apr 25, 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.

3 participants