# Multi GPU FIFO Implementation Plan > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development or superpowers:executing-plans. Complete each task's RED/GREEN checks and record evidence. **Goal:** Dispatch ready jobs FIFO across idle GPUs and run the workspace with 384 GiB RAM. **Architecture:** One scheduler owns FIFO claims and persistent per-GPU leases, while independent execution monitors own task process groups. Business orchestration feeds independent ready leaves into that queue within quotas. Aggregated resource state drives the web UI. **Tech Stack:** Python/SQLite/Linux processes, FastAPI/SQLAlchemy, Vue/Pinia, Docker. **Spec:** `docs/superpowers/specs/2026-11-11-multi-gpu-fifo-design.md` (approved; 384 GiB supplement). ## Global Constraints - One job per GPU UUID, max_gpu_jobs=4; 68 GiB allocator, 8 GiB GPU reserve, 15-second idle admission. - Global FIFO for eligible tasks; retain pauses, windows, quotas, output/attempt fencing and external-user priority. - No replay of hard-crashed execution; preserve queue/model files and unrelated working-copy edits. - Workspace RAM=384 GiB; total memory+swap limit=384 GiB (no swap allowance). Keep other services intact. - Source baseline is isolated commit `18701ee`; integrate only this feature's delta into the current canonical checkout. ## Review Focus - Delayed GPU telemetry must not allocate one physical GPU twice. - Cancelling/preempting one runner must not stop or finalize another attempt. - More than eight independent workflow leaves must make progress without quota transaction rollback. - Old API/worker initialization must not silently restore the singleton index. - Cgroup/SHM pressure and normal PID exit must not create OOM or preemption retry storms. ### Task 1: Inference FIFO scheduler, per-GPU leases and memory admission Files: `inference/llm_services/{store,worker,gpu_policy,api}.py`, `inference/scripts/service.py`, new scheduler/resource helpers if useful, related inference tests. Interfaces: scheduler JSON schema_version=2; `active_jobs` entries carry `job_id`, `attempt_count`, `gpu_index`, `gpu_uuid`, `stage`, `state`, `reason`; top-level `running_count`, `queued_count`, `state`, `policy`, `updated_at`. States `running/waiting/idle/blocked`, with per-entry preempting allowed. Settings keys live in worker config/settings.json, never runtime-policy.json. `max_gpu_jobs=4`, `cpu_threads_per_job=2`, initial host-memory estimates GiB: image=88, video=64, defect=24, audio=12; global headroom=16. These conservative estimates are configurable and updated by real measurements. Admission accounts for current cgroup working memory, active reservations and SHM, without counting reclaimable inactive file cache as permanently consumed. - [x] Write and run failing tests: three UUIDs launch A/B/C FIFO while D waits; concurrent claims never duplicate UUID/job; mixed modes use eligible queue_seq; old-attempt writes rejected; one cancellation or external preemption leaves other runners alive; multiple markers block unsafe recovery; old schema migration preserves jobs; memory shortage queues head job. - [x] Replace singleton index/claim guard with atomic GPU lease uniqueness; schema compatibility rejects legacy singleton re-creation. - [x] Implement one event dispatcher with per-job monitors and markers. Claims/spawns ordered, monitor/cleanup independent, status single writer. Keep `run_once` compatibility for meaningful legacy fixtures or update callers deliberately. - [x] Add attempt CAS to terminal and requeue writes, bounded all-runner shutdown, per-runner env/CPU threads, max slot and memory admission. - [x] Run inference suite on Windows for portable parts, then complete Linux process/guard/service suite in isolated server scratch. Record RED/GREEN and commit scoped files after review. ### Task 2: Application FIFO, parallel workflow/batch feeder Files: `backend/app/{coordinator,workflow_engine,batches,workflows,jobs}.py` as needed and corresponding backend tests. Do not edit providers.py (Task 4 owner). Interfaces: reuse existing upstream scheduling protocol/job IDs and attempt fences. Independent ready steps enqueue in stable step order within remaining per-owner quota (8 interactive GPU jobs). Multiple active batch members allowed; preserve existing current_item_index compatibility while providing active item list/count if needed. Separate new-submit FIFO from next_action_at retry polling. Bound background preparation/collection and continue querying existing upstream executions. - [x] Write RED tests for three independent shot submissions, 12/20-shot quota replenishment, two batch members in flight, compose waiting all chosen outputs, cancelling one child, stable FIFO ready submission despite polling timestamps. - [x] Implement bounded per-leaf persistence and replenish; remove only unique-active-member gate, preserve run/user quotas, hold controls, permissions and dependencies. - [x] Ensure long preparation/result imports do not starve ready submissions; retain CPU/Qwen pool limits and persisted outcomes. - [x] Run full backend tests, report any baseline unrelated failures separately; scoped review/commit. ### Task 3: GPU monitor disappearing-PID handling and diagnostics Files: `inference/admin/gpu_guard.py`, `inference/tests/test_gpu_guard.py` (and only narrowly related tests). Interfaces: preserve guard status schema v1, ownership and global failure behavior. A missing PID can be dropped only after one fresh NVIDIA sample confirms disappearance; permission/identity ambiguity stays fail-closed. Logs record failed PID, stage, error category without dumping command/env/secrets. - [x] RED tests: sampled PID exits before /proc read then absent on bounded resample -> no global error; still-present unknown PID/permission failure -> fail closed; new external process in refreshed sample is retained; sample retry bounded and existing watchdog identity tests pass. - [x] Implement one bounded resample and structured diagnostics; retain root-only policy and pidfd signaling. - [x] Run guard suite portable then Linux, review and scoped commit. Root deploys root-owned script only after full verification. ### Task 4: Aggregated UI resources, documentation and integration Files: `backend/app/providers.py`, `backend/tests/test_resource_status*.py` or existing resource tests, frontend resource types/components/text/tests, help manuals, README and deployment checks. Root owns these files. - [x] RED tests for multiple active_jobs, single-card preemption with another card running/ready, schema-v1 compatibility, no sensitive process detail in public resource state. - [x] Adapt provider resource summary and frontend types/counts/card information; remove current single-task wording, preserve history reports. - [x] Run backend full suite, frontend full tests/typecheck/build, inference full Linux suite; independently review integration. Resolve important findings with focused RED/GREEN checks. ### Task 5: 384 GiB deployment, selective source integration and real three-card validation Files: scoped deploy script, new QA evidence/README; remote backup and deployment records. - [x] Recheck host available RAM and target container identity; save old configuration; docker update memory and memory-swap to384g; verify exact cgroup limit412316860416 and unchanged container start time. - [x] Compare canonical files to baseline manifest; integrate only this feature's delta with three-way preservation of concurrent edits, then retest combined source. Do not stage or deploy unrelated incomplete work. - [x] Drain existing jobs before coordinated API/worker schema switch; retain queued jobs. Back up SQLite using backup API, configurations, service identities and touched source. - [x] Deploy consistent inference/API/UI versions, root guard source and operator config; check readiness and Qwen/other container identity. - [x] Submit four low-cost real GPU jobs across three free cards; prove FIFO starts, overlapping execution, fourth waiting then filling a released card, outputs decoded, per-card cleanup, single-card controlled external preemption, RAM/SHM peaks, no duplicate attempts or unexplained requeue. Do not consume GPU0 external service. - [x] Restore prior test-only inputs/policy after validation; leave production concurrency enabled and384 GiB. Record final tests, changed service bindings, source commit and limitations.