Repository navigation
feat(mcp-cloudflare): Share allowlisted cache entries across isolates through R2 - #1842
Open
sentry-junior[bot] wants to merge 1 commit into
Open
sentry-junior[bot] wants to merge 1 commit into
sentry-junior[bot] wants to merge 1 commit into
Conversation
… through R2 Add the R2 tier of the hosted response cache behind MCP_RESPONSE_CACHE=tiered. TieredStore reads memory, then R2, for organization event details (without averageColumn) and project trace-item details (without debug). It writes to R2 only when the response carries Cache-Control: private with a positive max-age, and expires objects at the lesser of max-age and 5 minutes, checked on read. Writes run in waitUntil, and a 1-day bucket lifecycle rule collects garbage. Authorization values kept for Vary matching are stored as SHA-256 hashes, never as tokens. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully 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.
Task 7.3 of the #1669 plan. It is stacked on #1833 (7.1) and adds the R2 tier behind
MCP_RESPONSE_CACHE=tiered. Merge #1833 first, and only after the buckets below exist.Still off everywhere. No config sets
MCP_RESPONSE_CACHE, so the new binding is inert in every deployed environment. Whentieredhas no bucket, it logs one warning and caches in memory only.What goes to R2 (
src/server/lib/r2-cache-store.ts):/api/0/organizations/{org}/events/{project}:{event_id}/withoutaverageColumn, and/api/0/projects/{org}/{project}/trace-items/{id}/withoutdebug. Every other URL uses the memory store unchanged.Cache-Control: privatewith a positivemax-age, and nono-storeorno-cache. Until feat(api): Add opt-in max-age mode to ConditionalGetResponseMixin sentry#128828 ships, R2 stores nothing.expiresAt=createdAt+ min(max-age, 5 min) in custom metadata, and reads enforce it. An R2 hit is copied into memory only for the time it has left. A 1-day lifecycle rule is only garbage collection.waitUntil. Invalidation touches memory only, as in the design. A write under the same path, such as deleting a project, does not clear R2 within the 5-minute window. This is part of the 7.4 sign-off.Identity isolation. Object keys are
<grant identity>/<HMAC cache key>, and a read also rejects an entry whose stored identity differs.Vary: Authorizationmakes the policy keep request headers, so the cache now storessha256:of the Authorization value, never the raw upstream token. That applies to memory too. The shared policy now keepsCache-Controlon entries so the store can decide.Tests (workerd, real miniflare R2 bucket):
max-age=0. In those cases the entry stays memory-only.averageColumn,debug) are memory only.max-age=3600is capped at 5 minutes, andmax-age=60expires at 60 s.Metrics (7.5):
app.response_cache.r2.lookup(hit/miss/expired) andapp.response_cache.r2.write, plus warning logs for R2 failures. Both are documented indocs/operations/monitoring.md.Provisioning (required before merge). Deploys use
--experimental-auto-create=false, so a Cloudflare admin must run:I created nothing. The same steps are in
docs/cloudflare/architecture.md.Pending, needs a deployed Worker: 7.2 (zstd) and the 7.5 preview check, as described in #1833. With
tieredon a preview, also check thatr2.lookupshows up.r2.writestays at zero until the server headers ship. 7.4 is a human privacy/security sign-off.Checks:
pnpm run tscandpnpm run lintpass, and lint also passes with no builtdist, as in CI.docs:checkandtest:ci-projectspass. Tests pass for toolkit-core (381), mcp-core (1932, 6 skipped), and mcp-cloudflare (499).via @BYK.
--
View Session [Sentry]