Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pm-stack/opencode-claimant/claimant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions pm-stack/opencode-claimant/test_claimant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading