# Foundation audit Audited only starting foundation **4a02cd145745a9d1c45d2ca8d669b650dce619f8**. HEAD matched that commit and the tracked working tree was clean. Concurrent work was not inspected. No source, pins or lockfiles changed. Delivered: `artifacts/goal/batches/e02-evaluation/items/foundation-audit/result.md` (untracked). Installations, downloaded pinned dependencies, test state and logs are only under ignored `scratch/`. **Verdict:** reference integrity, actual Gate P, offline operation and Linux setup checks pass. Two reproducible setup defects remain: incomplete deadline enforcement and stale engine variables when switching to replica mode. No patches were made. macOS execution is **untested**, not certified by downloaded wheel tags. ## Budget, first benchmark and exact principal commands 55-minute item cap; completed within it. All checks had outer timeouts below 480s, longest suite 46.23s; no timeout/checkpoint loss. Initial scratch runtime/cache was absent. Materialization used stdlib python3; subsequent checks used pinned CPython 3.12.16. Commands ran at checkout root; logs under scratch/audit are not delivered. No bank, tuning or parity sweep. ```sh timeout 20s mkdir -p scratch/audit timeout 30s /usr/bin/time -p python3 -B reference/materialize.py --out scratch/reference timeout 470s /usr/bin/time -p bash setup_fast.sh --platform linux-x86_64 --replica-only --cache scratch/cache --scratch scratch/runtime --smoke ``` First workload results (before selecting further checks): materialized 35 originals in **0.34s**. Cold replica setup: **4 downloads / 114,819,511 bytes**, fresh install, **14.48s** wall; fetch/install/verify/smoke **1.803/6.946/2.751/2.930s**, total 14.460s. Existing synthetic smoke: compile 1.588s; first 4 runs 0.0090s; capped 256 x 10,000-step runs 0.6489s, **394.5 synthetic runs/sec/core**, finite/reproducible. **Not replica2 throughput or policy edges.** Measured cost justified suites and small JIT checks. ```sh timeout 470s /usr/bin/time -p scratch/runtime/venv/bin/python -B -m unittest discover -s tests -p test_gatep.py -v timeout 470s /usr/bin/time -p scratch/runtime/venv/bin/python -B tests/test_setup_fast.py -v timeout 470s /usr/bin/time -p scratch/runtime/venv/bin/python -B gatep.py --reference scratch/reference/taylor --cache scratch/cache/gatep timeout 30s /usr/bin/time -p scratch/runtime/venv/bin/python -B gatep.py --reference scratch/reference/taylor --cache scratch/cache/gatep timeout 470s /usr/bin/time -p bash setup_fast.sh --platform linux-x86_64 --cache scratch/cache timeout 60s /usr/bin/time -p bash setup_fast.sh --platform linux-x86_64 --cache scratch/cache --offline ``` | Check | Exact result | Timing | |---|---|---| | `tests/test_gatep.py` | **24 run, 24 pass, 0 skip, 0 fail, 0 error** | unittest 24.383 s; wall 24.74 s | | `tests/test_setup_fast.py` | **25 run, 24 pass, 1 skip, 0 fail, 0 error** | unittest 46.060 s; wall 46.23 s | | Actual Gate P CLI | PASS, executed gates.py | wall 8.34 s | | Same CLI/cache repeat | PASS, verified cache hit, identical stdout | wall 0.31 s | | Documented default-scratch engine setup | 16 hits, 0 downloads, fresh installation | script 10.596 s; wall 10.62 s | | Documented setup plus `--offline` | 16 hits, 0 downloads, reused installation | script 1.807 s; wall 1.83 s | The single skipped test is `MacIntegration.test_replica_only_setup_and_numba`: execution requires Darwin arm64. `MacArtifacts.test_macos_files_download_verify_and_are_arm64` **passed**, checking four downloads, Mach-O arm64 interpreter and wheel tags without executing macOS binaries. Linux integration: 12 additional downloads / 20,949,276 bytes, 4 hits, fresh install **15.543s**; offline 16 hits/reused **1.712s**; offline forced reinstall plus smokes **11.601s**. Offline tests assert fake curl was never called. Replica-only JIT returned 42 and engine import correctly failed. Hash/size/corruption/missing-cache/failed-transfer/deadline/non-HTTPS negative tests passed. ## Integrity, coverage and closure **35/35 envelopes** matched SHA256; decoded zlib originals matched size/SHA and destination bytes: **11,961,132 bytes**. Counts: Taylor 17, qt1 5, TwoComp 1, COMBO 4, tools 4, Numba 4 (bundle + 3 matching members). **52/52 tracked files** credit gtmcknight/full commit in first 12 lines; JSON `_credit` first. Credits stay in envelopes to preserve original bytes. Independently fetched the pinned recursive Taylor Git tree: ```sh timeout 40s curl -fsSL --connect-timeout 10 --max-time 30 'https://api.github.com/repos/gtmcknight/amm-sim/git/trees/4812a6382311624e1506aca131ca35c378f930d9?recursive=1' -o scratch/audit/taylor-tree.json ``` `timeout 60s scratch/runtime/venv/bin/python -B -` with stdin audit code checked non-truncated upstream tree, exact solved filenames and Git blob hashes (`sha1(b'blob '+str(len(data)).encode()+b'\0'+data)`): **17/17 match**. Also decoded/rehashed all envelopes, checked 52 headers and AST import closure; **0.327s** tool wall. Taylor closure: 13 Python modules plus README and 3 JSON files. Only external non-stdlib imports are NumPy/Numba, provided by setup. Actual Gate P consumes the included policy/QM data. Calibration: 8192 rows; oracle/T/HA/fixed30 each 2048, exactly seeds 10000..12047; no HA values regenerated. `timeout 30s bash -c '. scratch/test_setup_fast/it/env.sh; exec "$IMD_AMM_PYTHON" -B -'` with stdin code checked importlib metadata requirements using packaging markers (`extra=''`): **12 distributions, 8 active dependency edges, all satisfied**. Rehashed/sized all **20 downloads / 216,116,608 bytes**, including macOS. **1.188s** tool wall. No added dependency. | Object | SHA256 | |---|---| | `reference/sources.json` | `62147ff112987f666e2c1ad5041012276a66033baec543c2b014f766cd8f01f5` | | `bootstrap/manifest.tsv` | `f9a0c49310aa6f501eac9a760e537af444d21f556239e3f00a9ed6f1d9628dad` | | `bootstrap/pins.sh` | `cc5af39de3626b919659b5bc8ae9b5536363037a8310453a65784c3463127bcb` | | decoded Numba bundle | `a5d32e4c06dc93881821d568d8d89ca50adfdba56d5dccd92afef6c6c2157952` | | qt1 `Strategy.sol` | `c68887cff61180e12ba2b1ceb333edf76a830f91f63b5d775a8806fb9ec08aca` | | release engine wheel | `aedb68280aca34c110968f00148387c95885207913fb2cf19a1ab4c5cfd6887a` | | installed engine `.so` | `ff88b6353c2aad7342f0a26194f7347e78b9c3b38d683a7449006d423978cd14` | | Gate P input mapping digest | `0dabe003f62d413d6cb222acca4586f806e2a3f94b183d02569f04fd010f2d5e` | | Gate P stdout | `10f187b4b7d36e2d034ac4c74766f4b6670b3f766a2d291c7370050b799dcbf8` | Actual Gate P reproduced all twelve values: ```text seed perfect-info gaussian+plain gaussian+qm lattice+qm 10000 448.261189 443.455598 443.522608 443.663520 10001 576.779199 571.463409 571.623551 571.977293 10002 531.886497 525.168028 525.865859 526.411631 ``` Gate suite rejects tampering of each of 17 Taylor inputs on cache hit; checks extra/missing/symlink/bytecode, corrupt inventory/envelopes/records/values, timeout/failure/changed-during-execution and partial materialization. Three actual concurrent CLIs: **one execution, two hits, one JSON, no stage leftovers**. Python-version separation is mocked (no second Python runtime). Additional `timeout 60s scratch/runtime/venv/bin/python -B -` stdin check patched `verify_inputs` separately for commit and digest, mocked subprocess success: both distinct keys and exactly one execute call. Mock records removed; this is identity plumbing, not genuine alternate commits. With `socket.socket` blocked, materialization into scratch/offline-reference returned **35**. **1.139s** tool wall. ## Small replica and engine exercises Archived-kernel smoke ran via `timeout 120s bash -c '. scratch/runtime/env.sh; exec "$IMD_AMM_PYTHON" -B -'` with stdin Python importing `fastsim` from `scratch/reference/numba`, calling `load_tables('scratch/reference/qt1/blob.bin','scratch/reference/qt1/qmref.py',cache='scratch/audit/tables.npz')`, then `run(10000,p,tabs=tabs,n_steps=16)` for `p` in `('qmref','twocomp','combo')`, asserting finite results and timing each call. Table loading **2.32954 s**; first kernel JIT/run **15.80266 s**, edge **0.30422653341151784**; TwoComp **0.3046553352560859** in **0.000119 s**, COMBO **0.3073068900036353** in **0.000124 s**. These 16-step values are only import/JIT evidence; no full replica throughput or 1e-9 parity certification follows. Exactly **one supplied engine smoke simulation**, Vanilla vs Vanilla, seed **9700000**, `run_batch(..., [config], 8)`. Compile **0.210 s**, run **0.340 s**, 48 config-field comparisons against `_build_configs` at indices 0..3 (construction only; not simulations). Submission edge **346.0273756163182**, normalizer **346.0273756130103**; 11,970 afterSwap calls, peak gas **22,592**, all five error counters zero. Runtime 668 bytes, SHA256 `3bcbd8a295b9d9c357e76df36a08c6232f8afa692a2189c643fe0d029a9efc05`. Refusal tests passed seeds 9700001, 0 and 9699999 to the smoke and verified exit 2 before simulation; **no out-of-range engine simulation occurred**. This is not a qt1 bank or a benchmark of candidate quality. ## Reproducible defects (no repairs applied) **D1 — Medium: setup deadline is not a hard command bound.** `setup_fast.sh:206` hashes cached entries without checking the deadline; `:245` returns fetch-only success without a deadline check. `:346` checks only before unbounded verification at `:349`, and `:373` can print success after the budget expired. Extraction, pip and smoke subprocesses similarly have no remaining-time limit. This contradicts the before-budget exit promise in `setup_fast.sh:22`. Exact reproduction after the first benchmark: ```sh timeout 30s /usr/bin/time -p bash setup_fast.sh --platform linux-x86_64 --replica-only --cache scratch/cache --scratch scratch/runtime --offline --deadline 1 timeout 30s /usr/bin/time -p bash setup_fast.sh --platform linux-x86_64 --replica-only --cache scratch/cache --scratch scratch/runtime --offline --fetch-only --deadline 0 ``` Expected: exit 75 with resume hint when budget expires, no success after expiry. Actual: **both exit 0**. First reports total **1.573 s** (wall 1.59), verify 1.066 s; second reports cached success total **0.609 s** (wall 0.64) despite zero deadline. Repair: check cache paths and before success; apply remaining-time watchdog to long children and kill/reap descendants. Final checks alone cannot enforce a hard ceiling. Keep external timeout 470s. Existing test only exercises cold-cache deadline, hence passes. **D2 — Low: sourcing replica mode retains stale engine environment.** `setup_fast.sh:275` exports three variables only for engine, but has no replica `unset` branch. Exact bounded reproduction, using the suite's prepared engine environment and first benchmark's replica environment: ```sh timeout 20s bash -c '. scratch/test_setup_fast/it/env.sh; . scratch/runtime/env.sh; printf "mode=%s\n" "$IMD_AMM_MODE"; for name in IMD_AMM_ENGINE IMD_AMM_HARNESS SOLCX_BINARY_PATH; do if [[ -v $name ]]; then printf "%s remains set\n" "$name"; fi; done; test -z "${IMD_AMM_ENGINE+x}"' ``` Expected: replica mode with engine-only variables absent, as documented. Actual: prints `mode=replica`, all three names `remains set`, **exit 1**. Minimum repair: emit `unset IMD_AMM_ENGINE IMD_AMM_HARNESS SOLCX_BINARY_PATH` for replica mode and test sequential sourcing. This does not install engine packages into the replica venv; it exposes stale configuration to later consumers. ## Limitations, stale documentation and integration boundaries - **Known archived-driver limitation, not a new foundation defect:** decoded `numba/driver.py:15` unconditionally imports missing `head`; `:19` loads missing `head8.json` even in parity mode. After copying the six verified existing files named at `:6` into `scratch/audit/flat`, the bounded command `timeout 20s scratch/runtime/venv/bin/python -B scratch/reference/numba/driver.py scratch/audit/flat scratch/audit/driver-state parity` exits **1**, `ModuleNotFoundError: No module named 'head'` at line 15. This was exercised via a Python subprocess with timeout=20 inside timeout 30s, before any simulation. Do not invent HEAD8 files or weights; later parity tooling must avoid this unconditional dependency or receive genuine inputs. `docs/reference.md` already discloses both the missing HEAD8 and flattened-layout requirements. - **Stale status, separately from defects:** `README.md:20` says installer pending although it exists and passed tests; `docs/contracts.md:6` repeats that claim, and `docs/reference.md` calls the pinned installer future. Repair prose/status/link to `docs/setup.md`; no pin change needed. Pending ammfast/banks/scorer and final merged raw URLs are appropriate for this starting foundation, not audit failures. - `docs/contracts.md` fixes public vs archived policy IDs, ordered duplicate-preserving batches, finite unrounded results, residual-head validation, parity seeds, six-decimal banks/HA provenance, engine config/workers/gas/range and sample-SE stopping. Partial rounds and n<2 are delegated. No concurrent implementation was inspected or certified. - Gate P checks six-decimal upstream results, not Numba parity; once-only execution requires callers to share the selected cache. No machine fingerprint is used. - Installer review found pinned HTTPS/size/SHA fetches, no Rust or package-index resolution, pip `--isolated --no-index --no-deps --require-hashes`. Archived setup/tools were not executed. No host configuration/identifiers were inspected; default home-cache behavior was not exercised. - Documented Linux setup/Gate/materialize commands worked from absent task runtime state. External timeout is the audit wrapper, not an installer dependency. - Not run: macOS execution, other Python versions/architectures, full parity/banks/scorer, HEAD8 validation, qt1 engine simulation, source builds, OS/network tracing, hard-kill recovery beyond supplied tests. Starter/Numba upstream were not fetched again (bundled pinned bytes verified); Taylor closure was independently checked against upstream. No final merged publication commit is claimed. ## Inspection, failures, resume and acceptance Inspection commands (20s each): git rev-parse/status/ls-tree; rg --files and rg -n imports/data/run sites; cat README, docs, tests, setup, bootstrap, materializer, Gate P and .gitignore; head sources.json; nl/sed line references; cat/tail scratch logs. Initial ls found no runtime (expected). `nl .../numba/driver.py | head -24` emitted harmless broken pipe. No suite failures; D2/driver failed as reported; D1 incorrectly succeeded. Resume: rerun principal commands unchanged. Setup reuses verified downloads; `--offline --force` reinstalls. Gate shares scratch cache; remove only a diagnosed corrupt record to recompute. Materialization resumes partial extraction, rejects changes. Suites remain bounded by timeout 470s. No requester input or timed wait remains. Acceptance checklist: - [x] Only declared untracked result delivered; no source/pin changes, lockfile/submodule or staged files. - [x] First benchmark, bounded checks, scratch state, exact test totals/timings and failures recorded. - [x] Hashes/closure/data/attribution, actual Gate/cache/concurrency/tampering/identity checked. - [x] Linux cold/cached/offline/dependency/download checks and small replica/allowed engine smoke passed. - [x] Defects reproducible with file/line, severity and repair; integration/HEAD8/stale docs distinguished. - [ ] Deadline and mode-switch defects repaired (no patches permitted). - [ ] macOS execution certified (unavailable). Final checks: git diff and cached diff empty; no tracked scratch files. Report length checks initially failed during drafting; shortened and rechecked <=16000 bytes. Only this report is delivered, unstaged.