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
9 changes: 9 additions & 0 deletions pm-stack/opencode-claimant/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ def _active_root_state(s, now_ms, active_ids=None):
# counts the root no matter what its stored markers say.
if active_ids is not None and s.get("id") in active_ids:
return True
# Terminal markers are decidable without a readable clock
# (#8853): a finished root stays finished even when its
# timestamps are malformed — checking timing first made one
# such root report the whole cap unknown and block every
# launch. A root with malformed timing and NO terminal marker
# still falls through to the fail-closed None below.
t = s.get("time")
if (isinstance(t, dict) and t.get("idle")) or s.get("outcome"):
return False
timing = _session_timing(s)
if timing is None:
return None
Expand Down
21 changes: 21 additions & 0 deletions pm-stack/opencode-claimant/test_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,27 @@ def test_summarize_cap_unknown_not_manufactured_room(self):
self.assertIsNone(active)
self.assertIsNone(room)

def test_terminal_marker_with_malformed_timing_is_inactive(self):
# #8853 (oracle: the acceptance example on issue #8853): a
# finished root's malformed timestamp must not make the cap
# unknown — the terminal marker is checked before timing.
s = {"id": "ses_done", "time": {"idle": 123, "updated": "bad"}}
self.assertIs(poll._active_root_state(s, NOW, set()), False)
self.assertEqual(poll.count_active_roots([s], NOW, set()), 0)
live, active, room = poll.summarize_cap([root(), s], set(), NOW)
self.assertEqual((live, active, room), (2, 1, poll.CAP - 1))

def test_outcome_with_malformed_timing_is_inactive(self):
s = {"id": "ses_done", "time": {"updated": "bad"},
"outcome": "failed"}
self.assertIs(poll._active_root_state(s, NOW, set()), False)

def test_active_set_still_overrides_terminal_marker(self):
# A resumed session in the server's active set counts active
# even with a stored terminal marker and malformed timing.
s = {"id": "ses_done", "time": {"idle": 123, "updated": "bad"}}
self.assertIs(poll._active_root_state(s, NOW, {"ses_done"}), True)

def test_is_stuck_bound_never_raises_and_never_stuck(self):
row = TestIsStuckBound().row()
for bad in self.BAD_TIMES:
Expand Down
Loading