lfnovo/open-notebook · error · HTTPException

Error deleting session: {str(e)}

Error message

Error deleting session: {str(e)}

What it means

Generic 500 from DELETE /chat/sessions/{session_id} when deletion fails unexpectedly. Cause logged as 'Error deleting session: ...'.

Source

Thrown at api/routers/chat.py:301

@router.delete("/chat/sessions/{session_id}", response_model=SuccessResponse)
async def delete_session(session_id: str):
    """Delete a chat session."""
    try:
        # Get session (normalizes the ID and 404s if missing)
        _full_session_id, session = await get_session_or_404(session_id)

        await session.delete()

        return SuccessResponse(success=True, message="Session deleted successfully")
    except NotFoundError:
        raise HTTPException(status_code=404, detail="Session not found")
    except HTTPException:
        raise
    except OpenNotebookError:
        raise
    except Exception as e:
        logger.error(f"Error deleting session: {str(e)}")
        raise HTTPException(status_code=500, detail=f"Error deleting session: {str(e)}")


@router.post("/chat/execute", response_model=ExecuteChatResponse)
async def execute_chat(request: ExecuteChatRequest):
    """Execute a chat request and get AI response."""
    try:
        # Verify session exists (normalizes the ID and 404s if missing)
        full_session_id, session = await get_session_or_404(request.session_id)

        # Fetch notebook linked to this session
        notebook_query = await repo_query(
            "SELECT out FROM refers_to WHERE in = $session_id",
            {"session_id": ensure_record_id(full_session_id)},
        )
        notebook = None
        if notebook_query:
            notebook = await Notebook.get(notebook_query[0]["out"])

View on GitHub (pinned to a7de90d38a)

Solutions

  1. Check the API log for the underlying exception
  2. Verify SurrealDB is reachable and healthy
  3. Retry after confirming the session exists; if it fails persistently, remove the row directly in SurrealDB
Defensive patterns

Strategy: retry

Try / catch

catch (e) { if (e.status === 500) { await sleep(500); await deleteSession(id); } else throw e; }

Prevention

When it happens

Trigger: SurrealDB connection failure during delete, or record link/constraint errors preventing removal of the session row.

Common situations: DB outage, permission or namespace issues on the SurrealDB instance, orphaned references from other tables.

Related errors


AI-assisted analysis of lfnovo/open-notebook@a7de90d38a (2026-08-27). Data as JSON: /api/errors/2d1ac1bdcf96a734. Report an issue: GitHub.