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
10 changes: 9 additions & 1 deletion plugins/platforms/slack/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3806,7 +3806,15 @@ def _has_active_session_for_thread(
)

session_store._ensure_loaded()
return session_key in session_store._entries
entry = session_store._entries.get(session_key)
if entry is None:
return False

should_reset = getattr(type(session_store), "_should_reset", None)
if callable(should_reset) and should_reset(session_store, entry, source):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_should_reset() is only one part of the routing freshness decision. SessionStore._get_or_create_session_impl() also invalidates DB-ended sessions, suspended entries, and expired resume_pending entries (gateway/session.py:1870-1884), so this still returns true for keys that the next routing step will replace.

return False

return True
except Exception:
return False

Expand Down
25 changes: 25 additions & 0 deletions tests/gateway/test_slack_approval_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,31 @@ def test_no_session_store(self):
)
assert result is False

def test_stale_session_returns_false(self):
adapter = _make_adapter()

class Store:
config = MagicMock()
config.group_sessions_per_user = False
config.thread_sessions_per_user = False
_entries = {
"agent:main:slack:group:C1:1000.0": MagicMock()
}

def _ensure_loaded(self):
return None

def _should_reset(self, entry, source):
return "idle"

adapter._session_store = Store()

result = adapter._has_active_session_for_thread(
channel_id="C1", thread_ts="1000.0", user_id="U123"
)

assert result is False


# ===========================================================================
# Thread engagement — bot-started threads & mentioned threads
Expand Down