Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions docs/flashnext-cache-admission.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Flash Next short snapshot admission

This branch tests whether admitting snapshots from 2048-token prompts can retain short-dialog reuse without displacing expensive long prefixes. The guard applies to the shared Flash Next host. Other families keep the existing policy through `protect_from = 0`.

A new mark below token position 4096 may replace shorter entries, but cannot evict an entry saved at position 4096 or later. Long marks retain the existing eviction order. Classification uses the saved position; capacity checks use actual retained bytes and conservative allocation estimates. The policy does not pin all older entries merely because they are longer than a new request.

Admission runs before reservation and again before a save. A rejected short mark must preserve existing entries. Planning counts all accepted marks together, preserves the lookup state until restoration, and accounts for spare buffers that cannot be trimmed. Candidate selection prioritizes larger marks, but recalculates the complete tentative demand in ascending keep order. At most one mark claims the reusable pool, charging all its spare bytes as a conservative upper bound. This can reject a feasible allocation when the pool contains several suitable buffers; it avoids assuming that several marks can spend the same buffer.

Long states can occupy the budget indefinitely during an exclusively short workload. Short snapshots may then be refused. The hardware qualification measures warm short reuse before filling the long cache, followed by a mixed pressure trace in the same server. It does not require a short hit after protected long states exhaust the budget.

## Qualification

The candidate and both controls start from upstream `e7c523ebfa16b8094cf9e35e3773a7d25befcc5b`, using Zig 0.17.0. The completed hardware matrix alternated cache off, 4K admission, unprotected 2K admission, protected 2K admission, protected 2K admission, unprotected 2K admission, 4K admission, and cache off.

Each of eight server blocks has 72 dialog responses, 12 shared-session responses, 12 pressure responses, four completed cancellation-peer/reuse responses, and one aborted stream. The independently audited receipt confirms 800 completed responses, including 96 completed thinking responses, plus eight aborted streams.

The matrix uses an M3 Ultra, the existing six-bit checkpoint, four native slots, a 24576-token context, a 2 GiB RAM snapshot budget, and MTP chaining disabled. Shared groups run before all long dialogs in every mode. Their timings are not directly comparable with the older threshold receipt, which used a different section order. This experiment does not qualify the production four-bit service, tensor parallelism, vision, or Thunderbolt coupling.

The original launchd service is drained and temporarily stopped for the GPU run. The reviewed wrapper terminates its controller process group and remaining owned native processes before restoring that service. A failed restore keeps the session lock and returns a failure status. Hardware timings and restoration evidence belong in a separate receipt; local tests alone do not establish deployment or a performance gain.

## M3 Ultra result

The protected mode retains short reuse and protects both long revisits in both pressure traces. Against 4K admission, 2048-token dialog time falls from 8.976 to 3.834 seconds, thinking dialog time from 10.340 to 5.119, and warm four-session group time from 9.861 to 2.272. Mixed pressure takes 37.237 seconds versus 37.194 for 4K and 53.358 for unprotected 2K. The small 0.12% difference versus 4K is not a claimed improvement.

All response signatures and cache counters passed the independent audit. All observed swap probes reported zero usage. The original service was restored healthy. The [complete receipt](receipts/flashnext-cache-admission-2026-10-11/README.md) includes the failing pool-order regression, stopped first attempt, final matrix, local checks and measurement limits.
100 changes: 100 additions & 0 deletions docs/receipts/flashnext-cache-admission-2026-10-11/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Flash Next protected 2K snapshot admission

All eight server blocks completed 800 HTTP responses, including 96 thinking responses, plus eight cancelled streams. Answer content, reasoning content, finish reasons, token usage and native 12-hex generation fingerprints match frozen cache-off references. A fresh checkpoint gate separately compares full generated token sequences.

The protected policy changes mixed-pressure time by +0.12% versus 4K admission and -30.21% versus unprotected 2K admission. Its warm four-session group takes 2.272 seconds, a 76.96% reduction versus 4K. These results cover one M3 Ultra and a 2-GiB snapshot budget.

## Complete dialogs

Each dialog includes the cold first prompt, regeneration, a follow-up and an edited follow-up. Seconds are medians of six observations per case and mode: three distinct public fixtures across two fresh server processes. Positive reductions mean the protected mode finishes sooner.

| Prime length and mode | Cache off | 4K | 2K | Protected 2K | Reduction vs 4K |
|---|---:|---:|---:|---:|---:|
| 2,047, plain | 8.871 | 8.863 | 7.147 | 7.149 | 19.33% |
| 2,048, plain | 8.985 | 8.976 | 3.835 | 3.834 | 57.29% |
| 2,049, plain | 9.056 | 9.063 | 3.911 | 3.909 | 56.86% |
| 2,048, thinking | 10.349 | 10.340 | 5.126 | 5.119 | 50.49% |
| 8,192, plain | 25.687 | 8.109 | 8.114 | 8.114 | -0.07% |
| 16,384, plain | 50.049 | 14.181 | 14.183 | 14.196 | -0.10% |

The 2,047-token boundary prevents new admission for the prime. Existing states remain eligible for lookup; later turns can cross the admission threshold. Thinking uses a 512-token ceiling and every thinking response finishes with `stop`, nonempty reasoning and visible final content. Plain dialog replies use 64 tokens, pressure replies 32, and cancellation peers and replacements 512.

## Cold first-prompt cost

