agentscope-ai/agentscope · warning · LookupError
Session '{session_id}' not found.
Error message
Session '{session_id}' not found. What it means
ChatService.interrupt raises LookupError when storage.get_session(user_id, agent_id, session_id) returns None, i.e. no session matches that triple. Because sessions are scoped per user and agent, a technically existing session id still fails if the user_id or agent_id in the call doesn't match the session's owner.
Source
Thrown at src/agentscope/app/_service/_chat.py:558
Args:
user_id (`str`):
Authenticated caller's user id.
session_id (`str`):
Target session id.
agent_id (`str`):
Agent that owns the session.
Raises:
LookupError:
The session does not exist.
"""
session = await self._storage.get_session(
user_id,
agent_id,
session_id,
)
if session is None:
raise LookupError(f"Session '{session_id}' not found.")
if await self._message_bus.is_locked(
MessageBusKeys.session_lock(session_id),
):
await self._message_bus.publish(
MessageBusKeys.session_interrupt_channel(),
{"session_id": session_id},
)
return
await enqueue_run_trigger(
self._message_bus,
user_id=user_id,
session_id=session_id,
agent_id=agent_id,
kind=MessageBusKeys.WAKEUP_KIND_RESUME,
inputs=UserInterruptEvent(reply_id=session.state.reply_id),
)View on GitHub (pinned to e90f1c7592)
Solutions
- Confirm the session exists via the session list/get endpoint for that exact user and agent before interrupting
- Check that user_id and agent_id in the call match the session's owners
- Refresh the session id from the current conversation state instead of caching it long-term
- Treat LookupError on interrupt as 'nothing to interrupt' and surface a friendly message
Example fix
# before
await chat_service.interrupt(user_id, agent_id, session_id) # LookupError
# after
if await storage.get_session(user_id, agent_id, session_id) is not None:
await chat_service.interrupt(user_id, agent_id, session_id)
else:
logger.info("Session already gone; nothing to interrupt") Defensive patterns
Strategy: try-catch
Validate before calling
session = await chat_client.get_session(user_id, agent_id, session_id)
if session is None:
logger.info("Session gone; nothing to interrupt")
return
await chat_client.interrupt(user_id, agent_id, session_id) Try / catch
try:
await chat_service.interrupt(user_id, agent_id, session_id)
except LookupError:
pass # session already ended; nothing to interrupt Prevention
- Match user_id and agent_id exactly to the session's owners
- Expire cached session ids in the client so stale interrupts aren't sent
When it happens
Trigger: Calling the session interrupt endpoint with a session_id that doesn't exist, or with a mismatched user_id/agent_id pair (e.g. interrupting another user's session or passing the wrong agent).
Common situations: Stale session ids held in a frontend after the session ended and was cleaned up; retrying an interrupt after the run completed and the session was reaped; passing an admin user_id while the session belongs to a regular user; copy-pasting ids across environments.
Related errors
- Session {session_id!r} not found.
- Session {session_id!r} already has an active chat run in thi
- Session {session_id!r} not found for agent {agent_id!r}.
- Knowledge base {knowledge_base_id!r} not found.
- Credential {record.data.embedding_model_config.credential_id
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/8096696ec10d3451.
Report an issue: GitHub.