Files
automaton/tasks/runnable-test-suite/subtasks/vram-detect-cross-platform/IMPLEMENTATION.md
T
Lap Tran f32f98575b
CI / build (push) Has been cancelled
Make test suite runnable from clean checkout + cross-platform vram_detect
runnable-test-suite (parent) — complete. Three sub-tasks all complete:

- make-tests-runnable: add requirements.txt pinning pytest==7.4.4, sweep all
  docs/prompts from bare 'python' to 'python3' (stock macOS/Windows ships
  python3), add idempotent .venv install block to scripts/install.sh, and add
  'from __future__ import annotations' to 3 dashboard modules using PEP 604
  union syntax at definition time so they import on Python 3.9+. The
  PEP 604 bug was caught by the streak verifier itself during implementation.

- vram-detect-cross-platform: scripts/vram_detect.py now branches on
  platform.system() for Linux/Darwin/Windows. macOS path uses
  system_profiler SPDisplaysDataType (Apple Silicon unified memory via
  sysctl hw.memsize; Intel Macs via 'VRAM (Total):'). Windows uses wmic
  path win32_VideoController get AdapterRAM with PowerShell fallback. Linux
  /proc/meminfo and nvidia-smi/lspci paths unchanged (regression test locks
  them). Added 14 local-LLM context-window entries (llama-3.1, qwen2.5,
  mistral, deepseek-r1/v3, glm-4/4.5, gemma-2, phi-3/4) with source-cited
  model cards. Added _probe_ollama_model() that runs 'ollama list' as a
  last-resort fallback. run_command() now wraps PowerShell cmdlets on
  Windows (['powershell', '-NoProfile', '-NoLogo', '-Command', ...]).

- vram-detect-cross-platform-tests: 11 new monkeypatched tests in
  tests/test_vram_detect.py covering Linux/Darwin/Windows branches for
  detect_ram and detect_gpu_vram, prefix-match for unknown model names,
  ollama probe, Windows PowerShell wrapper, and a LOCKED regression test
  for _detect_ram_linux(). All external subprocess/sysctl/wmic calls are
  mocked; no live hardware probes. Suite total: 235 passed, 0 errors.

Verified on this box: gpu_vram_gb 0 -> 32 on Apple M5 (32GB unified memory),
target context correctly jumped 12k -> 42k.

Subtask-2 implementation was authored by local LLM (gemma-4-26B-A4B-it
via headroom proxy @ localhost:8787). The 10-consecutive-clean-pass streak
verifier ran as the independent checker model (article #2/#9/#13 in
'WTF Is a Loop? Part 2'). One anti-spin rail fired: local LLM produced
inline branches where subtask-3 tests expected private _detect_ram_linux()
helper; extracted helper to match the test contract without weakening tests.

Parent + all 3 subtasks complete. Prior opencode-subagent implementation
of subtask-2 preserved in git stash for reference.
2026-06-21 18:28:15 -04:00

3.3 KiB

IMPLEMENTATION — vram-detect-cross-platform

Implementer: local LLM (gemma-4-26B-A4B-it-uncensored-Q4_K_M.gguf via headroom @ localhost:8787, model id local-llm) Orchestrator: opencode (glm-5.2)

What changed in scripts/vram_detect.py

Function Author Change
import platform (new top-level import) Orchestrator (mechanical) Added to support platform.system() dispatch
detect_gpu_vram() Local LLM Branched on platform.system(). Linux: unchanged. Darwin: system_profiler SPDisplaysDataType parser (Apple Silicon → unified memory via sysctl -n hw.memsize; Intel Macs → VRAM (Total):). Windows: wmic path win32_VideoController get AdapterRAM,Name /format:list + PowerShell fallback.
detect_ram() + _detect_ram_linux/_darwin/_windows() Local LLM + Orchestrator refactor Local LLM produced inline branches; Orchestrator extracted private helpers to match subtask-3 test contract (_detect_ram_linux()). Linux path byte-identical. macOS: sysctl hw.memsize (no available RAM, reports total). Windows: wmic + PowerShell fallback.
MODEL_CONTEXT_WINDOWS Local LLM Added 14 local-LLM entries (llama-3.1, qwen2.5, mistral, deepseek-r1/v3, glm-4/4.5, gemma-2, phi-3/4) with source-cited context sizes. Conservative values where YaRN extends context.
_probe_ollama_model() (new) Local LLM Calls ollama list, parses first non-header row's NAME column, strips :latest. Returns None on any error or if ollama not installed.
detect_model_context() Orchestrator (mechanical wire-up) Calls _probe_ollama_model() as last-resort fallback after all config-file probes fail.
run_command() Local LLM On Windows, if first cmd arg starts with Get- or contains CimInstance, rewrites cmd to ['powershell', '-NoProfile', '-NoLogo', '-Command', ' '.join(cmd)] before shutil.which check. Preserves Linux behavior.

BEFORE vs AFTER on this Darwin arm64 (Apple M5, 32GB)

  • BEFORE: gpu_vram_gb: 0 (macOS not supported, falls through to "no GPU")
  • AFTER: gpu_vram_gb: 32, GPU: Apple Silicon (unified memory), Total System RAM (Shared VRAM): 32768 MB
  • Target context correctly jumped 12k → 42k (reflects shared VRAM budget).
  • JSON shape unchanged (same 8 keys, same order, same types).

Anti-spin rails that fired

  • Signature mismatch on _detect_ram_linux(): subtask-3's test expected a private helper; local LLM's first refactor put Linux path inline in detect_ram(). Orchestrator (me) extracted the helper to match the test contract — NOT weakening the test, the opposite: making code more testable per the contract.
  • All other local-LLM output was applied verbatim after passing py_compile.

Streak verifier result

STREAK_COMPLETE attempt=1 clean=10/10

The independent checker model (the streak verifier, per article #2/#9/#13) ran the full suite 10 consecutive times with no edits between. The worker (local LLM) did not grade its own homework.

Test count

  • 235 passed (was 224; subtask-3 added 11 cross-platform tests).
  • 0 errors, 0 skipped.
  • Suite runtime ~3.5s.

Files touched (and ONLY this file)

  • scripts/vram_detect.py (+ 1 new top-level import, +14 dict entries, +1 new helper function _probe_ollama_model, refactor of 3 existing functions, +1 new branch in run_command, +1 wire-up call in detect_model_context)