[claude] Fix cycle-metrics pipeline: seed issue= from queue so retro is never null (#1250) (#1253)
Some checks failed
Tests / lint (push) Has been cancelled
Tests / test (push) Has been cancelled

This commit was merged in pull request #1253.
This commit is contained in:
2026-03-23 23:42:23 +00:00
parent f62220eb61
commit 35d2547a0b
2 changed files with 180 additions and 0 deletions

View File

@@ -240,9 +240,33 @@ def compute_backoff(consecutive_idle: int) -> int:
return min(BACKOFF_BASE * (BACKOFF_MULTIPLIER ** consecutive_idle), BACKOFF_MAX)
def seed_cycle_result(item: dict) -> None:
"""Pre-seed cycle_result.json with the top queue item.
Only writes if cycle_result.json does not already exist — never overwrites
agent-written data. This ensures cycle_retro.py can always resolve the
issue number even when the dispatcher (claude-loop, gemini-loop, etc.) does
not write cycle_result.json itself.
"""
if CYCLE_RESULT_FILE.exists():
return # Agent already wrote its own result — leave it alone
seed = {
"issue": item.get("issue"),
"type": item.get("type", "unknown"),
}
try:
CYCLE_RESULT_FILE.parent.mkdir(parents=True, exist_ok=True)
CYCLE_RESULT_FILE.write_text(json.dumps(seed) + "\n")
print(f"[loop-guard] Seeded cycle_result.json with issue #{seed['issue']}")
except OSError as exc:
print(f"[loop-guard] WARNING: Could not seed cycle_result.json: {exc}")
def main() -> int:
wait_mode = "--wait" in sys.argv
status_mode = "--status" in sys.argv
pick_mode = "--pick" in sys.argv
state = load_idle_state()
@@ -269,6 +293,17 @@ def main() -> int:
state["consecutive_idle"] = 0
state["last_idle_at"] = 0
save_idle_state(state)
# Pre-seed cycle_result.json so cycle_retro.py can resolve issue=
# even when the dispatcher doesn't write the file itself.
seed_cycle_result(ready[0])
if pick_mode:
# Emit the top issue number to stdout for shell script capture.
issue = ready[0].get("issue")
if issue is not None:
print(issue)
return 0
# Queue empty — apply backoff