fix(spawner): compact 检测 v5 — gateway log 开始标记 + jsonl 结束标记配对 #48
Reference in New Issue
Block a user
Delete Branch "fix/is-pr-detection"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
❌ REQUEST_CHANGES
数据验证发现
用实测 gateway log 验证了三种开始标记的匹配情况:
[context-overflow-precheck]+route=compact_then_truncatesessionKey=agent:xxx:main ... route=compact_then_truncateattempting auto-compaction(overflow)context overflow detected (attempt 1/3); attempting auto-compaction for zhipu/glm-5.1[timeout-compaction]+attempting(timeout)关键:
session_key not in msg前置过滤运行在 marker 匹配之前,导致不含 sessionKey 的 marker 被静默丢弃。🔴 必须修
M1. [spawner.py:1430-1436] sessionKey 前置过滤导致 overflow/timeout 开始标记为死代码
"attempting auto-compaction"消息不含 sessionKey → 被前置if session_key not in msg: continue过滤,永不匹配[timeout-compaction]标记是否含 sessionKey 无法验证(无实测数据),timeout 路径可能完全失效→ 修改方向:(a) 将 sessionKey 检查从前置过滤移入各 marker 分支内部,overflow/timeout 路径用时间窗口关联匹配含 sessionKey 的相邻日志行(如 precheck);或 (b) 如果确认 overflow 永远有 precheck 领先触发,删除 overflow/timeout 分支并注释说明只依赖 precheck
M2. [docs/design/24-compact-detection-fix.md] 设计文档仍描述 v4(trajectory prompt.submitted),代码实现 v5(gateway log + jsonl 配对),方案与实现不一致
→ 修改方向:更新 §24 设计文档,新增 v5 方案描述(开始标记检测规则、结束标记配对逻辑、三种 compact 路径覆盖分析),标记 v4 为 deprecated
🟡 建议改
S1. [tests/test_spawner_compact.py] v4 有 17 个单元测试覆盖
_check_compact_in_progress_trajectory,v5 新增 173 行在 spawner.py(高风险模块)无对应测试。建议补_find_compact_start_in_gateway_log和_check_compaction_finished_in_jsonl的单元测试S2. 分支名
fix/is-pr-detection是 PR #47 的分支,与 compact 检测内容不匹配。建议后续 PR 使用独立分支M1: overflow/timeout 标记不含 sessionKey,被前置过滤跳过是死代码。 precheck 总在 overflow 之前触发且含 sessionKey,已覆盖 overflow 场景。 删除 overflow/timeout 分支,只保留 precheck route=compact_then_truncate。 M2: §24 设计文档新增 v5 章节描述(方案概述、三种触发路径分析、为什么只依赖 precheck)。✅ APPROVED
M1 修复确认:overflow/timeout 死代码分支已删除,只保留 precheck
route=compact_then_truncate,docstring 详细说明了三种触发路径覆盖分析。与实测 gateway log 数据一致。M2 修复确认:§24 设计文档新增 v5 章节(§0.1-§0.4),含方案概述、三种路径分析表、为什么只依赖 precheck、超时兜底,v4 标记为 deprecated。
🟢 小问题(可选改进)
G1. [spawner.py:1651] 调度逻辑注释仍写 "overflow/timeout/precheck",但代码只检测 precheck。建议改为只写 precheck
G2. v5 新增 148 行(spawner.py 高风险模块)无单元测试,v4 有 17 个。建议后续补
_find_compact_start_in_gateway_log和_check_compaction_finished_in_jsonl的单元测试✅ 确认项:
Approve