Skip to content

fix(context): 细化 micro compact 保留策略#611

Merged
phantom5099 merged 2 commits into1024XEngineer:mainfrom
Yumiue:html_progress
May 10, 2026
Merged

fix(context): 细化 micro compact 保留策略#611
phantom5099 merged 2 commits into1024XEngineer:mainfrom
Yumiue:html_progress

Conversation

@Yumiue
Copy link
Copy Markdown
Collaborator

@Yumiue Yumiue commented May 10, 2026

@

概要

本 PR 修复并细化了上下文微压缩(micro compact)的保留策略,解决三个问题:

1. 缺少专用摘要器的工具结果被静默清空

summarizeOrClear 在遇到未注册摘要器的工具时直接返回清空消息,导致历史信息丢失。现在会退化为最小可读摘要 [summary] toolName lines=N chars=M,保证工具执行历史始终有可见痕迹。

2. 文件操作 pin 判定覆盖不足

  • 新增 CopyFile / MoveFile 到默认 pin 工具列表
  • pin 路径匹配从单一字段扩展为多候选顺序检查:relative_path → path → source_path → destination_path,防止复制/移动操作的文件被过早回收

3. 工具输出截断丢弃尾部关键信息

原来的单点截断(仅保留前 600 字符)可能导致错误日志、堆栈信息等尾部关键内容丢失。改为头尾窗口保留(各 300 字符),中间用 ...[truncated]... 标记,确保 memo 提取时兼顾上下文与错误定位。

附带变更

  • ReadTool / SpawnSubagent 的 MicroCompactPolicy 调整为 Compact,避免其历史被无条件保留
  • projectedToolMetadataAllowlist 新增 source_path / destination_path 字段

测试

  • go build ./... 通过
  • go test ./internal/context/... 全部通过
  • 17 文件,+427 / -75

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

Found 2 noteworthy issues after code quality, performance, security, and documentation passes.

Comment thread internal/tools/format.go
Comment on lines +44 to +46
"source_path": {},
"status_code": {},
"destination_path": {},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium Adding source_path / destination_path to the projected metadata allowlist makes copy/move tool messages send absolute local filesystem paths back to the provider. filesystem_copy_file and filesystem_move_file currently persist src/dst as absolute paths, so this change leaks workspace layout and usernames into recent-window / memo-extraction context. Please normalize these fields to workspace-relative paths before allowlisting them, or keep them out of model-visible metadata.

Comment thread internal/tools/codebase/read.go Outdated

func (t *ReadTool) MicroCompactPolicy() tools.MicroCompactPolicy {
return tools.MicroCompactPolicyPreserveHistory
return tools.MicroCompactPolicyCompact
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium Switching codebase_read from PreserveHistory to Compact is a behavior change that drops previously-read source bodies down to path/line-count summaries. That is at odds with the current repository design contract (docs/repository-design.md, acceptance criterion 28), which explicitly relies on codebase_read being the implementation-bearing tool that stays available across compact while codebase_search_* can be summarized. If this policy change is intentional, the surrounding docs/prompt contract should be updated in the same PR; otherwise this weakens the "must verify via codebase_read" workflow.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

❌ Patch coverage is 79.31034% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/context/projection.go 66.66% 7 Missing and 3 partials ⚠️
internal/context/microcompact.go 71.42% 4 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@phantom5099 phantom5099 merged commit fb5f51c into 1024XEngineer:main May 10, 2026
2 of 3 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.

2 participants