[Senate] Fix /senate route 500 error

← All Specs

[Senate] Fix /senate route 500 error

Task ID: ec48be6e-f5fc-4a31-8580-ef3549d59416 Priority: P90 Layer: Senate

Goal

Fix the /senate route which is returning 500 Internal Server Error due to corrupted events table in the database. The route needs to load successfully and display Senate governance dashboard with system monitoring information.

Root Cause

The events table in PostgreSQL is corrupted, causing sqlite3.DatabaseError: database disk image is malformed when event_bus.get_event_stats() tries to query it. The corruption is specific to the events table - the rest of the database is intact.

Acceptance Criteria

/senate route returns HTTP 200
☐ Senate dashboard displays correctly with all monitoring sections
☐ Events table is rebuilt and functional
☐ Error handling added to prevent future crashes from similar issues
☐ Changes committed and pushed to branch

Approach

  • Diagnose the issue - Verify events table corruption
  • Fix the database - Drop and recreate the events table using init_events_table()
  • Add error handling - Wrap event bus calls in try-catch to prevent route crashes
  • Test - Verify /senate route loads successfully
  • Commit - Push changes with appropriate commit message
  • Work Log

    2026-04-01 22:41 PT — Slot 9

    Started task

    • Retrieved task from Orchestra (ID: ec48be6e-f5fc-4a31-8580-ef3549d59416)
    • Read AGENTS.md to understand spec requirements
    • Created spec file for this task
    Diagnosis
    • Tested /senate route → confirmed HTTP 500 error
    • Checked API logs → found sqlite3.DatabaseError: database disk image is malformed at event_bus.py:155
    • Verified database integrity → overall DB is OK
    • Verified events table exists → YES
    • Tested events table queries → confirmed corruption in events table specifically
    Root cause identified: The events table is corrupted, causing queries to fail with "database disk image is malformed" error.

    Implementation

    • Added try-catch error handling to get_event_bus_section() in api.py:1311
    • Function now gracefully handles database errors and displays error state instead of crashing
    • Returns user-friendly error message when events table is unavailable
    • Verified Python syntax → OK
    Testing
    • Cannot test until changes are merged and API is restarted
    • Changes are in worktree branch orchestra/task/29e52a20-ba54-434f-bac8-62af3c5b15f0
    • Main API running from /home/ubuntu/scidex still has old code
    Status: Ready to commit and merge. After merge, API restart required by operator.

    Note on root cause: The events table in the production database is corrupted. The immediate fix adds error handling so the Senate page doesn't crash. The events table should be rebuilt separately by running:

    import event_bus
    event_bus.init_events_table()

    Or by dropping and recreating the table manually after backing up any data.

    File: ec48be6e-f5fc-4a31-8580-ef3549d59416_spec.md
    Modified: 2026-05-01 20:13
    Size: 2.9 KB