Notebooks Endpoint 500 Error Fix

← All Specs

Notebooks Endpoint 500 Error Fix

Task ID: 8d169dae-68d5-46cb-9f9c-d6b391936cbb Layer: [Forge] / [UI] Priority: 95

Goal

Fix the /notebooks endpoint which is returning a 500 Internal Server Error due to missing database columns. The route handler expects columns that don't exist in the notebooks table schema.

Root Cause

The notebooks table schema is incomplete. The route handler in api.py:1516 queries for:

  • associated_analysis_id (actual column: analysis_id)
  • associated_entities (missing)
  • rendered_html_path (missing)
  • description (missing)

Current schema only has: id, title, path, analysis_id, created_at

Acceptance Criteria

☑ ~~Add missing columns to notebooks table~~ (already present)
☑ ~~Update query to use correct column name~~ (already correct)
/notebooks endpoint returns 200 OK
☑ Empty state displays correctly (0 notebooks currently)
☑ No errors in API logs when accessing /notebooks

Approach

  • Check current notebooks table schema
  • Add missing columns via ALTER TABLE statements:
  • - description TEXT
    - associated_entities TEXT (JSON array of entity names)
    - rendered_html_path TEXT
  • Update the SQL query in api.py line 1519 from n.associated_analysis_id to n.analysis_id
  • Test endpoint: curl http://localhost/notebooks should return 200
  • Verify no errors in logs
  • Commit changes
  • Work Log

    2026-04-01 20:50 PT — Slot 0

    • Started task investigation
    • Found root cause: sqlite3.OperationalError: no such column: n.associated_analysis_id in API logs (from 20:49 timeframe)
    • Investigated database schema and api.py code
    • Finding: Issue was already resolved by another process/agent
    • Verified /notebooks endpoint now returns 200 OK
    • Verified database has correct schema: id, title, description, created_at, associated_analysis_id, associated_entities, rendered_html_path
    • Verified API code correctly uses associated_analysis_id to match database schema
    • Result: RESOLVED — Endpoint working, displays empty state correctly
    • No code changes needed

    2026-04-24 14:58 UTC — Verification (glm-5, retry 0)

    Task was reopened due to missing task_runs row. Re-verified all acceptance criteria:

    Evidence:

  • /notebooks returns 200 (default, cached, trailing slash, sort_by=title/analyses, tag filter — all 200)
  • /api/notebooks returns 200; /api/notebooks/{id} returns 200 for real notebook IDs
  • notebooks table has all 9 required columns: id, title, description, created_at, associated_analysis_id, associated_entities, rendered_html_path, tags, is_spotlight (34 columns total)
  • Table has 552 notebooks, spotlight query returns 5 rows
  • Global exception handler at api.py:1313 catches unhandled errors and returns styled 500 pages
  • Root cause was already fixed: Missing columns were added to the notebooks table by a prior migration. The route handler code correctly references associated_analysis_id matching the actual column name. No code changes needed — the fix is in the database schema, not in api.py.

    Verdict: Task already resolved on main. Closing as verified pass.

    File: 8d169dae-68d5-46cb-9f9c-d6b391936cbb_spec.md
    Modified: 2026-04-25 23:40
    Size: 3.1 KB