fix(harness): replace implicit .harness-active absence with explicit .harness-reflect marker for self-reflect triggering

Fixes two bugs:
- False positive: stale harness-tasks.json from previous runs triggered self-reflect when harness wasn't active
- False negative: self-reflect didn't trigger after harness completed all tasks

Generated with SWE-Agent.ai

Co-Authored-By: SWE-Agent.ai <noreply@swe-agent.ai>
This commit is contained in:
cexll
2026-03-02 00:30:34 +08:00
parent 683409464c
commit 08877af530
3 changed files with 54 additions and 14 deletions

View File

@@ -260,6 +260,11 @@ def main() -> int:
# If nothing left to do, allow stop
if not pending_eligible and not retryable and not in_progress_blocking:
_reset_block_counter(root)
# Signal self-reflect hook BEFORE removing active marker
try:
(root / ".harness-reflect").touch()
except Exception:
pass
try:
(root / ".harness-active").unlink(missing_ok=True)
except Exception:

View File

@@ -146,13 +146,15 @@ def main() -> int:
if not session_id:
return 0 # 无 session_id放行
# 守卫 1harness 从未初始化过 → 完全不触发自
# 守卫:仅当 harness 完成所有任务后(.harness-reflect 存在)才触发自
# 这避免了两个问题:
# 1. 历史残留的 harness-tasks.json 导致误触发false positive
# 2. harness-stop.py 移除 .harness-active 后 Claude Code 跳过后续 hookfalse negative
root = _find_harness_root(payload)
if root is None:
return 0 # harness 未曾使用,不触发自省
return 0
# 守卫 2harness 仍活跃 → 由 harness-stop.py 全权管理
if (root / ".harness-active").is_file():
if not (root / ".harness-reflect").is_file():
return 0
# 读取最大迭代次数
@@ -168,8 +170,12 @@ def main() -> int:
# 读取当前计数
count = _read_counter(session_id)
# 超过最大次数,放行
# 超过最大次数,清理 marker 并放行
if count >= max_iter:
try:
(root / ".harness-reflect").unlink(missing_ok=True)
except Exception:
pass
return 0
# 递增计数