diff --git a/pm-stack/opencode-claimant/claimant.py b/pm-stack/opencode-claimant/claimant.py index f6150f3fcc..673aceb9cc 100755 --- a/pm-stack/opencode-claimant/claimant.py +++ b/pm-stack/opencode-claimant/claimant.py @@ -99,8 +99,13 @@ def ensure_state_dir() -> None: STATE_DIR.mkdir(parents=True, exist_ok=True) -def log_fire(mode: str, candidates: List[Dict], launched: List[Dict], cap_room: int, skips: List[Dict]) -> None: - """Append a fire log entry to fires.jsonl.""" +def log_fire(mode: str, candidates: List[Dict], launched: List[Dict], cap_room: "int | None", skips: List[Dict]) -> None: + """Append a fire log entry to fires.jsonl. + + cap_room is the measured available-slot count, or None when the + fire exited before the cap step ran (#7732): null means unknown, + never a placeholder 0, which would read as a saturated fleet. + """ ensure_state_dir() fire_entry = { @@ -754,7 +759,7 @@ def main(): if not has_candidates: print("No unbound opencode-lane candidates found. Exiting.") - log_fire(mode, [], [], 0, [{"reason": "no_candidates"}]) + log_fire(mode, [], [], None, [{"reason": "no_candidates"}]) return 0 # Step 3: Cap diff --git a/pm-stack/opencode-claimant/test_claimant.py b/pm-stack/opencode-claimant/test_claimant.py index 45d53bcda4..410cef20dd 100644 --- a/pm-stack/opencode-claimant/test_claimant.py +++ b/pm-stack/opencode-claimant/test_claimant.py @@ -417,5 +417,26 @@ def poll_stub(): [{"task_id": 777, "reason": "task_state_changed"}]) +class TestGateExitFireLog(unittest.TestCase): + def test_gate_exit_logs_cap_room_null_not_zero(self): + # #7732: a fire that exits at the gate never ran cap_step, so + # its cap_room is unknown (null) - a hardcoded 0 would read as + # a saturated fleet in fires.jsonl. + with tempfile.TemporaryDirectory() as tmp: + state_dir = Path(tmp) + fires = state_dir / "fires.jsonl" + with patch.object(claimant, "read_mode", return_value="shadow"), \ + patch.object(claimant, "run_poll", + return_value={"candidates": []}), \ + patch.object(claimant, "STATE_DIR", state_dir), \ + patch.object(claimant, "FIRES_FILE", fires): + self.assertEqual(claimant.main(), 0) + entries = [json.loads(line) + for line in fires.read_text().splitlines() if line] + self.assertEqual(len(entries), 1) + self.assertIsNone(entries[0]["cap_room"]) + self.assertEqual(entries[0]["skips"], [{"reason": "no_candidates"}]) + + if __name__ == "__main__": unittest.main()