infiniflow/ragflow · error · LookupError

100

100

Error message

Fail to create a session!

What it means

Raised in chat_api when creating a chat session with save_session enabled: ConversationService.save persisted the conversation but the immediate get_by_id lookup for the new conv['id'] returned ok=False. It means the session row could not be read back from the database right after insertion, so the API cannot return a session object.

Source

Thrown at api/apps/restful_apis/chat_api.py:225

    )


async def _create_session_for_completion(chat_id, dialog, user_id, save_session=True):
    conv = {
        "id": get_uuid(),
        "dialog_id": chat_id,
        "name": "New session",
        "message": [{"role": "assistant", "content": dialog.prompt_config.get("prologue", "")}],
        "user_id": user_id,
        "reference": [],
    }
    if not save_session:
        conv["id"] = None
        return SimpleNamespace(**conv)
    await thread_pool_exec(ConversationService.save, **conv)
    ok, conv_obj = await thread_pool_exec(ConversationService.get_by_id, conv["id"])
    if not ok:
        raise LookupError("Fail to create a session!")
    return conv_obj


def _get_bool_request_flag(req, *names, default=False):
    for name in names:
        if name not in req:
            continue
        value = req.pop(name)
        if isinstance(value, str):
            return value.strip().lower() in {"1", "true", "yes", "on"}
        return bool(value)
    return default


def _normalize_completion_messages(req):
    messages = req.get("messages")
    if messages is None:
        question = req.get("question")

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Check server logs for the underlying DB error around ConversationService.save (connection loss, deadlock, constraint failure).
  2. Retry the create-session request once — transient read-after-write failures often clear.
  3. Verify the database is healthy and not in a read-only or migration-pending state (check /system health endpoints).
  4. If it persists, inspect ConversationService.save to confirm it commits and returns/backfills conv['id'].
Defensive patterns

Strategy: retry

Validate before calling

async def healthcheck_db():
    ok, _ = await thread_pool_exec(ConversationService.get_by_id, "00000000-0000-0000-0000-000000000000")
    return ok is not None  # raises nothing, proves SELECT path works

# only attempt session creation when DB is reachable
if await healthcheck_db():
    conv = await create_session(chat_id, user_id)

Try / catch

for attempt in range(2):
    try:
        conv = await create_session(chat_id, user_id)
        break
    except LookupError as e:
        if "Fail to create a session" not in str(e) or attempt == 1:
            raise

Prevention

When it happens

Trigger: POST to create a chat session (or an internal completion flow that saves sessions) where the DB insert succeeds or silently fails and the follow-up SELECT by the generated conversation id finds no row — e.g. a transaction not committed, the id not backfilled by save(), or the row being deleted concurrently.

Common situations: Database connectivity glitches, a misconfigured Peewee/MySQL setup where auto-commit is off, the ConversationService.save implementation not setting the generated id, or concurrent cleanup jobs deleting sessions immediately.

Related errors


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