| Case | 4K | 2K | Protected 2K |
|---|---:|---:|---:|
| 2,047, plain | 2.403 | 2.408 | 2.409 |
| 2,048, plain | 2.464 | 2.476 | 2.475 |
| 2,049, plain | 2.505 | 2.512 | 2.512 |
| 2,048, thinking | 2.618 | 2.629 | 2.622 |
| 8,192, plain | 6.691 | 6.692 | 6.693 |
| 16,384, plain | 12.778 | 12.784 | 12.788 |

## Four sessions and mixed pressure

| Mode | Warm four-session group | Mixed trace |
|---|---:|---:|
| off | 9.866 | 54.966 |
| 4k | 9.861 | 37.194 |
| 2k | 2.264 | 53.358 |
| protected | 2.272 | 37.237 |

Warm times use four groups per mode, with a common system prefix and fresh user suffixes. Every group reaches four active slots. Shared groups precede all long dialogs in every block. The older threshold experiment used a different order and is not a timing control.

The mixed trace primes 16K and 8K prefixes, inserts six distinct 2K prefixes, then revisits both long prefixes and two short prefixes. There are two traces per mode. New short marks cannot evict states saved at position 4096 or later in the protected mode. Long states can fill the budget and cause short admission refusals.

| Block | Mode | Short-prime evictions | Revisited 16K: cached tokens / seconds | Revisited 8K: cached tokens / seconds |
|---|---|---:|---:|---:|
| 0 | off | 0 | 0 / 12.382 | 0 / 6.329 |
| 1 | 4k | 0 | 16377 / 0.450 | 8185 / 0.470 |
| 2 | 2k | 2 | 0 / 12.418 | 0 / 6.346 |
| 3 | protected | 5 | 16377 / 0.451 | 8185 / 0.471 |
| 4 | protected | 5 | 16377 / 0.453 | 8185 / 0.473 |
| 5 | 2k | 2 | 0 / 12.409 | 0 / 6.344 |
| 6 | 4k | 0 | 16377 / 0.452 | 8185 / 0.474 |
| 7 | off | 0 | 0 / 12.390 | 0 / 6.332 |

`analysis.json` exposes every block and stage separately. The first and last cache-off blocks use different unprotected control binaries. The independent auditor recomputes timings and cache counters from the full HTTP receipt and eight native logs. Native retained-plus-spare accounting stays within 2048 MiB in every cache-enabled log; these counters have whole-MiB precision.

## Memory and restoration

| Block | Mode | Maximum observed physical footprint, GiB | Samples |
|---|---|---:|---:|
| 0 | off | 174.139 | 99 |
| 1 | 4k | 176.106 | 64 |
| 2 | 2k | 176.141 | 52 |
| 3 | protected | 176.143 | 49 |
| 4 | protected | 176.142 | 49 |
| 5 | 2k | 176.142 | 52 |
| 6 | 4k | 176.097 | 64 |
| 7 | off | 174.142 | 99 |

Physical footprint was sampled every five seconds. The table reports the maximum observed sample, not a lifetime peak. All swap probes, including checkpoint-gate probes, report zero usage. Raw PID and wall-clock records remain outside the repository.

The original launchd service was drained before the GPU run and restored healthy afterwards. `lifecycle.json` records the final health check, unchanged launchd plist, closed benchmark port, stopped owned processes and removed session lock. The tested candidate was not promoted to the regular service.

## Validation and limits

The candidate and both controls use upstream `e7c523ebfa16b8094cf9e35e3773a7d25befcc5b` and Zig 0.17.0. `build-pins.json` records source commits and transferred binary/helper hashes. The candidate policy is `c3abc209398a5db614610c731954e5ad85529087`; native HTTP and tokenizer code use ReleaseSafe, the engine uses ReleaseFast, and the checkpoint gate uses ReleaseFast.

The clean dependent PR passed 70 cache tests, 1327 of 1329 host/native/golden tests with two skips, and all 881 workflow-target tests. Whole-tree formatting passed. `packaging-validation.json` records the commands, logs and non-documentation source fingerprint matching the measured candidate. Earlier candidate reruns reused cached tests; their separate counts remain in `manifest.json`. Lean reports 534 inherited problems, matching the upstream and pre-policy baselines, with no new normalized finding. Golden checks have ten inherited differences and zero unexpected differences. These local results do not establish GitHub CI status.

The first hardware attempt was stopped after 74 recorded cache-off responses in an incomplete run when review found that largest-first allocation estimates could underreserve ascending saves. It is retained under `attempt-1/` and excluded from timing comparisons. A whole-buffer regression test failed before the correction and passed afterwards. The second attempt rebuilt the candidate, verified all transferred hashes and reran the checkpoint gate.

Four native slots, a 24576-token context and the existing six-bit MTP checkpoint were used. MTP chaining and learned disk states were disabled. The production four-bit model, larger contexts, additional slots, vision and Thunderbolt coupling are outside this experiment. The policy can refuse a feasible admission when several reusable buffers would fit; it charges all spare bytes once as a conservative upper bound. Protected long states can persist during short-only workloads.

Each cancellation observes four occupied slots, one disconnected stream and three remaining active peers before reusing the free slot. All peers and replacements match cache-off references. HTTP equality uses response fields and truncated fingerprints; it is not a full token-ID proof.

Reproduce the receipt analysis with Python 3.11 or newer:

```sh
python3.11 analyze.py http.json.gz > analysis-recomputed.json
```

Reproduce the hardware matrix only on an idle, coordinated device:

```sh
python3.11 tools/zig/flashnext_cache_threshold.py \
/path/to/4k-native /path/to/2k-native /path/to/6bit-checkpoint /path/to/output \
--rounds 3 --protected /path/to/protected-native
```
Loading
Loading