[Agora] Add spectator mode and real-time debate streaming to /debates page done analysis:5

← Open Debates
## REOPENED TASK — CRITICAL CONTEXT This task was previously marked 'done' but the audit could not verify the work actually landed on main. The original work may have been: - Lost to an orphan branch / failed push - Only a spec-file edit (no code changes) - Already addressed by other agents in the meantime - Made obsolete by subsequent work **Before doing anything else:** 1. **Re-evaluate the task in light of CURRENT main state.** Read the spec and the relevant files on origin/main NOW. The original task may have been written against a state of the code that no longer exists. 2. **Verify the task still advances SciDEX's aims.** If the system has evolved past the need for this work (different architecture, different priorities), close the task with reason "obsolete: " instead of doing it. 3. **Check if it's already done.** Run `git log --grep=''` and read the related commits. If real work landed, complete the task with `--no-sha-check --summary 'Already done in '`. 4. **Make sure your changes don't regress recent functionality.** Many agents have been working on this codebase. Before committing, run `git log --since='24 hours ago' -- ` to see what changed in your area, and verify you don't undo any of it. 5. **Stay scoped.** Only do what this specific task asks for. Do not refactor, do not "fix" unrelated issues, do not add features that weren't requested. Scope creep at this point is regression risk. If you cannot do this task safely (because it would regress, conflict with current direction, or the requirements no longer apply), escalate via `orchestra escalate` with a clear explanation instead of committing.

Completion Notes

Auto-completed by supervisor after successful deploy to main

Git Commits (2)

[Agora] Update spec work log — fix commit message for api.py mention [task:be358f25e574]2026-04-18
[Agora] Add spectator mode and real-time debate streaming to /debates [task:be358f25e574]2026-04-18
Spec File

[Agora] Add spectator mode and real-time debate streaming to /debates page

Quest: Open Debates Priority: P2 Status: open

Goal

Add spectator mode and real-time debate streaming to /debates page

Context

This task is part of the Open Debates quest (Agora layer). It contributes to the broader goal of building out SciDEX's agora capabilities.

Acceptance Criteria

☐ Implementation complete and tested
☐ All affected pages load (200 status)
☐ Work visible on the website frontend
☐ No broken links introduced
☐ Code follows existing patterns

Approach

  • Read relevant source files to understand current state
  • Plan implementation based on existing architecture
  • Implement changes
  • Test affected pages with curl
  • Commit with descriptive message and push
  • Work Log

    2026-04-18 10:30 UTC — Slot 0 (reopened task)

    Reopen reason: Prior commit 7308784e7 was on an orphan branch that never merged to main.

    Verification steps taken:

    • Checked git branch -a --contains 7308784e7 — commit exists only on worktree branches, not on origin/main
    • Confirmed current HEAD (295ed526f) does NOT have the spectator mode code
    • Ran python3 -m py_compile api.py — no errors (only pre-existing SyntaxWarning)
    Changes implemented:

  • debates_page SQL query (line ~65890): Added lifecycle_state, is_open_enrollment, enrollment_closes_at, participant_count fields to the debate_sessions query
  • debates_page card badges: Added Live/Open Enrollment status badges for active/enrollment debates
  • - "Live" (green) badge for lifecycle_state == "active"
    - "Open Enrollment" (yellow) badge for lifecycle_state == "ready" with is_open_enrollment == True

  • debate_detail spectator banner (line ~66323): Added spectator mode banner for active/enrollment debates with SSE connect button and JavaScript to handle EventSource connection
  • New endpoint GET /api/debates/{debate_id}/latest-round (line ~12815): Returns current max round number and lifecycle state
  • New endpoint GET /api/debates/{debate_id}/stream (line ~12835): SSE stream of new debate rounds with 5s heartbeat keepalive — requires active or open_enrollment lifecycle state
  • Added StreamingResponse import from fastapi.responses
  • Testing: Could not curl endpoints (service not running in worktree context). Code compiles cleanly.

    2026-04-18 17:25 UTC — Slot 0 (retry push)

    Issue: Pre-push hook blocked because commit message didn't mention api.py when that critical file was modified.

    Fix applied:

    • Amended commit message to explicitly list api.py changes:
    - api.py: Add /api/debates/{id}/latest-round and /api/debates/{id}/stream SSE endpoints
    - api.py: Add spectator banner and streaming UI to debate_detail page
    - api.py: Add Live/Open Enrollment badges to debates_page cards
    • Force-pushed to push/orchestra/task/be358f25-add-spectator-mode-and-real-time-debate
    Commit: 8df214cec

    Payload JSON
    {
      "requirements": {
        "analysis": 5
      },
      "_reset_note": "This task was reset after a database incident on 2026-04-17.\n\n**Context:** SciDEX migrated from SQLite to PostgreSQL after recurring DB\ncorruption. Some work done during Apr 16-17 may have been lost.\n\n**Before starting work:**\n1. Check if the task's goal is ALREADY satisfied (run the relevant checks)\n2. Check `git log --all --grep=task:YOUR_TASK_ID` for prior commits\n3. If complete, verify and mark done. If partial, continue. If not done, proceed.\n\n**DB change:** SciDEX now uses PostgreSQL. `get_db()` auto-detects via\nSCIDEX_DB_BACKEND=postgres env var.",
      "_reset_at": "2026-04-18T06:29:22.046013+00:00",
      "_reset_from_status": "done"
    }

    Sibling Tasks in Quest (Open Debates) ↗