Skip to content

fix: record activation cache prefix identities - #1041

Merged
ndizazzo merged 3 commits into
mainfrom
codex/issue-683-record-identities
Jul 26, 2026
Merged

fix: record activation cache prefix identities#1041
ndizazzo merged 3 commits into
mainfrom
codex/issue-683-record-identities

Conversation

@ndizazzo

@ndizazzo ndizazzo commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Closes #683.

Summary

  • record every eligible prefix identity for resident activation frames
  • preserve identity/frame token-count continuity and reject ambiguous cached records
  • apply per-identity accounting and telemetry to chunked/full binary and OpenAI prefill paths
  • extract binary activation-cache accounting into its owning module

Validation

  • cargo test -p skippy-server --lib (277 passed)
  • cargo clippy -p skippy-server --all-targets -- -D warnings
  • cargo check -p mesh-llm
  • cargo clippy -p mesh-llm --all-targets -- -D warnings
  • cargo test -p skippy-protocol --lib
  • just test-all

Summary by CodeRabbit

  • New Features
    • Expanded activation-cache support to record/restore multiple matching activation entries.
    • Added per-entry activation-cache telemetry for binary KV decisions (including recorded and evicted metrics).
    • Centralized “completed prefill” binary KV recording for more consistent accounting.
  • Bug Fixes
    • Strengthened activation-cache identity validation to avoid incorrect restores when token counts or payload/descriptor sizes differ.
    • Improved eligibility and shape checks to reduce ambiguous or mismatched restorations.
  • Tests
    • Updated and expanded coverage for multi-record activation flows, restoration correctness, and rejection scenarios.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Resident activation recording now returns multiple validated cache records, with stricter restoration checks. Binary transport centralizes completed-prefill accounting and emits telemetry per record, while frontend prefill handling iterates over all activation records.

Changes

Resident activation recording

Layer / File(s) Summary
Multi-record activation caching
crates/skippy-server/src/kv_integration/activation.rs
Recording derives multiple candidate identities and returns one record per cached entry; restoration validates token and payload metadata, with tests covering shared prefixes, mismatches, ambiguity, and flagged frames.

Binary transport accounting and completed-prefill recording

