Skip to content
Merged
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
10 changes: 8 additions & 2 deletions src/lab_harness/web/session_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,18 @@ def mark_done(self, session_id: str) -> None:
live.completed_at = time.time()

def cleanup(self) -> int:
"""Remove sessions that completed > TTL ago. Returns count removed."""
"""Remove sessions whose age since completion has reached the TTL. Returns count removed.

Uses ``>=`` so that a ``done_ttl_seconds`` of 0 expires sessions
immediately, even when the elapsed time is below the system clock's
resolution (a strict ``>`` left such sessions stuck forever on coarse
clocks).
"""
now = time.time()
to_remove = [
sid
for sid, live in self._sessions.items()
if live.done and live.completed_at and (now - live.completed_at) > self._done_ttl
if live.done and live.completed_at and (now - live.completed_at) >= self._done_ttl
]
for sid in to_remove:
del self._sessions[sid]
Expand Down
Loading