fix(compact): 修复会话压缩系统六项缺陷并扩展两项可配置性#270
Conversation
合并 main 分支引入的 decodeCompactSummaryResponse 严格解码、 extractJSONObjectCandidate 候选遍历、ClampTaskStateBoundaries 边界限幅,同时保留本分支的容忍解析与 reactive compact 降级策略。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
/simplify |
Result已按触发评论完成:读取历史评论、评估未解决 review comment、修复值得修复的问题,并执行代码简化。 What I changed
Validation
Git
Notes
|
- escape TaskState line breaks before prompt rendering - use strict decoder during compact JSON candidate scan - add regressions for injection-safe rendering and strict-candidate fallback - apply low-risk simplifications in touched files Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
fix(compact): address review findings and simplify parsing/rendering
|
/review |
|
/simplify |
Result已完成你触发评论要求的全部步骤:读取历史评论、评估未解决 review comment、修复值得修复的问题,并执行代码简化。 What I changed
Validation
Git
Not done
|
…sembly Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
fix(compact): enforce strict archived prompt cap
|
/review |
There was a problem hiding this comment.
Found 2 noteworthy issues in this PR.
Also note: behavior/docs drift appears in reactive compact retry semantics and compact_done payload (before_tokens) but those doc files are not part of this diff, so I’m leaving that as a summary note instead of inline comments.
| MaxSummaryChars int `yaml:"max_summary_chars,omitempty"` | ||
| MicroCompactDisabled bool `yaml:"micro_compact_disabled,omitempty"` | ||
| MicroCompactRetainedToolSpans int `yaml:"micro_compact_retained_tool_spans,omitempty"` | ||
| MaxArchivedPromptChars int `yaml:"max_archived_prompt_chars,omitempty"` |
There was a problem hiding this comment.
CompactConfig adds micro_compact_retained_tool_spans / max_archived_prompt_chars, but the YAML persistence mapping is not updated (persistedCompactConfig, newPersistedContextConfig, fromPersistedContextConfig in internal/config/loader.go). With KnownFields(true), users configuring these keys will hit unknown-field parse failures, and values also cannot round-trip through save/load.
Please wire both fields through loader read/write structs and add config load/save tests for these keys.
| // cloneStringSlice 复制字符串切片,避免结果复用解析对象的底层数组。 | ||
| func cloneStringSlice(items []string) []string { | ||
| return append([]string(nil), items...) | ||
| // coerceStringArray 尝试将 json.RawMessage 解析为 []string,容忍单个 string 值。 |
There was a problem hiding this comment.
coerceStringArray currently downgrades type errors (number/object/bool/malformed array) to nil, which means malformed model output can silently clear durable task_state list fields (e.g. user_constraints, blockers) while still passing overall parsing.
Consider failing parse on non-[]string / non-string values (or preserving previous field values on invalid types) to avoid silent state loss.
|
/simplify |
Result已按本次 What I changed
Validation
Git
Not done
|
- wire compact extended fields through loader persistence - reject invalid compact task_state list value types to avoid silent data loss - add loader/load-save tests for new compact keys - simplify loader provider assembly and loader tests helper Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
fix(compact): resolve unresolved review findings and harden parsing
Summary
会话压缩(compact)系统存在 6 个功能缺陷和 2 个可配置性不足,本 PR 逐一修复并扩展。
缺陷修复
normalizeTaskStateList用strings.ToLower去重,误杀大小写不同项(如 React/react)"progress": "item"代替数组时json.Unmarshal直接报错tolerantSummaryResponse+coerceStringArray容忍解析sanitizePromptTaskStateText将所有空白(含换行)折叠为单空格,丢失结构\n,仅折叠行内空白和控制字符bool→int计数器,最多 3 次逐步减半ManualKeepRecentMessages降级重试.neocode/projects/下无限累积Cleanup方法,保留最近 50 个,删除最旧文件BeforeChars/AfterChars,与 token 限制脱节Metrics新增BeforeTokens,从 session 的TokenInputTotal填充可配置性扩展
microCompactRetainedToolSpans从硬编码常量 2 改为CompactConfig.MicroCompactRetainedToolSpans配置项CompactConfig.MaxArchivedPromptChars,超限时在消息边界截断 archived material 并前置提示Test plan
go build ./...编译通过go test ./...全部通过gofmt -w ./cmd ./internal格式化通过task_state_test.go(D3)、compact_generator_test.go(D5)、transcript_store_test.go(D6)、runtime_internal_helpers_test.go(D2)source_task_state_test.go(D4)、runtime_test.go(D2 行为变更)、microcompact_test.go(O1 签名变更)