diff --git a/pm-stack/opencode-claimant/poll.py b/pm-stack/opencode-claimant/poll.py index 8a05d72a8e..e5369181fb 100755 --- a/pm-stack/opencode-claimant/poll.py +++ b/pm-stack/opencode-claimant/poll.py @@ -244,8 +244,9 @@ def is_root_session(s): def _active_root_state(s, now_ms, active_ids=None): """True (proven active), False (proven inactive), or None (the - entry's timing cannot be read, so its activity is UNKNOWN — see - _session_timing; #6868).""" + entry has neither an authoritative active-set membership nor a + readable timestamp/terminal marker, so its activity is UNKNOWN — + see _session_timing; #6868).""" if not is_root_session(s): return False # The server's active set is authoritative: a RESUMED session keeps @@ -255,12 +256,16 @@ 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 + # A terminal marker proves inactivity without a usable activity + # timestamp. Check it first so malformed updated/created values do + # not turn a known-finished root into UNKNOWN and block cap room. + 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 - idle, updated = timing - if idle or s.get("outcome"): - return False + _, updated = timing return now_ms - updated < ACTIVE_WINDOW_MS diff --git a/pm-stack/opencode-claimant/test_poll.py b/pm-stack/opencode-claimant/test_poll.py index 46bbe1dc22..de39691647 100755 --- a/pm-stack/opencode-claimant/test_poll.py +++ b/pm-stack/opencode-claimant/test_poll.py @@ -153,6 +153,16 @@ def test_summarize_cap_unknown_not_manufactured_room(self): self.assertIsNone(active) self.assertIsNone(room) + def test_terminal_marker_makes_malformed_timestamp_inactive(self): + finished = {"id": "ses_bad", "time": {"idle": 123, "updated": "bad"}} + live, active, room = poll.summarize_cap([finished], set(), NOW) + self.assertEqual((live, active, room), (1, 0, poll.CAP)) + + def test_outcome_makes_malformed_timestamp_inactive(self): + finished = {"id": "ses_bad", "time": {"updated": "bad"}, + "outcome": "failed"} + self.assertFalse(poll.is_active_root(finished, NOW, set())) + def test_is_stuck_bound_never_raises_and_never_stuck(self): row = TestIsStuckBound().row() for bad in self.BAD_TIMES: