feat(spawner): §24 compact detection via gateway log rotation events
This commit is contained in:
@@ -233,20 +233,27 @@ def _revive_session(agent_id: str) -> bool:
|
||||
pass
|
||||
```
|
||||
|
||||
### 4.5 O5: compact 扫描条件收紧
|
||||
### 4.5 O5: compact 检测(§24 rotation-only v3)
|
||||
|
||||
当前 compact 扫描在 status 非 idle/done/unknown/None 时都触发,范围过宽。
|
||||
§24 设计文档:`docs/design/24-compact-detection-fix.md`
|
||||
|
||||
**改后**:只在 status 为 running 或 compacting 相关时扫描:
|
||||
**检测方法**:读 gateway 日志尾部 2MB,按 sessionKey 过滤 `[compaction] rotated active transcript` 事件。
|
||||
如果最近的 rotation 事件在 120s 窗口内 → 视为 compact 循环进行中(可能还在 post-compact retry)。
|
||||
|
||||
旧方法 `_check_recent_compaction_jsonl`(扫描 session jsonl 的 `type=compaction` 事件)保留作为 fallback。
|
||||
|
||||
```python
|
||||
# 只在这些状态下检查 compact
|
||||
if result["status"] in ("running",) and sf:
|
||||
result["recent_compact"] = AgentSpawner._check_recent_compaction_jsonl(sf)
|
||||
# §24 v3: compact 检测优先用 gateway 日志 rotation 事件
|
||||
if result["status"] not in ("done", "idle", "unknown", None):
|
||||
session_key = f"agent:{agent_id}:main"
|
||||
result["recent_compact"] = AgentSpawner._check_compact_in_progress_gateway(
|
||||
session_key)
|
||||
if not result["recent_compact"] and sf:
|
||||
result["recent_compact"] = AgentSpawner._check_recent_compaction_jsonl(sf)
|
||||
```
|
||||
|
||||
注:Gateway 的 sessions.json status 实际值主要是 `idle/running/timeout/failed`。
|
||||
`running` 时检查 compact 有意义(agent turn 执行中可能触发 compact)。
|
||||
非空闲状态(`running`/`timeout`/`failed`)时检查 compact 有意义。
|
||||
其他状态不需要检查。
|
||||
|
||||
## 五、改动范围
|
||||
|
||||
Reference in New Issue
Block a user