Skip to content

State safety: cache-level checks (tap v4): kernels, KV repoint, radix prefill path - #118

Merged
SamMausberg merged 2 commits into
mainfrom
state/v4-cache
Oct 1, 2026
Merged

SamMausberg merged 2 commits into
mainfrom
state/v4-cache

Conversation

@SamMausberg

Copy link
Copy Markdown
Owner

Cache-level results from the tap v4 run. The tap hashes the KV (per cached position and attention layer) and the GDN conv and SSM state that each tapped forward reads. Every run here is plain decoding or MTP steps 3, at batch 1, with the unpinned flags of the first matrix. The tap engine patch is engine/sglang/patches/state/0001-state-tap.patch.

Results

  • Plain vs MTP steps 3, 40 prompts (cachecheck_v4_plain_c1_vs_mtp_s3_c1.json): resolves the pending cache check for the plain-vs-MTP mechanism.
    • In all 40, every cache entering every forward is identical up to the first differing module output: layer 0's GDN recurrence at output index 1, the first verify against the first decode.
    • The first cache to differ is layer 0's SSM state, which that kernel writes.
    • So the decode and target-verify recurrent kernels produce different bits from identical inputs and state.
  • History pairs (history_v4_*.json): each prompt served alone, and right after its predecessor, on fresh servers. This confirms the req_to_token repoint at KV level for both pairs.
    • For mt_bench-0056 after mt_bench-0054, and humaneval-0008 after humaneval-0000, the first differing module output is layer 3's attention at output index 2.
    • The keys and values of all 8 attention layers that enter that step differ at cached positions 3–5 (6 shared tokens) and 3–21 (22 shared tokens).
    • The caches entering decode step 1 are identical.
  • Radix cache on vs off, 40 prompts (cachecheck_v4_plain_c1_radix_vs_noradix.json):
    • The 34 prompts of up to 63 tokens are identical throughout.
    • All 6 prompts longer than one 64-token GDN chunk differ in the prefill, from prompt position 1, at layer 0's GDN recurrence. No cache is read before that point.
    • The likely cause, from reading the code but not verified, is the radix-on extend kernel's checkpoint state tracking.
    • This is not KV provenance. It means radix-off runs differ from radix-on runs from the first output token for those prompts.
  • humaneval-0044 same-server repeats (repeats_v4_h44_*.json): this is a second history mechanism, separate from the repoint.
    • Flushed between repeats: 4 of 4 are bitwise identical.
    • Not flushed, the second request's full 128-token prefill differs from position 1, and later requests reuse a 64-token cached prefix and differ from position 64.
    • So the GDN prefill depends on what the radix tree holds.
  • Tap neutrality: the v4 tap changes the same five prompts as v3.

Code

  • mechanism.py no longer compares caches at a prefill with no cached prefix. Its GDN slot can hold an earlier request's state, which the kernel ignores (has_initial_state is false). Before this change, that stale state showed up as spurious "cache" origins. There is a unit test for this.
  • compare_repeats writes a run path relative to the data root.
  • pools.py also covers cachecheck_* and history_v4_*.
  • run_tap_v4.sh records the run's commands. The run itself used a scratch copy that named its outputs mechanism_v4_*. The committed summaries were regenerated from the tap data with this mechanism.py.
  • The summaries are named cachecheck_v4_* rather than mechanism_*, so the paper's first-difference figure input doesn't change.

Checks

  • The host-identity hook passes.
  • No absolute paths appear in the new evidence.
  • 28 state tests pass, and pre-commit passes, including mypy and shellcheck.

The tap v4 run hashes the caches each forward reads. With it:
- Plain vs MTP steps 3, 40 prompts: every entering cache is identical up to
  the first differing module output, layer 0's GDN recurrence at the first
  verify. So the decode and verify recurrent kernels differ from identical
  inputs and state.
- Both history pairs: K and V of all attention layers differ at the shared
  prefix positions 3+ from decode step 2, and are identical at step 1. This
  confirms the req_to_token repoint at KV level.
- Radix on vs off: the 6 prompts longer than one 64-token GDN chunk differ in
  the prefill from prompt position 1. The 34 shorter ones are identical.
- humaneval-0044 same-server repeats: the GDN prefill differs depending on what
  the radix tree holds, a second history mechanism; flushed repeats are
  identical.

