Skip to content
Closed
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
15 changes: 10 additions & 5 deletions pm-stack/opencode-claimant/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
10 changes: 10 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,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:
Expand Down
Loading