lfnovo/open-notebook · error · HTTPException
Error fetching insight
Error message
Error fetching insight
What it means
Generic 500 from GET /api/insights/{insight_id} when an unexpected exception occurs — commonly inside insight.get_source() while following the insight→source relationship.
Source
Thrown at api/routers/insights.py:40
# Get source ID from the insight relationship
source = await insight.get_source()
return SourceInsightResponse(
id=insight.id or "",
source_id=source.id or "",
insight_type=insight.insight_type,
content=insight.content,
created=insight.created.isoformat() if insight.created else None,
updated=insight.updated.isoformat() if insight.updated else None,
)
except HTTPException:
raise
except OpenNotebookError:
raise
except Exception as e:
logger.error(f"Error fetching insight {insight_id}: {str(e)}")
raise HTTPException(status_code=500, detail="Error fetching insight")
@router.delete("/insights/{insight_id}")
async def delete_insight(insight_id: str):
"""Delete a specific insight."""
try:
insight = await SourceInsight.get(insight_id)
if not insight:
raise HTTPException(status_code=404, detail="Insight not found")
await insight.delete()
return {"message": "Insight deleted successfully"}
except HTTPException:
raise
except OpenNotebookError:
raise
except Exception as e:View on GitHub (pinned to a7de90d38a)
Solutions
- Check the log 'Error fetching insight <id>' for the traceback
- If the source was deleted leaving a dangling reference, delete/repair the orphaned insight
- Verify DB health and retry
- Fix migrations/relationships if get_source() consistently fails
Defensive patterns
Strategy: retry
Try / catch
try:
return await client.get(f"/api/insights/{insight_id}")
except httpx.HTTPStatusError as e:
if e.response.status_code >= 500:
await asyncio.sleep(1)
return await client.get(f"/api/insights/{insight_id}")
raise Prevention
- Delete insights when deleting their source to avoid dangling relationships
- Watch API logs — get_source() failures are visible with tracebacks
- Keep migrations consistent so insight→source edges stay valid
When it happens
Trigger: SourceInsight.get succeeds but get_source() fails: dangling source reference (source deleted first), DB connectivity error, or response model serialization failure.
Common situations: Source deleted while its insights remained; SurrealDB restart mid-request; schema drift after migration breaking relationship traversal.
Related errors
- Error saving insight as note
- Failed to fetch episode profiles
- Failed to fetch episode profile
- Error deleting insight
- Error fetching chat sessions: {str(e)}
AI-assisted analysis of lfnovo/open-notebook@a7de90d38a (2026-08-27).
Data as JSON: /api/errors/3145ddf66b02967f.
Report an issue: GitHub.