mechanism.py no longer compares caches at a prefill with no cached prefix,
whose stale GDN slot the kernel does not read. compare_repeats writes a path
relative to the data root. pools.py covers the new summaries.
run_tap_v4.sh records the run's commands.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T13:27:30.543599Z cb8b9df Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2be8dd58b4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread experiments/state_safety/run_tap_v4.sh Outdated
rm -rf "$T"/v4_*

echo "v4 smoke $(date +%T)"
python tap_runs.py --config plain --concurrency 1 --tap-ids "$T/ids_smoke.txt" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Create the v4 input manifests before reading them

When this script is invoked as documented on a fresh data tree, tap_runs.py immediately reads $T/ids_smoke.txt, but neither this script nor any tracked generator creates that file; the later ids_v4.txt, limits_c1.json, and ids_h44.txt inputs are likewise absent from the repository and undocumented. The run therefore stops with FileNotFoundError before collecting any sessions, so these manifests need to be generated by the script or checked in at a stable path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cb8b9df. The prompt lists and per-prompt token limits that run_tap_v4.sh reads (ids_smoke.txt, ids_v4.txt, limits_c1.json, ids_h44.txt) are now committed in experiments/state_safety/tap_v4_inputs/, and the script reads them from there. The four files have the same content as the ones the run used; limits_c1.json only gained a final newline from the end-of-file hook. The history-pair ID files are still generated by the script.

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: REQUEST CHANGES

Review on the exact head 2be8dd5 ("Add the cache-level checks from the tap v4 run").

Verified

  • Regeneration. With this head's mechanism.py and the tap data in ~/vp-data/state/tap, the six summaries regenerate byte-identical on one core in 36 s: both cachecheck_v4_*.json, both history_v4_*.json and both repeats_v4_h44_*.json.
  • Plain against MTP steps 3. In 40/40 prompts the first difference is layer 0's gdn_core at output index 1 (DECODE against TARGET_VERIFY), every origin is module, and the first cache to differ is layer 0's SSM.
  • History pairs. In both, layer 3's attention differs first at output index 2. The keys and values of all 8 attention layers (16 caches) differ entering that step, at positions 3-5 (3 positions) and 3-21 (19 positions). Earlier steps are identical.
  • Radix on against off.
    • The 34 prompts of at most 63 tokens show no difference.
    • The 6 that differ have 67, 68, 68, 216, 225 and 353 tokens, and differ from prompt position 1 at layer 0's gdn_core with origin module.
    • tap_check shows the same five tap-changed prompts as v3's tap_check.json.
  • humaneval-0044.
    • Flushed between repeats, 4 of 4 are bitwise identical.
    • Not flushed, r1 (a 128-token prefill) differs from position 1, and r2 onwards (64-token extends) differ from position 64.
  • The post-data change to mechanism.py is a genuine fix, shown from this run's own artifacts.
    • All 38 "cache" origins in the pre-change summaries (~/vp-data/state/tap/mechanism_v4_*.json: 4 plain-against-MTP, 34 radix) were at a forward where both runs had cached == 0, and only GDN conv and SSM state differed (no KV).
    • That stale state was not used. In 31 of those 34 radix prompts (the short ones) the module outputs are bitwise identical throughout, although the stale slot state entering the prefill differed. In the remaining 3, and in all 4 plain-against-MTP prompts, position 0, which the initial state would affect first, is identical.
    • So skipping cache comparison at a prefill with nothing cached removes only reads that do not happen.
  • Tests and hooks. The three state test files give 24 passed. Pre-commit passes on origin/main..HEAD.
  • Hygiene. The hostname does not appear in the tip (runtime search), there are no absolute paths in the added lines, and the commit is by Samuel Mausberg with no AI lines.

