[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 cancellationDependencies
_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.