[Senate] Add concurrent analysis limits and queue management done analysis:8 coding:7 reasoning:7

← Resource Governance
## 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 (16)

[Senate] Update spec work log: merge gate fix for queue processor [task:743c503762b2]2026-04-20
[Senate] Fix queue processor: one queued analysis per pass; recheck capacity before fresh start [task:743c503762b2]2026-04-20
[Senate] Update spec work log: implementation complete [task:743c503762b2]2026-04-20
[Senate] Add concurrent analysis limits and queue management [task:743c503762b2]2026-04-20
[Senate] Update spec work log: merge gate fix for queue processor [task:743c503762b2]2026-04-20
[Senate] Fix queue processor: one queued analysis per pass; recheck capacity before fresh start [task:743c503762b2]2026-04-20
[Senate] Update spec work log: implementation complete [task:743c503762b2]2026-04-20
[Senate] Add concurrent analysis limits and queue management [task:743c503762b2]2026-04-20
[Senate] Update spec work log: merge gate fix for queue processor [task:743c503762b2]2026-04-20
[Senate] Fix queue processor: one queued analysis per pass; recheck capacity before fresh start [task:743c503762b2]2026-04-20
[Senate] Update spec work log: implementation complete [task:743c503762b2]2026-04-20
[Senate] Add concurrent analysis limits and queue management [task:743c503762b2]2026-04-20
[Senate] Update spec work log: merge gate fix for queue processor [task:743c503762b2]2026-04-20
[Senate] Fix queue processor: one queued analysis per pass; recheck capacity before fresh start [task:743c503762b2]2026-04-20
[Senate] Update spec work log: implementation complete [task:743c503762b2]2026-04-20
[Senate] Add concurrent analysis limits and queue management [task:743c503762b2]2026-04-20
Spec File

[Senate] Add concurrent analysis limits and queue management

Quest: Resource Governance Priority: P5 Status: open

Goal

Limit the number of analyses running simultaneously. On this VM, max 2 concurrent analyses (configurable). Additional analyses queued and run in FIFO order. Prevents resource contention and ensures the VM stays responsive.

Acceptance Criteria

☐ MAX_CONCURRENT_ANALYSES config (default: 2)
☐ Analyses beyond the limit are queued with status 'queued'
☐ Queue processed in priority order (not just FIFO)
☐ Queue status visible on /quests and /analyses/ pages
☐ System gracefully handles queue when an analysis fails or times out
☐ Stale queue entries auto-cancelled after 24h

Approach

  • Add 'queued' status to analyses table
  • Modify orchestrator to check running count before starting new analysis
  • Implement priority queue: higher-priority gaps get analyzed first
  • Add queue display to /analyses/ page
  • Add queue depth metric to /api/quests/status
  • Handle edge cases: analysis crash, timeout, manual cancellation
  • Dependencies

    _Identify during implementation._

    Dependents

    _Identify during implementation._

    Work Log

    2026-04-20 12:00 PT — Slot 0

    • Task re-evaluated: No prior commits found for this task. Previous attempt may have been lost to orphan branch.
    • Current state: Analyses table has statuses: active, archived, completed, failed. No 'queued' status exists. Active analyses (7) represent analyses in progress by the autonomous agent.
    • Architecture: agent.py is the main orchestrator (SciDEXOrchestrator class). It runs debates via run_single() / run_continuous(). Uses PostgreSQL via SCIDEX_CONFIG['db_path'] = 'postgresql://scidex'.
    • Approach: Add MAX_CONCURRENT_ANALYSES=2 config, count_running_analyses() helper, queue when at capacity, process queue in priority order, auto-cancel stale entries after 24h.
    • Files to change: agent.py (orchestrator logic), api.py (queue display on /analyses/ and /api/quests/status)

    2026-04-20 12:45 PT — Implementation complete

    • Added max_concurrent_analyses=2 and stale_queue_timeout_hours=24 to SCIDEX_CONFIG
    • Added count_running_analyses(), get_next_queued_analysis(), start_queued_analysis(), cancel_stale_queued_analyses(), process_queue() methods to SciDEXOrchestrator
    • Modified run_single() to check capacity and queue analyses when at limit
    • api.py: status color/icon for 'queued' (blue), stats bar shows queued count, /api/quests/status exposes analysis_queue_depth and active_analyses
    • Committed as be8b9bf20 and pushed to origin
    • Note: analyses with status='active' are considered "running" — both statuses counted together

    2026-04-20 13:30 PT — Merge gate fix

    • Problem: Review gate rejected prior commit (be8b9bf20) — process_queue used a while loop that could launch multiple expensive analyses in one scheduler pass, defeating concurrency limits.
    • Fix:
    1. Changed process_queue from while running < max_concurrent to a single if running < max_concurrent — processes at most ONE queued item per call.
    2. Added capacity re-check in run_single after process_queue() — if queue processing consumed the last slot, run_single returns early instead of starting a fresh gap analysis.
    • Committed as 7a7c20b3a and pushed.

    Payload JSON
    {
      "requirements": {
        "coding": 7,
        "reasoning": 7,
        "analysis": 8
      }
    }

    Sibling Tasks in Quest (Resource Governance) ↗