Skip to content

stats/dashboard: prompt cache, disk tier and FSR cache on /stats and the dashboard (#2655) - #2682

Merged
ashhart merged 2 commits into
ashhart:mainfrom
volfco:dashboard-cache-2655
Nov 11, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
volfco:dashboard-cache-2655

Conversation

@volfco

@volfco volfco commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Closes #2655.

What

/stats and the --dashboard page now show the cache state the engine already tracks but never displayed.

  • Prompt cache. States, hits, held bytes against budget, cached tokens and prefill reuse. A table lists the 64 most recently used states with these columns: id, token position, bytes, shared/branched, borrowers, hits, created time and last access time.
  • Entry id. Each entry's id is the stem of the name the disk tier gives its .st file. Without a disk tier it is the same hash with an empty identity. The table shows the first 12 hex characters, and hovering shows <id>.st.
  • Disk tier, when present. Read and write counts, a latency histogram (p50/p95), last and EMA latency, last read and write time, queue depth, read-ahead counts and failures. A cap of 0 shows as "no cap".
  • FSR SSD-expert cache (Flash Next on Metal). Hits, evictions and occupancy, published behind a spinlock after each serve(job).
  • Header and memory. /stats also gains cached_tokens_total, preemptions_total, requests_requeued, the p50 latency and TTFT medians, and model/version/backend/device. The header shows the model name.

How

  • Snapshots. The engine thread copies the store into api.Status under the host mutex in noteLive. HTTP threads never read the store directly.
    • A full copy happens at most once a second.
    • Every other round only updates states and bytes, which /metrics reads.
  • Timing fields. prompt_cache.Entry gains one seen: Seen field holding wall-clock created and last-use times, hits and the id. It is for display only and never feeds eviction policy.
    • note moved to prompt_cache_note.zig to keep prompt_cache.zig under the 600-line cap.
  • Code layout. The /stats builder is in the new server/stats_snapshot.zig, and its tests moved there.

Testing

🤖 Generated with Claude Code

@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Thank you @volfco, this is a useful page, and the store side reads cleanly: eviction still orders by the store clock, so replies can't change. A few things before it can go further:

  1. A rebase. The CHANGELOG conflict means CI hasn't run on 9d6e30cc yet.

  2. The Metal build.

    • native/flashnext_host.zig:7 imports ../core/prompt_cache_status.zig from outside its module.
    • Lines 255-256 pass a Store value (|s| on ?pc.Store) where a pointer is expected (|*s|).
    • fsr_runtime.zig:8 imports core/engine_status.zig relatively, though engine_api already owns that file.

    We don't think the Flash Next host builds as it stands. Exporting the new file through engine_api and building on macOS should show it.

  3. The hot path. syncSnapshot runs at the top of after() (fsr_runtime.zig:190), once per MoE layer per pass. Each call is a slot scan plus a spin gate. Could it publish at most once a second, as the lane host does, from a running count?

  4. A hash on every keep. Seen.of (prompt_cache.zig:505, :535) hashes the whole kept prefix for every family, with the dashboard on or off. Could it run only when the dashboard is on?

  5. The SSD-expert tile. Only the single-driver Flash Next host fills .fsr; the shared host never does.

Two comment lines are over 120 columns (fsr_runtime.zig:11, dashboard.html:319). Three commits carry AI co-author trailers; please drop them, or we'll squash at landing with your authorship.

@volfco

volfco commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart, all addressed in f7f65f8 on a fresh rebase:

  1. Rebased; CHANGELOG conflict resolved.
  2. flashnext_host reads the copies through api.prompt_cache.status and passes |*s|; fsr_runtime keeps its own Counts (no engine_status.zig import) and Status.FsrCache.from copies it on the host side. Both Flash Next hosts now type-check for aarch64-macos (the old head failed with "file exists in modules 'engine_api' and 'core'"). That is a cross-target compile check from Linux, not a run on a Mac.
  3. after() only counts; the clock is read every 256 calls and the copy runs at most once a second, plus once when a single-host reply ends. On the shared host the last second of counts shows after the next pass, since it has no single end-of-reply point to publish from.
  4. Seen.of hashes only while --dashboard is on, set before the engine loads.
  5. The shared lane host reports fsr through an FsrSource the batch host fills.

Both long lines fixed; lean shows 0 new findings.

On the trailers: please squash at landing with my authorship. That drops the AI co-author trailers from the three earlier commits without another force-push.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @volfco, that covers all five points and the two long lines:

  • the Flash Next host reads the copies through api.prompt_cache.status and passes |*s|, and fsr_runtime.zig keeps
    its own Counts;
  • after() now only counts, reads the clock every 256 calls and copies at most once a second, plus once when a reply
    ends (fsr_runtime.zig:91-101, flashnext_host.zig:254);
  • Seen.of names a state only while --dashboard is on (prompt_cache_status.zig:24-25), with a test;
  • the shared host reports fsr through its FsrSource.

One more rebase, sorry. The prompt-cache work in #2699 landed on main after your push and moved two of the functions
you touched. resumedWithReason is now in prompt_cache_lifetime.zig (its e.used = s.clock is at :40), and
keepBorn is in prompt_cache_keep.zig (:23 and :76), so prompt_cache.zig conflicts. Your seen updates need
to move with them, plus the shared-cut entry at prompt_cache.zig:456. used should stay the store's clock, as it
already is in your version. Please post the prompt-cache host tests after the rebase.

We'll squash at landing with your authorship, which drops the trailers, and we'll fix the CHANGELOG line's PR number
and credit. You've only cross-compiled the Flash Next host, so we'll build and run it on a Mac ourselves. We'll check
dashboard on and off, replies equal to main, and decode no slower.

@volfco
volfco force-pushed the dashboard-cache-2655 branch from f7f65f8 to f2f5027 Compare November 11, 2026 01:55
@volfco

volfco commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart. Rebased onto main after #2699 in f2f5027 (the six commits squashed into one, since five of them conflicted on the same lines).

The seen updates moved with the functions:

  • prompt_cache_lifetime.zig:40 (resumedWithReason): e.used = e.seen.hit(s.clock);
  • prompt_cache_keep.zig:23 (a re-keep of the same state): e.used = e.seen.touch(s.clock);
  • prompt_cache_keep.zig:76 (a new entry): .seen = .of(s, last[0..n], decoded, starts, at);
  • the shared-cut entry at prompt_cache.zig:457 keeps its own .seen = .of(...).

used stays the store's clock. The rest of the diff is unchanged from f7f65f8.

Tests after the rebase:

  • zig build test-prompt-cache-host: 592/592 pass (main: 586). The lane host: a packed decision failed (DeviceLost) line in its output also appears on main, from lane_host_score_test.
  • test-flashnext-fsr-owner-host and test-flashnext-scheduling-host: 68 pass, 4 skipped.
  • test-http-limits-host (compiles the server module with stats_snapshot.zig and status_routes.zig): 29/29 pass.
  • tools/pr_check.py: lean 386 vs 386, 0 new.

The Flash Next host wasn't cross-compiled again this round; thanks for building it on a Mac.

@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thanks @volfco, the rebase reads right: resumedWithReason now sets e.used = e.seen.hit(s.clock) (zig/src/core/prompt_cache_lifetime.zig:40), a re-keep touches it (prompt_cache_keep.zig:23), a new entry gets .seen = .of(...) (:76), and the shared-cut entry keeps its own (prompt_cache.zig:457), with used still the store's clock. Everything from the last round is still in place, the 1 Hz copy and the end-of-reply publish included, and the squash drops the trailers. Thanks for the host test results.

One small question for the squash at landing: the commit's author address is [email protected]. We usually land commits under a GitHub noreply address; would you like us to use yours (<id>[email protected]), or keep this one?

From here it's ours: we'll build the Flash Next host on a Mac and check dashboard on and off, replies equal to main, and decode no slower, then land it with the CHANGELOG line fixed.

  • Synthena (Ash's Agent)

@volfco

volfco commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Using the github email is fine

@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@volfco one last thing before this can land: our landing step refused it because the branch's commits carry an email address that isn't a GitHub noreply address, and landing would publish it in main's history. Could you re-commit them with your noreply address (GitHub Settings → Emails shows it, in the form [email protected]) and force-push? For example:

git config user.email '[email protected]'
git rebase --exec 'git commit --amend --no-edit --reset-author' $(git merge-base HEAD origin/main)
git push --force-with-lease

Nothing else changes; it goes straight back on the landing queue once the new head's CI is green. Sorry we didn't catch it at review.

  • Synthena (Ash's Agent)

@ashhart
ashhart force-pushed the dashboard-cache-2655 branch from f2f5027 to f2e588a Compare November 11, 2026 03:29
@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thanks @volfco, done: the commit is re-authored with your noreply address and nothing else changed (same tree). It goes back on the landing queue once CI is green on the new head.

  • Synthena (Ash's Agent)

volfco and others added 2 commits November 11, 2026 06:39
…the dashboard (ashhart#2655)

The branch's six commits squashed and rebased onto main after ashhart#2699. The `seen` updates move with the functions
ashhart#2699 moved: a resume in `prompt_cache_lifetime.zig` (`resumedWithReason`), a re-keep and a new entry in
`prompt_cache_keep.zig` (`keepBorn`); the shared-cut entry in `prompt_cache.zig` keeps its own. `used` stays the
store's clock.
@ashhart
ashhart force-pushed the dashboard-cache-2655 branch from f2e588a to e7de167 Compare November 11, 2026 06:39
@ashhart
ashhart merged commit b5a9f92 into ashhart:main Nov 11, 2026
2 of 10 checks passed
@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thank you @volfco. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@volfco a heads-up, nothing for you to do: zig build test-native (which CI doesn't run) showed two of flashnext_host.zig's own tests crashing after this landed. They build a host with no engine, and status() now reads h.eng.r.fsr. #2876 keeps the FSR pointer on the host, set at open, the same way your change already publishes the cache figures. Served behaviour was never affected.

  • Synthena (Ash's Agent)

ashhart added a commit that referenced this pull request Nov 11, 2026
…he engine

#2682 had status() and the serve loop read h.eng.r.fsr. The host's own tests build a
Host with eng undefined, so a status poll dereferenced it and two of them crashed with
SIGSEGV in test-native. The host now keeps the engine's FSR runtime pointer, set at
open beside the GDN pipe, and both reads go through it. Served behaviour is unchanged.
ashhart added a commit that referenced this pull request Nov 11, 2026
Scope and figures corrected to the PRs (#2700, #2670, #2338, #2491,
#2680, #2557, #2597, #2760's load time, #2753's verify-row wait, #2681's
ledger row), #2831's and #2682's lines rewritten to what the code does,
#2709 given its own line above #2609's, the duplicate #2404, #2576,
#2597 and #2699 entries and the copy of #2609's line under 1.2.6
removed, entries spaced one blank line apart, and the released sections
restored to the v1.2.6 tag's text (#1651's 1.2.2 line and six blank
lines in 1.2.5 and older).
@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thanks @volfco! This is in TensorFold 1.2.7, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.7

  • Synthena (Ash's Agent)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dashboard: show prompt-cache hits, entries, last access and disk-tier latency

2 participants