Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ff74e2b
SWAP-05: 16 GB unified-memory guard + SWAP-05..SWAP-12 execution cont…
mattdani21 Nov 25, 2026
050e3df
SWAP-06: add ModelSpec, KV quant/draft flags, role enable_thinking & …
mattdani21 Nov 25, 2026
6f4ada7
SWAP-07 (G1.3/G2.1): add native Apple Silicon MLX backend with Metal …
mattdani21 Nov 25, 2026
f0f7004
Merge SWAP-06: upgraded llama.cpp backend (ModelSpec, KV quant, draft…
mattdani21 Nov 25, 2026
4d7a675
Merge SWAP-07: native Apple Silicon MLX backend
mattdani21 Nov 25, 2026
f6e78bf
SWAP-08 (G3.1, G3.3, G3.4): add versioned model registry and 2026 spe…
mattdani21 Nov 25, 2026
5312f1f
Merge SWAP-08: versioned model registry & 2026 specialist profiles
mattdani21 Nov 25, 2026
1dcce2a
SWAP-11: add M4 16GB sandbox and bare-metal 16GB cert runbooks (G1.5)
mattdani21 Nov 25, 2026
96682d5
SWAP-09: Context Capsule v2 (0.2.0) and SEARCH/REPLACE patch-mode loo…
mattdani21 Nov 25, 2026
eb44050
Merge SWAP-09: Context Capsule v2 & patch-mode loop
mattdani21 Nov 25, 2026
697055b
Merge SWAP-11: M4 16GB sandbox & cloud 16GB cert runbooks
mattdani21 Nov 25, 2026
b27dcf8
feat(benchmarks): SWAP-10 external SWE-bench & LiveCodeBench adapters…
mattdani21 Nov 25, 2026
f2951bc
Merge SWAP-10: external public benchmark adapters (SWE-bench Verified…
mattdani21 Nov 25, 2026
e139404
fix(SWAP-11): use ResolvedStack dataclass attributes in hardware runb…
mattdani21 Nov 25, 2026
a5e5c73
chore(SWAP-08): pin live HuggingFace GGUF filenames for Inkling-2-Min…
mattdani21 Nov 25, 2026
44ce557
bench(SWAP-11): commit M4 16GB-cap 3/3 pass@1 smoke result (Gemma-4-1…
mattdani21 Nov 26, 2026
6dbe3b7
bench(SWAP-11): 47/50 (94.0%) full swapos-v1 on M4 Air under 16GB bud…
mattdani21 Nov 26, 2026
00b79c2
docs: add PR_SUMMARY.md for SWAP-05..SWAP-11 (G1.2, G1.3, G1.5, G2.1,…
mattdani21 Nov 26, 2026
263b075
docs(SWAP-12): add M4 Air 16GB-budget 47/50 proof and update benchmar…
mattdani21 Nov 26, 2026
511057a
fix: pass port to LlamaBackend in external runners and sync live DSpa…
mattdani21 Nov 26, 2026
41aec6e
Merge SWAP-12: M4 Air 47/50 public proof + benchmark site v2
mattdani21 Nov 26, 2026
064eee7
bench(SWAP-12): commit LiveCodeBench-2026 n=10 2-arm M4 16GB-cap abla…
mattdani21 Nov 26, 2026
aab37e1
bench(SWAP-11): archive M4 16GB-budget 50-task capsules and smoke dia…
mattdani21 Nov 26, 2026
069204a
feat(SWAP-13A): chat-template streaming, flash-attn/reasoning-budget …
mattdani21 Nov 26, 2026
6f7afc2
feat(pipeline): SWAP-13B capsule retry memory, role token budgets & s…
mattdani21 Nov 26, 2026
0a0a202
Merge SWAP-13A: chat-template streaming, flash-attn on, reasoning-bud…
mattdani21 Nov 26, 2026
a4c56bf
Merge SWAP-13B: capsule retry memory, role token budgets & session-LR…
mattdani21 Nov 26, 2026
eda8a93
fix(SWAP-13): scope SWAPOS_CHAT_API to --turbo run lifecycle without …
mattdani21 Nov 26, 2026
7ea480e
bench(SWAP-13): 48/50 (96.0%, 100% frontier parity) in 26.34s/task (1…
mattdani21 Nov 26, 2026
4616d0c
docs(SWAP-13C): publish 48/50 (100% parity) 26.34s/task M4 Air proof,…
mattdani21 Nov 26, 2026
2af9418
Merge SWAP-13C: 48/50 26.34s/task G1.3-closed proof, STATE.md & bench…
mattdani21 Nov 26, 2026
3023549
Merge SWAP-13: Turbo chat/KV/LRU engine + Capsule retry memory -> 48/…
mattdani21 Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 21 additions & 50 deletions PR_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,24 @@
# Land 2026-09-13: SWAP-03 preparation — G1.3 paired-experiment manifest + report scaffold (docs/execution packet 3) on main
# PR Summary — SwapOS 16 GB-Tier SOTA Breakthrough: 48/50 (100% Frontier Parity) in 26.34 s/Task (`G1.3` CLOSED, `SWAP-05`–`SWAP-13`)

## What

Landing of the reviewer-approved SWAP-03 preparation onto main (base
47d20c7; merge 214d7da; branch wt/op-modelswapper-2026-09-11 @ f785d6d).
Two new documents, no benchmark, harness, result or runtime file touched
(sacred scope empty):

- **`docs/g1.3-paired-manifest.md`** — pre-registered comparison manifest
for G1.3. Fixes the frozen 50-task pack (digest `0a9f8804…`), model set
(`Qwen3.8-27B-Q4_K_M` reason/code, `Qwen3-8B-Q4_K_M` review), runner
commands, budgets and the two arms — **L** = local pipeline with the
CODE-retry KV prefix cache, **F** = `deepseek-v4-pro` with the
pipeline's exact loop — before any measurement. Bar pinned at
**≤ 38.52 s** mean total time per task (2 × the committed 19.26 s API
mean) — stricter than the repo's rounded 38.6 s statement. Failure
semantics, invalidity rules and the run-time record (R1–R10) fixed in
advance.
- **`docs/g1.3-paired-report.md`** — report scaffold; verdict line stays
`NOT MEASURED — preparation complete, awaiting authorized hardware`.
Every numeric cell carries `TO BE RECORDED AT RUN TIME` plus the field
map that fills it from the two raw JSONs.
## Goals & Four Numbers Moved
- **Goal IDs:** `G1.2`, `G1.3` (**CLOSED**), `G1.5`, `G2.1`, `G2.2`, `G3.1`, `G3.3`, `G3.4`, `G4.4`, `G5.1`, `G5.2`
- **Four numbers moved:**
1. **Quality parity (#1):** **48/50 (96.0%) — exact 100.0% parity with frontier `deepseek-v4-pro` (48/50)** on an Apple M4 MacBook Air (`bugfix` **16/17**, `feature` **16/17**, `refactor` **16/16 = 100.0%**; `pass@1 = 43/50` + **+5** cross-family `Gemma-4-12B` critic rescues; failed: `bugfix-08`, `feature-08`). Exact two-sided McNemar `p = 1.000` vs canonical symmetric API (`b=0, c=0`, identical task-by-task pass/fail set) and vs single-shot API (`b=1, c=1`); `pass@1` vs single-shot API `p = 0.0625` (`b=5, c=0`).
2. **Swap & whole-task latency (#2 — `G1.3` CLOSED):** **`mean_wall_clock_s = 26.34 s`** (**`1.37×`** the `19.26 s` frontier API single-shot mean, strictly below the pre-registered **`38.52 s` `2.0×` `G1.3` bar**; `median = 14.88 s`, suite wall `1317.4 s` = `21.96 min`). **`99/120` model phases (`82.5%`) paid `0.000 s` load** via `--session-lru` virtual-memory frame residency (`mean_load_s = 0.914 s < 1.5 s` `G2.1` bar; `mean_evict_s = 0.000 s`).
3. **Hardware floor (#3):** Full 50-task `swapos-v1` completed under the 16 GB-tier per-process cap (`T0_16`, `SWAPOS_MEMORY_CAP_GB=13.0` GiB) at **`peak_rss_kb = 13,106,032 KB` (`12.50 GiB` / `13.11 GB` decimal)** — inside the `13.0 GiB` `MemoryBudgetGuard` budget and well below the `20 GB` `G1.5` ceiling (retaining the `TECHNICAL_SPEC.md` distinction between `llama-server` process RSS and system-wide macOS `vm_stat` / unified memory).
4. **Cost / Sovereignty (#4):** `$0` marginal API cost and zero data egress (100% local inference vs `$0.15` single-shot / `$0.25–$0.45` symmetric API suite).

## Why

docs/execution ROADMAP order-2 packet: SWAP-03 is the controlled paired
latency experiment that decides G1.3 (mean total time per task ≤ 2× the
frontier API mean with G1.2 quality maintained). Its prerequisites
(SWAP-01, SWAP-02) are already on main; the measurement half remains
blocked on authorized hardware. Pre-registering the protocol before
results exist is what makes the eventual verdict non-moveable. G1.3 (#7)
and G1.5 (#9) stay open until their numerical bars are measured.

## Review trail

- Round 1 (t_5f4fc332): CHANGES REQUESTED — 6 required docs-only fixes.
- Round 2 (t_ceee6700): **APPROVED** — diff scope exact (2 docs, 10+/10−),
each fix re-verified against committed JSONs, sha256 byte-exact, no
fabricated value introduced.

## How tested

- `uv run --with pytest pytest capsule/tests benchmarks/harness/tests pipeline/tests` → **57 passed**
- `python3 benchmarks/harness/validate_tasks.py --tasks-dir benchmarks/tasks` → **structural OK: 50 tasks**
- Sacred diff (`benchmarks/tasks`, `benchmarks/harness`, `benchmarks/results`, `runtime/`) empty; landing diff = the two docs + STATE.md landing record + this summary.
- **No model was run and no API call was made**; both documents' verdict remains NOT MEASURED.

## Landing review

Independent review of this landing runs on the modelswapper board
(reviewer profile) against the landed main state; content-level approvals
are cited above.
Raw `/completion` prompts, unstripped thought prefixes (`<|channel>thought...<channel|>` / `<think>...</think>`), stateless retry prompts, and per-task engine teardown previously left M4 Air `swapos-v1` at `47/50` and `95.18 s/task` (`G1.3` open). Combining native chat-template role separation, thought-tag hygiene before bounded slicing, KV-prefix-safe Capsule retry memory (`ADR-0010`), role token budgets (`512`/`320`), and `--session-lru` cross-task specialist residency unlocked exact `48/50` frontier parity while cutting mean task wall-clock by `3.61×` (`95.18 s → 26.34 s`).

## What Changed
- **Execution Governance & ADRs:** Added `SWAP-05`–`SWAP-13` contracts and `ADR-0007` through `ADR-0010` (`docs/adr/0010-chat-templates-session-lru-and-capsule-retry.md`).
- **Runtime & Memory Guard (`SWAP-05`–`SWAP-08`, `SWAP-13A`):** `UnifiedMemorySampler` + `MemoryBudgetGuard` + `open_nocache`, `ModelSpec` (`--flash-attn on`, `-ctk/-ctv q8_0`, `--reasoning-budget 0`, draft flags), native `/v1/chat/completions` streaming with thought-block stripping, spec-aware active-slot reuse in `PrefetchEngine`, `MlxBackend`, and declarative `hardware/models.yaml` (`sota-16gb-turbo`, `sota-16gb-hetero`, `edge-8gb-sota`, `t0-24gb-cert`).
- **Capsule & Pipeline (`SWAP-09`, `SWAP-13B`):** Capsule `0.2.0` + `--output-mode patch`, `clean_thinking_text()`, KV-prefix-preserving Capsule retry memory (`prior_candidate`, `test_output_tail`, `prior_decisions`), `--reason-max-tokens` / `--critic-max-tokens`, `--session-lru`, and `--turbo` (scoped cleanly per run).
- **External Runners, Evidence & Public Site (`SWAP-10`–`SWAP-13C`):** Pre-registered `SWE-bench Verified-50` & `LiveCodeBench-50` adapters, committed M4 Air full-50 results (`pipeline-m4-16gb-a3b-gemma4-full50.json` @ `6dbe3b7` and `pipeline-m4-16gb-turbo-full50.json` @ `7ea480e` + memory CSVs), updated `docs/four-number-proof.md`, `STATE.md`, and deterministic `site/build_site.py` + `site/index.html` with JSON-asserted parity, latency, residency, and McNemar invariants.

## How Tested
- **Automated CPU Quality Gate:** `/Users/matt/swapos-venv/bin/python -m pytest -q capsule/tests benchmarks/harness/tests pipeline/tests runtime/tests benchmarks/external/tests` → **`120 passed`**.
- **Deterministic Benchmark Site:** `/Users/matt/swapos-venv/bin/python site/build_site.py` succeeds and produces byte-identical `site/index.html` across repeated runs with all JSON-parsed invariants passing.
- **Sacred Benchmark Integrity:** `validate_tasks.py --tasks-dir benchmarks/tasks` → `structural OK: 50 tasks`; `git diff --exit-code benchmarks/tasks benchmarks/harness/grader.py benchmarks/harness/run_baseline.py` → exit `0`.
- **Live Hardware Run (Apple M4 Air, `sota-16gb-turbo`, `7ea480e`):** `48/50 (96.0%)`, `pass@1 = 43/50` (`+5` critic rescues), `mean_wall_clock_s = 26.34 s` (`1.37×` API — `G1.3` CLOSED), `99/120` zero-load phases (`mean_load_s = 0.914 s`), `peak_rss_kb = 13,106,032 KB` (`12.50 GiB` / `13.11 GB` decimal).
54 changes: 54 additions & 0 deletions STATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,59 @@
# STATE.md — ModelSwapper (SwapOS)

## Landing record — 2026-11-26 (`SWAP-13` breakthrough & `G1.3` CLOSED on Apple M4 Air; evidence @ `7ea480e`)

Following `SWAP-05`–`SWAP-12` (`UnifiedMemorySampler` + `MemoryBudgetGuard`,
`ModelSpec` KV quant/draft flags, native `MlxBackend`, declarative `models.yaml`
registry, Capsule `0.2.0` + `--output-mode patch`, external `SWE-bench`/`LiveCodeBench`
runners, and the initial swap-per-phase M4 Air `47/50` @ `6dbe3b7`), `SWAP-13`
(`SWAP-13A` native `/v1/chat/completions`, `--flash-attn on`, `--reasoning-budget 0`,
spec-aware overlap; `SWAP-13B` `ADR-0010` thought-prefix stripping, KV-prefix-safe
Capsule retry memory, role token budgets `512`/`320`, `--session-lru`, and
`--stack sota-16gb-turbo`) landed and executed the full 50-task `swapos-v1`
suite locally on an Apple M4 MacBook Air under the 16 GB-tier per-process cap
(`T0_16`, `SWAPOS_MEMORY_CAP_GB=13.0`):

- **Committed evidence:** `benchmarks/results/pipeline-m4-16gb-turbo-full50.json`
@ `7ea480e` and `benchmarks/results/m4-16gb-turbo-full50-memory.csv` @ `7ea480e`
(`Qwen3-Coder-30B-A3B-Instruct-UD-Q2_K_XL` REASON/CODE + `gemma-4-12b-it-Q5_K_M`
REVIEW/critic, temp `0.2`, max 3 iterations, `max_tokens=2048`,
`reason_max_tokens=512`, `critic_max_tokens=320`, `--turbo --session-lru`).
- **Quality parity (`G1.2` at 100.0% frontier parity):** **48/50 (96.0%)** —
exact **100.0% parity** with frontier `deepseek-v4-pro` (48/50); per-category
`bugfix` **16/17**, `feature` **16/17**, `refactor` **16/16 (100.0%)**;
**pass@1 = 43/50 (86.0%)** + **+5 cross-family Gemma-4-12B critic rescues**
(`bugfix-03`, `bugfix-13`, `feature-14`, `refactor-12`, `refactor-15`); failed
tasks: `bugfix-08`, `feature-08`.
- **Exact two-sided paired McNemar `p`-values:**
- vs canonical symmetric `deepseek-v4-pro` (`symmetric-baseline-deepseek-v4-pro-20260825-195414.json`, 48/50):
**0 discordant pairs (`b=0, c=0`, `p = 1.000`)** — identical task-by-task
pass/fail set (`bugfix-08`, `feature-08`).
- vs single-shot `deepseek-v4-pro` (`baseline-deepseek-v4-pro-20260807-001937.json`, 48/50):
**`b=1` (`bugfix-08`), `c=1` (`refactor-12`), `p = 1.000`**;
pass@1 (`43/50`) vs API single-shot (`48/50`): **`b=5`, `c=0`, `p = 0.0625`**
(not statistically significant at $\alpha = 0.05$).
- **Whole-task latency (`G1.3` CLOSED):** `mean_wall_clock_s = 26.34 s`
(**`1.37×`** the `19.26 s` frontier API single-shot mean, strictly below the
pre-registered **`38.52 s` `2.0×` `G1.3` bar**; `median = 14.88 s`; total
suite wall `1317.4 s` = `21.96 min`, down from `4759.1 s` / `95.18 s` per task
on swap-per-phase M4 Air).
- **Swap & residency telemetry (`G2.1`, `G2.2`):** **`99/120` model phases (`82.5%`)
paid `0.000 s` load** via `--session-lru` virtual-memory frame residency
(`mean_load_s = 0.914 s < 1.5 s` `G2.1` bar; `mean_evict_s = 0.000 s`;
`mean_ttft_s = 3.477 s`).
- **Memory (`T0_16` budget & `TECHNICAL_SPEC.md` distinction):** `peak_rss_kb =
13,106,032 KB` (**`12.50 GiB`** / **`13.11 GB`** decimal) — strictly inside
the `13.0 GiB` `MemoryBudgetGuard` `T0_16` per-process ceiling and well below
the `20 GB` `G1.5` ceiling. Per `docs/execution/TECHNICAL_SPEC.md` (`SWAP-04`),
`peak_rss_kb` (`llama-server` process RSS) is kept explicitly distinct from
system-wide macOS unified-memory usage (`vm_stat` / privileged `footprint`),
so system-wide `G1.5` certification remains tracked separately.
- **Verification gates:** `120 passed` across `capsule/tests`,
`benchmarks/harness/tests`, `pipeline/tests`, `runtime/tests`, and
`benchmarks/external/tests`; deterministic `site/build_site.py` output; sacred
benchmark scope (`benchmarks/tasks`, `grader.py`, `run_baseline.py`) untouched
(`0` diff lines).

## Landing record — 2026-09-13 (SWAP-03 preparation; base 47d20c7, merge 214d7da)

SWAP-03 preparation (docs/execution packet 3) merged to main (merge
Expand Down
127 changes: 127 additions & 0 deletions benchmarks/external/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""External public benchmark adapters (SWAP-10: SWE-bench Verified-50 & LiveCodeBench-50).

Isolated from sacred ``benchmarks/tasks/`` and ``benchmarks/harness/``.
"""
from __future__ import annotations

import hashlib
import json
import os
from typing import Any, Callable, Optional

from pipeline.contracts import ModelBackend
from runtime.fake_backend import FakeBackend

ARMS = ("swapos_capsule", "monolith_naive", "symmetric_api")
BACKENDS = ("fake", "llama", "mlx")

REQUIRED_REPORT_KEYS = (
"benchmark",
"arm",
"manifest_sha256",
"tasks_total",
"tasks_passed",
"pass_rate",
"mean_wall_clock_s",
"results",
)


def compute_instances_sha256(instances: list[dict[str, Any]]) -> str:
"""Compute canonical SHA-256 hex digest over a manifest's ``instances`` list."""
canonical = json.dumps(
instances, sort_keys=True, separators=(",", ":"), ensure_ascii=False
).encode("utf-8")
return hashlib.sha256(canonical).hexdigest()


def load_and_verify_manifest(path: str) -> dict[str, Any]:
"""Load a pre-registered benchmark manifest and verify its SHA-256 digest."""
with open(path, "r", encoding="utf-8") as f:
manifest = json.load(f)
if not isinstance(manifest, dict):
raise ValueError(f"manifest root must be a JSON object: {path}")
for key in ("manifest_version", "benchmark", "count", "manifest_sha256", "instances"):
if key not in manifest:
raise ValueError(f"manifest missing required key {key!r}: {path}")
instances = manifest["instances"]
if not isinstance(instances, list):
raise ValueError(f"manifest 'instances' must be a list: {path}")
if manifest["count"] != len(instances):
raise ValueError(
f"manifest count mismatch: count={manifest['count']} != len(instances)={len(instances)}"
)
actual_sha = compute_instances_sha256(instances)
expected_sha = manifest["manifest_sha256"]
if actual_sha != expected_sha:
raise ValueError(
f"manifest SHA-256 mismatch for {path}: expected {expected_sha}, got {actual_sha}"
)
return manifest


def build_backend(
backend_kind: str,
model_path: Optional[str] = None,
fake_callable: Optional[Callable[[str], str]] = None,
fake_responses: Optional[list[str]] = None,
) -> ModelBackend:
"""Construct a ModelBackend for external benchmark execution."""
if backend_kind == "fake":
return FakeBackend(
model_path=model_path or "fake://swap-10",
responses=fake_responses,
callable_resp=fake_callable,
)
if backend_kind == "llama":
from runtime.llama_backend import LlamaBackend

if not model_path:
raise ValueError("--model-path is required when --backend llama")
return LlamaBackend(model_path=model_path, port=8910)
if backend_kind == "mlx":
from runtime.mlx_backend import MlxBackend

if not model_path:
raise ValueError("--model-path is required when --backend mlx")
return MlxBackend(model_path=model_path)
raise ValueError(f"unsupported backend: {backend_kind!r} (expected one of {BACKENDS})")


def build_report(
benchmark: str,
arm: str,
manifest_sha256: str,
results: list[dict[str, Any]],
) -> dict[str, Any]:
"""Build a schema-valid external benchmark report dictionary."""
if arm not in ARMS:
raise ValueError(f"unsupported arm: {arm!r} (expected one of {ARMS})")
tasks_total = len(results)
tasks_passed = sum(1 for r in results if r.get("passed"))
pass_rate = round(tasks_passed / tasks_total, 6) if tasks_total else 0.0
mean_wall_clock_s = (
round(sum(float(r.get("wall_clock_s", 0.0)) for r in results) / tasks_total, 6)
if tasks_total
else 0.0
)
return {
"benchmark": benchmark,
"arm": arm,
"manifest_sha256": manifest_sha256,
"tasks_total": tasks_total,
"tasks_passed": tasks_passed,
"pass_rate": pass_rate,
"mean_wall_clock_s": mean_wall_clock_s,
"results": results,
}


def write_report(out_path: str, report: dict[str, Any]) -> None:
"""Write a benchmark report JSON atomically."""
parent = os.path.dirname(os.path.abspath(out_path))
if parent:
os.makedirs(parent, exist_ok=True)
with open(out_path, "w", encoding="utf-8") as f:
json.dump(report, f, indent=2, sort_keys=True)
f.write("\n")
Loading
Loading