infiniflow/ragflow · error · LookupError

Session not found!

Error message

Session not found!

What it means

LookupError raised in the canvas completion() flow when a session_id was supplied but API4ConversationService.get_by_id(session_id) returns nothing: the conversation/session row for that agent chat no longer exists. The session carries its own DSL copy, so a missing session cannot be resumed; callers should start a new session instead.

Source

Thrown at api/db/services/canvas_service.py:369

        if not isinstance(dsl, str):
            dsl = json.dumps(dsl, ensure_ascii=False)

        return cvs, dsl


async def completion(tenant_id, agent_id, session_id=None, **kwargs):
    query = kwargs.get("query", "") or kwargs.get("question", "")
    files = kwargs.get("files", [])
    inputs = kwargs.get("inputs", {})
    user_id = kwargs.get("user_id", "")
    chat_template_kwargs = kwargs.get("chat_template_kwargs")
    custom_header = kwargs.get("custom_header", "")
    release_mode = str(kwargs.get("release", "")).strip().lower()

    if session_id:
        e, conv = await thread_pool_exec(API4ConversationService.get_by_id, session_id)
        if not e:
            raise LookupError("Session not found!")
        if not conv.message:
            conv.message = []
        if not isinstance(conv.dsl, str):
            conv.dsl = json.dumps(conv.dsl, ensure_ascii=False)
        canvas = Canvas(conv.dsl, tenant_id, task_id=session_id, canvas_id=agent_id, custom_header=custom_header)
    else:
        cvs, dsl = await thread_pool_exec(UserCanvasService.get_agent_dsl_with_release, agent_id, release_mode=release_mode == "true", tenant_id=tenant_id)

        session_id = get_uuid()
        canvas = Canvas(dsl, tenant_id, task_id=session_id, canvas_id=cvs.id, custom_header=custom_header)
        canvas.reset()
        # Get the version title based on release_mode
        version_title = await thread_pool_exec(UserCanvasVersionService.get_latest_version_title, cvs.id, release_mode=release_mode == "true")
        conv = {"id": session_id, "dialog_id": cvs.id, "user_id": user_id, "message": [], "source": "agent", "dsl": dsl, "reference": [], "version_title": version_title}
        await thread_pool_exec(API4ConversationService.save, **conv)
        conv = API4Conversation(**conv)

    message_id = str(uuid4())

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Verify the session exists (API4ConversationService.get_by_id) before resuming; if gone, create a new session (omit session_id) and restart the conversation.
  2. If sessions are being purged, keep client-side session handles in sync or stop purging sessions still in use.
  3. Confirm you are passing the conversation/session id returned by a prior completion call, not the agent id.
  4. Catch LookupError in clients and silently start a fresh session.

Example fix

# before
resp = await completion(tenant_id, agent_id, session_id=old_session)

# after
exist, _ = await thread_pool_exec(API4ConversationService.get_by_id, old_session)
if not exist:
    old_session = None  # start a new session
resp = await completion(tenant_id, agent_id, session_id=old_session)
Defensive patterns

Strategy: fallback

Validate before calling

if session_id:
    exist, _ = await thread_pool_exec(API4ConversationService.get_by_id, session_id)
    if not exist:
        session_id = None  # start fresh instead of failing

Try / catch

try:
    resp = await completion(tenant_id, agent_id, session_id=sid)
except LookupError as e:
    if str(e) == "Session not found!":
        resp = await completion(tenant_id, agent_id)  # new session

Prevention

When it happens

Trigger: Calling the agent completion API with a session_id that was deleted (session cleared by the user), expired/purged, or belongs to another deployment; passing an agent id where a session id is expected.

Common situations: Chat history purged by the user or a retention job while a client still held the id; browser tab resumed after DB reset; scripts replaying recorded session ids against a fresh environment.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/b962174519411106. Report an issue: GitHub.