fix(spawner): address PR#36 review feedback (M1+M2+S1+S2)
This commit is contained in:
@@ -244,7 +244,7 @@ def _revive_session(agent_id: str) -> bool:
|
||||
|
||||
```python
|
||||
# §24 v3: compact 检测优先用 gateway 日志 rotation 事件
|
||||
if result["status"] not in ("done", "idle", "unknown", None):
|
||||
if result["status"] not in ("idle", "unknown", None):
|
||||
session_key = f"agent:{agent_id}:main"
|
||||
result["recent_compact"] = AgentSpawner._check_compact_in_progress_gateway(
|
||||
session_key)
|
||||
|
||||
@@ -45,11 +45,15 @@ Gateway 日志中 `[compaction] rotated active transcript after compaction (sess
|
||||
```
|
||||
1. 读 gateway 日志(当天 + 昨天尾部)
|
||||
2. 按目标 sessionKey 过滤 compact 相关事件
|
||||
3. 从后往前找最后一条相关事件:
|
||||
a. 如果是 rotation 且 < N 秒(建议 120s)→ compact=True
|
||||
3. 从后往前找最后一条 rotation 事件:
|
||||
a. 如果 rotation 事件在窗口内(< 120s)→ compact=True
|
||||
(刚完成一轮 compact,可能还在 post-compact retry 循环中)
|
||||
b. 如果是 model.completed 或其他正常事件 → compact=False
|
||||
c. 超出时间窗口 → compact=False
|
||||
b. 无 rotation 事件或超出时间窗口 → compact=False
|
||||
|
||||
**注意:此方案仅检查 rotation 事件,不检查 model.completed 等其他事件。**
|
||||
这是有意为之的保守策略:不检查正常 turn 事件意味着 compact 完成后的
|
||||
120s 内都可能被误判为 compact 进行中,但误判代价低(仅 skip 一轮 ticker),
|
||||
宁可多拦也不漏放。
|
||||
```
|
||||
|
||||
**为什么 rotation + 时间窗口就够了?**
|
||||
@@ -97,8 +101,7 @@ def _check_compact_in_progress_gateway(self, session_key: str, window_seconds: i
|
||||
now = datetime.now(timezone.utc)
|
||||
window_start = now - timedelta(seconds=window_seconds)
|
||||
|
||||
last_event_type = None
|
||||
last_event_time = None
|
||||
last_rotation_time = None
|
||||
|
||||
for log_path in log_paths:
|
||||
if not os.path.exists(log_path):
|
||||
@@ -127,14 +130,13 @@ def _check_compact_in_progress_gateway(self, session_key: str, window_seconds: i
|
||||
if "[compaction] rotated active transcript" in msg:
|
||||
try:
|
||||
event_time = datetime.fromisoformat(ts_str)
|
||||
if event_time > last_event_time if last_event_time else True:
|
||||
last_event_time = event_time
|
||||
last_event_type = "rotation"
|
||||
if last_rotation_time is None or event_time > last_rotation_time:
|
||||
last_rotation_time = event_time
|
||||
except (ValueError, TypeError):
|
||||
continue
|
||||
|
||||
if last_event_type == "rotation" and last_event_time:
|
||||
return last_event_time >= window_start
|
||||
if last_rotation_time is not None:
|
||||
return last_rotation_time >= window_start
|
||||
|
||||
return False
|
||||
```
|
||||
@@ -174,7 +176,7 @@ if compact:
|
||||
| 日志文件不存在 | 返回 False(fallback 到旧方法) |
|
||||
| 跨天 compact | 同时检查昨天日志尾部 |
|
||||
| compact 失败(无 rotation) | rotation 事件不会出现 → 检测不到 → 回退到旧方法 |
|
||||
| 误判(compact 完成后正常工作中) | 时间窗口 120s 内正常 turn 的 model.completed 事件会覆盖 rotation |
|
||||
| 误判(compact 完成后正常工作中) | 时间窗口 120s 内可能被误判,但代价低(skip 一轮 ticker)。不检查正常 turn 事件,是保守策略 |
|
||||
|
||||
## 6. 测试验证
|
||||
|
||||
|
||||
Reference in New Issue
Block a user