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
4 changes: 1 addition & 3 deletions gateway/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,7 @@ def suspend_recently_active(self, max_age_seconds: int = 120) -> int:
to avoid resetting long-idle sessions that are harmless to resume.
Returns the number of sessions that were suspended.
"""
import time as _time

cutoff = _time.time() - max_age_seconds
cutoff = _now() - timedelta(seconds=max_age_seconds)
count = 0
with self._lock:
self._ensure_loaded_locked()
Expand Down
47 changes: 47 additions & 0 deletions tests/gateway/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,53 @@ def test_update_session_zero_resets(self, tmp_path):
store.update_session("k1", last_prompt_tokens=0)
assert entry.last_prompt_tokens == 0


class TestSuspendRecentlyActive:
def test_suspends_only_recent_sessions(self, tmp_path):
"""Startup suspension should only mark recently updated sessions."""
from datetime import datetime, timedelta
from gateway.session import SessionEntry

config = GatewayConfig()
with patch("gateway.session.SessionStore._ensure_loaded"):
store = SessionStore(sessions_dir=tmp_path, config=config)
store._loaded = True
store._db = None
store._save = MagicMock()

recent_entry = SessionEntry(
session_key="recent",
session_id="s1",
created_at=datetime.now() - timedelta(minutes=1),
updated_at=datetime.now() - timedelta(seconds=30),
)
old_entry = SessionEntry(
session_key="old",
session_id="s2",
created_at=datetime.now() - timedelta(hours=1),
updated_at=datetime.now() - timedelta(minutes=10),
)
already_suspended_entry = SessionEntry(
session_key="suspended",
session_id="s3",
created_at=datetime.now(),
updated_at=datetime.now(),
suspended=True,
)
store._entries = {
"recent": recent_entry,
"old": old_entry,
"suspended": already_suspended_entry,
}

suspended = store.suspend_recently_active(max_age_seconds=120)

assert suspended == 1
assert recent_entry.suspended is True
assert old_entry.suspended is False
assert already_suspended_entry.suspended is True
store._save.assert_called_once()

class TestRewriteTranscriptPreservesReasoning:
"""rewrite_transcript must not drop reasoning fields from SQLite."""

Expand Down