Layer / File(s) Summary
Binary transport accounting and completed-prefill recording
crates/skippy-server/src/binary_transport.rs, crates/skippy-server/src/binary_transport/activation_cache.rs, crates/skippy-server/src/binary_transport/binary_kv.rs, crates/skippy-server/src/binary_transport/binary_messaging/*
Binary transport aggregates multiple activation records with saturating counters, emits per-record telemetry, and centralizes full versus incremental completed-prefill recording.

Frontend activation telemetry

Layer / File(s) Summary
Frontend activation telemetry
crates/skippy-server/src/frontend/prefix_cache.rs
Embedded stage-zero prefill iterates over activation records and emits per-record telemetry decisions, with updated empty-result fallback logic.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: michaelneale, i386

Sequence Diagram(s)

sequenceDiagram
  participant BinaryConnection
  participant PrefillRecording
  participant KvStageIntegration
  participant ActivationCache
  participant Telemetry
  BinaryConnection->>PrefillRecording: record_completed_prefill
  PrefillRecording->>KvStageIntegration: record_resident_activation
  KvStageIntegration->>ActivationCache: store candidate activation identities
  ActivationCache-->>KvStageIntegration: activation records
  KvStageIntegration-->>PrefillRecording: activation records
  PrefillRecording->>Telemetry: emit per-record binary KV decisions
  PrefillRecording-->>BinaryConnection: BinaryKvRecordResult
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and matches the main theme of recording activation-cache prefix identities.
Linked Issues check ✅ Passed The PR updates the listed sites to record multiple identities and per-record telemetry, matching issue #683.
Out of Scope Changes check ✅ Passed The changes stay focused on the record_identities migration and related accounting and telemetry refactors.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/issue-683-record-identities

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/skippy-server/src/binary_transport/binary_messaging/connection.rs (1)

83-102: 📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift

File exceeds the 1,000-line modification threshold.

handle_binary_connection and its surrounding module already run well past 1,000 lines, and this PR modifies it (lines 804-823) without extracting a separable responsibility to bring it under the limit.

As per coding guidelines: "When modifying a Rust file already over 1,000 lines, extract any separable responsibility into a named module, keep the new file under 1,000 lines, and move or add its tests with the extracted behavior."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/skippy-server/src/binary_transport/binary_messaging/connection.rs`
around lines 83 - 102, Extract a separable responsibility from
handle_binary_connection and its surrounding binary messaging logic into a named
Rust module, keeping the new module under 1,000 lines. Move or add tests for the
extracted behavior alongside that module, and update handle_binary_connection to
delegate to it while preserving existing behavior.

Source: Coding guidelines

🧹 Nitpick comments (1)
crates/skippy-server/src/kv_integration/activation.rs (1)

98-124: 🚀 Performance & Scalability | 🔵 Trivial | ⚖️ Poor tradeoff

Consider sharing prefix bytes instead of cloning per candidate.

activation_prefix_frame clones the full frame payload for the exact-match case and clones-then-truncates for each grid-floor candidate. With shared_prefix_record_limit > 1, every recorded prefill pays for N copies of the (potentially large) activation payload. Since every candidate is a strict byte-prefix of the same buffer, a shared/reference-counted buffer (e.g. Arc<[u8]> or bytes::Bytes) could avoid the repeated allocation/copy on this hot path — though this would require touching the ActivationFrame payload representation in skippy-runtime.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/skippy-server/src/kv_integration/activation.rs` around lines 98 - 124,
Update activation_prefix_frame and the ActivationFrame payload representation to
use a shared/reference-counted byte buffer, such as Arc<[u8]> or bytes::Bytes,
so exact-match and truncated prefix candidates share the original allocation
instead of cloning payload bytes. Preserve the existing validation, prefix
lengths, metadata updates, and returned frame behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@crates/skippy-server/src/binary_transport/binary_messaging/connection.rs`:
- Around line 83-102: Extract a separable responsibility from
handle_binary_connection and its surrounding binary messaging logic into a named
Rust module, keeping the new module under 1,000 lines. Move or add tests for the
extracted behavior alongside that module, and update handle_binary_connection to
delegate to it while preserving existing behavior.

---

Nitpick comments:
In `@crates/skippy-server/src/kv_integration/activation.rs`:
- Around line 98-124: Update activation_prefix_frame and the ActivationFrame
payload representation to use a shared/reference-counted byte buffer, such as
Arc<[u8]> or bytes::Bytes, so exact-match and truncated prefix candidates share
the original allocation instead of cloning payload bytes. Preserve the existing
validation, prefix lengths, metadata updates, and returned frame behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9c9b511e-a540-483b-882f-cab614fc3da9

📥 Commits

Reviewing files that changed from the base of the PR and between a6c7ddb and e548d91.

📒 Files selected for processing (6)
  • crates/skippy-server/src/binary_transport.rs
  • crates/skippy-server/src/binary_transport/activation_cache.rs
  • crates/skippy-server/src/binary_transport/binary_kv.rs
  • crates/skippy-server/src/binary_transport/binary_messaging/connection.rs
  • crates/skippy-server/src/frontend/prefix_cache.rs
  • crates/skippy-server/src/kv_integration/activation.rs

@ndizazzo

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ndizazzo ndizazzo changed the title Record activation cache prefix identities fix: record activation cache prefix identities Jul 21, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@crates/skippy-server/src/binary_transport/binary_messaging/prefill_recording.rs`:
- Around line 41-54: Remove the Clippy suppression from record_completed_prefill
and introduce cohesive context/request-input structs to reduce its argument
count while preserving behavior. Update
crates/skippy-server/src/binary_transport/binary_messaging/prefill_recording.rs
lines 41-54 to accept those grouped parameters, and update lines 85-96 so
record_full_prefill_with_activations reuses the shared context; do not add
another suppression.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 68c9fbfe-25a4-47ff-956b-06132d47c4a4

📥 Commits

Reviewing files that changed from the base of the PR and between e548d91 and d2cbfb9.

📒 Files selected for processing (3)
  • crates/skippy-server/src/binary_transport/binary_messaging.rs
  • crates/skippy-server/src/binary_transport/binary_messaging/connection.rs
  • crates/skippy-server/src/binary_transport/binary_messaging/prefill_recording.rs

@ndizazzo
ndizazzo force-pushed the codex/issue-683-record-identities branch 3 times, most recently from 38e85ef to 81e06b8 Compare July 24, 2026 00:53

i386 commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Codex review feedback:

I found one blocking issue in the activation-cache lookup path.

record_resident_activation now records multiple identities, for example an exact prompt identity plus a grid-floor shared-prefix identity. However, the downstream activation restore path in maybe_lookup_binary_prefill still calls restore_resident_activation(config, &base, token_start, token_ids, ...) with the full request token slice, and restore_resident_activation builds a single exact prefill_identity rather than walking the lookup_identities candidate set. It then passes only that exact activation identity to restore_binary_prefix.

That means the newly stored shorter activation frames are not considered for a later prompt that extends the same prefix. The new unit test only calls restore with shared_tokens = &lookup_tokens[..2176], so it does not exercise the actual full-token lookup path used by binary downstream restore.

Please update activation restore to walk the same lookup candidates used for resident KV and pass the matching prefix token slice/identity through, or add an end-to-end test showing a longer prompt can hit the newly recorded shared-prefix activation. As written, the multi-record activation recording adds extra cache entries/telemetry, but the normal binary downstream path still appears to restore only exact activation identities.

@ndizazzo
ndizazzo force-pushed the codex/issue-683-record-identities branch from 81e06b8 to a8e51e9 Compare July 25, 2026 06:18
@ndizazzo
ndizazzo merged commit b0d522a into main Jul 26, 2026
50 of 51 checks passed
@ndizazzo
ndizazzo deleted the codex/issue-683-record-identities branch July 26, 2026 21:43
michaelneale added a commit that referenced this pull request Jul 27, 2026
* origin/main:
  Fix Metal small-batch matmul parity for GLM verification (#1078)
  Handle K-only transposed KV page import and export (#1084)
  Refresh llama.cpp upstream patch queue (#1085)
  chore: improve embedded native-runtime compatibility guidance (#1043)
  fix(console-ui): chat transcript snapping during live status updates (#1083)
  ci: bump Linux CUDA slim container to gha-convention base runner image
  fix: record activation cache prefix identities (#1041)
  fix: read-only model download caches (#1042)
  ci: disable sccache for Windows ROCm native runtime build (#1087)
  ci: fix v0.74 release GPU builds (sccache disk-only + force_hosted_runners) (#1086)
  Make release sccache failures non-fatal (#1079)
  Keep client-only nodes out of model election (#1074)

# Conflicts:
#	crates/mesh-llm-host-runtime/src/runtime/auto_join.rs
#	crates/mesh-llm-host-runtime/src/runtime/tests/auto_join.rs
#	third_party/llama.cpp/patches/0004-Add-lanes-external-media-and-chat-grammar-support.patch
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.

Apply record_identities to remaining single-identity record sites (chunked prefill, binary transport, activation cache)

2 participants