Blocking

  1. The stated mechanism is right for the conv state but not for the SSM state.
    • The README and the new code comment say the stale slot is ignored because "has_initial_state is false". At the pin, that flag gates only the convolution (_convolve_prefill: has_initial_state=forward_batch.extend_prefix_lens > 0).
    • The chunked SSM prefill reads ssm_states[cache_indices] as its initial state unconditionally (gdn_triton.py, initial_state=recurrent_state). A fresh slot's SSM state is zeroed before the forward by model_runner's clear_slots(mamba_clear_indices), for requests with mamba_needs_clear set.
    • Please state both mechanisms, and add the run's own evidence: the 31 short radix prompts were identical despite differing stale state, and every remaining case has an identical position 0.
  2. "Their first logprob difference is at output index 0" has no committed source. The radix cases record no log-probability field, and the agent says the figure comes from client.jsonl in the tap data, which is not committed. Add the first log-probability difference per case to cachecheck_v4_plain_c1_radix_vs_noradix.json, as tap_check.json does for v3, or drop the sentence.
  3. Codex P2: create the v4 input manifests before reading them (State safety: cache-level checks (tap v4): kernels, KV repoint, radix prefill path #118 (comment)). It has no reply yet.
    • run_tap_v4.sh reads ids_smoke.txt, ids_v4.txt, limits_c1.json and ids_h44.txt from ~/vp-data/state/tap, and no tracked file creates them. The run cannot be reproduced from the repository.
    • Commit those four small files next to the script (or generate them in it), and point the script at the committed copies.

Suggestion (non-blocking). The radix paragraph's "From reading the code ... track_state, state_checkpoint_* ... it has not been verified" is labelled correctly. A one-line pending item for the check would make the follow-up visible.

… commit tap inputs

Reviewer on #118:
1. The cache hashes are taken in state_tap.begin, before the forward's deferred
   mamba clear zeroes a fresh slot. So a fresh prefill's hash shows leftover
   state, while the forward reads zeros: the SSM chunk prefill reads the cleared
   slot, and the conv reads no initial state. The code comment and README now
   say so, with the run's evidence: 38 such cases, all at fresh prefills in GDN
   state only, 31 radix pairs identical throughout, 7 identical at the first
   position.
2. mechanism.py records first_logprob_difference per case. The radix file now
   shows output index 0 for the 6 long prompts and no difference for the 34
   short ones.
3. Codex P2 r4155748473: run_tap_v4.sh's prompt lists and token limits are
   committed in tap_v4_inputs/ and read from there.
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE (provisional: Codex's review of cb8b9df was still running when I posted this. I will re-check its threads on this head before merge.)

Re-review on the exact head cb8b9df ("Correct the fresh-prefill rule's wording; record logprob differences; commit tap inputs").

  • Blocking item 1 (mechanism) is fixed.
    • The code comment and the README now say that the tap hashes in state_tap.begin, before _forward_raw runs the deferred clear_slots. The state-tap patch calls state_tap.begin right before _forward_raw, and at the pin _maybe_execute_deferred_mamba_cow_and_clear runs inside it, so the order is right.
    • The SSM chunk prefill then reads the zeroed slot, and the convolution reads no initial state.
    • The README cites the run's own evidence: the 38 old "cache" origins, the 31 identical radix pairs, and the other 7 identical at the first position. These are the counts I recomputed from the pre-change mechanism_v4_* outputs.
  • Blocking item 2 (log-probability source) is fixed.
    • mechanism.py records first_logprob_difference per case. In the radix file it is 0 for all six prompts longer than 64 tokens (67 to 353 tokens) and None for the other 34.
    • It is 1 for the plain-against-MTP file and 2 for both history files.
    • In all four files, only the new field changed against 2be8dd5.
  • Blocking item 3 (Codex P2 r4155748473) is fixed and has a reply. The four tap inputs are committed in experiments/state_safety/tap_v4_inputs/, and run_tap_v4.sh reads them from there. ids_smoke.txt, ids_v4.txt and ids_h44.txt are byte-identical to the files the run used, and limits_c1.json differs only by a final newline.
  • Regeneration. With cb8b9df's mechanism.py, all six summaries regenerate byte-identical from the tap data on one core.
  • Tests and hooks. The three state test files give 24 passed. Pre-commit passes on origin/main..HEAD. The commit is by Samuel Mausberg, with no AI lines.

Blocking: none. Suggestions: none.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: cb8b9dfdee

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE (confirmed on cb8b9df)

Codex finished its review of cb8b9df at 13:27:29 with "Didn't find any major issues". gh api --paginate shows no review threads on cb8b9df. The only earlier Codex thread (r4155748473) has a reply and a fix. My provisional approval (#118 (comment)) now stands without condition. The branch head is still cb8b9df.

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.

1 participant