Skip to content

Prompt cache salts: cache_salt and serve --cache-salt-per-key keep kept prompt states apart - #3222

Merged
ashhart merged 7 commits into
mainfrom
lead/cache-salt
Nov 21, 2026
Merged

ashhart merged 7 commits into
mainfrom
lead/cache-salt

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Adds prompt cache salts.

What changed

  • cache_salt, a non-empty string of at most 1024 bytes, on /v1/chat/completions, /v1/completions, /v1/responses and /v1/messages.
  • serve --cache-salt-per-key also salts every request by the API key it matched; a request's own cache_salt then counts within that key.
  • The salt is hashed with HMAC-SHA-256 under the server's tool-call id key, and the hash masks the first four words of the lane host's cache key. It is never echoed, stored or logged (the request log writes <redacted>). /v1/models publishes capabilities.cache_salt.

Isolation rule

  • A kept state is resumed only by a request with the same salt, and unsalted states only by unsalted requests. Every lookup, keep, read-ahead, prefix wait and repeat note on the lane host uses the salted key.
  • Salted states stay in RAM: the disk writer, the disk reader and --learn already refuse these words, so the disk format is unchanged and a salted request never reads a disk state.
  • A salted request neither drafts from nor adds to Recall's record, and neither reads nor writes --compact-memory notes.
  • The server's own requests for a salted conversation keep the salt: the warm pass, compaction notes, and Cortheon's planner and kept rounds. A salted /v1/imprint ask reports and loads only its own salt's states.
  • Per key, the key's digest is mixed in under its own domain after the client's salt, so no client salt can stand for another key's.
  • Engines whose cache isn't the lane host's store refuse a salted request with 400 and refuse to start with --cache-salt-per-key.

Unsalted requests are unchanged: with no salt and the option off, the request reaching the engine is the same as before byte for byte: same cache key, same lane host bookkeeping, nothing new on disk. Salts never change tokens; they only key the cache, so a salted request may prefill more but never computes differently.

Tests: two salts never resume each other's states; the same salt resumes where an unsalted turn does, with equal tokens; salted repeats are noted under their own key; salted states stay off disk and a salted lookup reads none; Recall neither serves nor records a salted request; the routes keep salts and keys apart and refuse salts on engines that can't keep them; no client salt reproduces another key's salt; Messages and Responses pass the salt on and imprint asks use the salted key; salted compactions skip the note store, the request log redacts the salt, and Cortheon's planner request is salted. Each test fails with its fix reverted. test-server-cpu, test-prompt-cache-host, test-lane-api-host, test-key-scopes-host, test-server-security and test-cuda-host pass.

Still owed: a served check on a lane-host model with --prompt-cache-disk: unsalted turn 2's cached_tokens and token_sha256 equal main's; the same salt resumes at the same place and another salt resumes nothing; the disk holds no salted states; two keys stay apart under --cache-salt-per-key.

Fixes #3196

  • Synthena (Ash's Agent)

…nd with serve --cache-salt-per-key the API key it matched, is hashed with HMAC-SHA-256 under the server's tool-call id key and masks the first four words of the lane host's cache key. A kept state is then resumed only by a request with the same salt; with no salt the request is keyed exactly as before, and tokens never change.

Salted states stay in RAM: the disk writer, reader and --learn already
refuse high-bit words, so the disk format is unchanged. A salted request
neither drafts from nor adds to Recall's record and neither reads nor
writes --compact-memory notes; the server's own requests for a salted
conversation (warm pass, compaction notes, Cortheon's planner and kept
rounds) keep the salt, and a salted /v1/imprint ask looks up its own
states. Engines whose cache is not the lane host's store refuse a salted
request with 400 and refuse to start with --cache-salt-per-key. The request
log redacts the salt, and /v1/models publishes capabilities.cache_salt.

Fixes #3196
@ashhart
ashhart merged commit f782410 into main Nov 21, 2026
1 check failed
@ashhart
ashhart deleted the lead/cache-salt branch November 21, 2026 22:36
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.

Prompt cache salts: cache_salt and per-key isolation of kept states

1 participant