Repository navigation
ref(toolkit-core): Share the response cache policy with the MCP - #1688
Merged
Merged
Conversation
Moves the CLI's cache policy into `@sentry/toolkit-core/response-cache` so the MCP can use the same rules (task 4.1 of the unify-sentry-api-layer proposal, #1669): - `classifyUrl` and `FALLBACK_TTL_MS`: the volatile/stable/no-cache tiers for responses without server cache headers. - `normalizeUrl` and `buildCacheKey`: identity-scoped keys over the method and full URL. Key derivation now uses WebCrypto HMAC-SHA256 instead of `node:crypto`, so it runs in Workers and browsers. The output is byte-identical, so existing CLI cache files still hit, and an empty identity is rejected instead of producing an unscoped key. - `computeInvalidationPrefixes`: moved unchanged from `cli/src/lib/cache-keys.ts`, with its tests. The module has no storage or I/O. The CLI's disk cache imports it, and its `buildCacheKey` wrapper (which defaults to the active identity) is now async, as are the tests that call it. WebCrypto HMAC runs on the libuv threadpool, so parallel requests can finish their cache lookups in either order. The `getLogs` batching test no longer assumes which batch reaches fetch first. Co-Authored-By: BYK <burak.kaya@sentry.io>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
sentry-junior Bot
added a commit
that referenced
this pull request
Oct 27, 2026
Co-Authored-By: BYK <burak.kaya@sentry.io>
BYK
requested changes
Oct 27, 2026
The tier, key, and URL normalization property tests now live next to the code in `toolkit-core/src/response-cache/policy.property.test.ts`, with `fast-check` added as a toolkit-core dev dependency. The CLI keeps only the tests for its disk store and for its `buildCacheKey` wrapper's default identity, which comes from the active login. Cases the property tests already cover are dropped from `tiers.test.ts` and `keys.test.ts`.
BYK
approved these changes
Oct 27, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves the CLI's response cache policy into
@sentry/toolkit-core/response-cacheso the MCP can use the same rules. This is task 4.1 of the unify-sentry-api-layer proposal (#1669). Codecs, theCacheStoreinterface, and the memory store (4.2–4.3) come in later PRs.What moved:
classifyUrlandFALLBACK_TTL_MS: the fallback tiers from fix(cli): Stop caching events and traces for 24 hours #1681, unchanged.volatileis 60 seconds,stableis 5 minutes, andno-cachecovers autofix and root-cause polling.normalizeUrlandbuildCacheKey: identity-scoped keys over the method and the full URL, including the host and sorted query params.computeInvalidationPrefixes:cli/src/lib/cache-keys.tsand its tests were moved as-is. Only the comments that named CLI functions changed.Key derivation moves to WebCrypto.
buildCacheKeynow usescrypto.subtleHMAC-SHA256 instead ofnode:crypto, so it runs in Workers and browsers. That makes it async; the call sites inresponse-cache.tswere already async. A test checks that the output matchescreateHmac("sha256", identity)byte for byte, so cache files written by released CLIs still hit. An empty identity now throws instead of producing a key that isn't scoped to anyone. The CLI never passes one, becausegetIdentityFingerprint()falls back to<anon>.CLI changes:
response-cache.tsimports the policy. ItsbuildCacheKeywrapper, which defaults to the active identity, is now async, and its tests await it.sentry-client.tsimportscomputeInvalidationPrefixesfrom toolkit-core.classifyUrl/normalizeUrltests import them from toolkit-core directly, so they aren't re-exported only for tests.One test change outside the cache tests. WebCrypto signs on the libuv threadpool, so parallel requests can finish their cache lookups in either order. The
getLogsbatching test used to assume the 100-ID batch reachedfetchfirst. It now checks for one request of each size, in any order.Promise.allstill returns the batches in order, so behavior is unchanged.Tests: new
tiers.test.tsandkeys.test.tscover the spec scenarios:node:cryptoparity, and an empty identityThe invalidation tests moved with the module. Two spec scenarios are tested in the CLI instead: token refresh keeping the same identity (
getIdentityFingerprint) and invalidation only touching the requester's entries (the disk store).Checks:
pnpm run tsc,pnpm run lint, andpnpm run docs:checkpass, and all 431 toolkit-core tests pass.maintoo, because the sandbox ignores read-only permissions. None touch the cache.via BYK.
--
View Junior Session in Sentry