[UI] Fix hypothesis page 25s load time — remove blocking API call done coding:7

← UI
Hypothesis detail pages take 25+ seconds to load due to a blocking ClinicalTrials.gov API call in _hypothesis_detail_render. Fix: skip the external API call on page load (show cached data or placeholder), batch debate N+1 queries. ## 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 (1)

[Agora] Batch debate N+1 queries in hypothesis_detail page render [task:b40095a9-3798-42e0-8a26-0255bd48f1d5]2026-04-13
Spec File

Spec: Fix hypothesis page 25s load time — remove blocking API call

Task ID: b40095a9-3798-42e0-8a26-0255bd48f1d5 Layer: Agora Type: one-time

Problem

Hypothesis detail pages took 25+ seconds to load due to:

  • A blocking ClinicalTrials.gov API call during page render
  • N+1 SQL queries when loading debate round transcripts (one query per debate session)
  • Solution

    ClinicalTrials.gov blocking call: Already resolved on main — the live API call was removed and replaced with a comment directing enrichment to background pipelines (line ~25898 in api.py).

    Debate N+1 queries: Fixed by batching the two per-session queries into two single IN (?) queries that fetch all session data at once, then grouping results by session_id in Python.

    Changes

    • api.py: Replaced per-session debate transcript loop (N+1 queries) with two batch queries using IN (...) for debate_rounds and debate_sessions.transcript_json.

    Work Log

    • 2026-04-13: Investigated current state. ClinicalTrials.gov blocking fix already landed on main. Debate N+1 queries still present. Batched the two queries to eliminate N+1 pattern. Verified rendering code at line ~27276 is compatible (already converts rows via dict(rnd)).

    Payload JSON
    {
      "requirements": {
        "coding": 7
      },
      "completion_shas": [
        "cf78c101f55bcc17389c33fd2cdcf801322b5d41"
      ],
      "completion_shas_checked_at": "2026-04-13T18:51:32.188136+00:00"
    }

    Sibling Tasks in Quest (UI) ↗