Repository navigation
feat(api): Add opt-in max-age mode to ConditionalGetResponseMixin - #128828
Merged
Merged
Conversation
BYK
marked this pull request as ready for review
October 26, 2026 21:43
Member
|
This LGTM but waiting for other folks to sign off as it is sensitive. |
This was referenced Oct 26, 2026
BYK
added a commit
to getsentry/toolkit
that referenced
this pull request
Oct 27, 2026
The CLI's fallback "immutable" cache tier kept any `/events/<id>/`, `/trace/<id>/`, or `/trace-items/<id>/` response for 24 hours. It was also checked before the `/issues/` volatile pattern, so `getLatestEvent` (`/issues/<id>/events/latest/`) was cached for a day: re-running `sentry issue view` an hour later could show an outdated "latest" event. The getsentry/sentry#128818 spike ([findings](getsentry/sentry#128818 (comment))) found that none of these responses are actually immutable. Event payloads embed `nextEventID`/`previousEventID`, user reports, and release data, reprocessing and merges can change them for the same ID, `latest`/`oldest`/`recommended` resolve to different events over time, and full traces gain spans as they arrive. This removes the `immutable` tier: | Tier | TTL | Matches | | --- | --- | --- | | no-cache | 0 | autofix and root-cause polling (unchanged) | | volatile | 60 s | `/issues/` (now including issue events), project event details, full traces, `dataset=logs\|spans`, trace logs | | stable | 5 m | everything else, now including organization event details and trace-item details | Server `Cache-Control` headers still take precedence, so when getsentry/sentry#128828 ships its `private, max-age=300` headers the CLI follows them without a release. A TODO points at getsentry/sentry-api-schema#81 and #102 for classifying by generated `@sentry/api` operation metadata instead of URL regexes. Notes for review: - **No migration.** Freshness is recomputed from `createdAt` and the current tier on read, so existing 24-hour entries on disk are treated by the new rules immediately. - **`immutableMinTimeToLive` removed.** It pointed at the deleted tier constant. The `http-cache-semantics` default is the same 24 hours, and it only applies to responses where the server sends `immutable`. - **Cost:** repeated reads of project/issue events and full traces will hit the API after 60 seconds instead of 24 hours; organization event and trace-item details after 5 minutes. Task group 2 of the `unify-sentry-api-layer` OpenSpec change in #1669. **Checks run locally:** - New `classifyUrl` cases plus fake-clock expiry tests for org event details (hit at 4 min, miss at 6 min), issue latest event, project event details, full traces, and server `max-age` overriding the fallback. 8 of them fail against the old classifier. - `pnpm exec vitest run test/lib/response-cache*.test.ts`: 60 passed - CLI `typecheck`, `lint`, and `oxlint`/`oxfmt` on the changed files: clean - `pnpm run test:unit` (first revision): 11,583 passed, 6 failed. The same 6 fail on unmodified `main` in my sandbox: filesystem-permission tests (`completions`, `code-scanner`, `file-changes`, `telemetry` readonly DB, `upgrade` lock) that depend on the environment, not this change. <!-- junior-session-footer:start --> <!-- junior-conversation-id:local%3Aweb%3A0ab4fc2bd5a2e23f2c25efcf --> -- [View Junior Session in Sentry](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A0ab4fc2bd5a2e23f2c25efcf/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <[email protected]>
sentry-junior
Bot
force-pushed
the
feat/api-max-age-event-responses
branch
from
October 28, 2026 19:45
74e2957 to
8bbfa33
Compare
Endpoints that set cache_max_age send Cache-Control: private, max-age=N and add Origin to Vary, so a browser can reuse event and trace item details without a round trip. Nothing changes until an endpoint class is listed in the new api.conditional_get.max_age_endpoints option, which defaults to empty. Superuser and staff sessions, and requests with live-data query params, keep private, no-cache. Opts in OrganizationEventDetailsEndpoint and ProjectTraceItemDetailsEndpoint with a 300 second max-age. Refs #128818 Co-Authored-By: BYK <[email protected]>
sentry-junior
Bot
force-pushed
the
feat/api-max-age-event-responses
branch
from
October 28, 2026 19:46
8bbfa33 to
7121dcc
Compare
BYK
requested changes
Oct 28, 2026
Replace hard-coded max-age seconds with a CacheTier enum that matches the response cache tiers used by the CLI in getsentry/toolkit.
Contributor
Author
|
Re: "We not doing ETags?" — yes, ETags are still in. Max-age is layered on top of them, not a replacement. Every response from these endpoints still gets an |
BYK
approved these changes
Nov 2, 2026
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.
Prototype from the #128818 spike. Lets an endpoint that serves data that rarely changes once written tell the browser it can reuse the response for N seconds, instead of revalidating every time.
What changes
ConditionalGetResponseMixingets acache_max_ageclass attribute. When it is set and the endpoint class is listed in the newapi.conditional_get.max_age_endpointsoption, 200 GET/HEAD responses sendCache-Control: private, max-age=NandVary: Cookie, Authorization, Origin. The ETag and 304 path stay, so a browser revalidates cheaply after the max-age runs out.Originis added toVaryonly in this mode. API responses reflect the request origin inAccess-Control-Allow-Origin(src/sentry/api/base.py). A response reused without revalidation keeps the origin it was fetched with, so a page on another origin, such assentry.ioversus<org>.sentry.io, would fail CORS.private, no-cache. They see extra fields, for example internal trace item attributes, and the session can end without the cookie changing.uncacheable_query_paramsfalls back tono-cachefor query params that pull in live data.averageColumnon organization event details adds 24h span averages.api.conditional_getmetric gets amodetag (max_age/no_cache).cache_max_age = 300:OrganizationEventDetailsEndpointandProjectTraceItemDetailsEndpoint.Rollout and rollback
Nothing changes until both options are set.
api.conditional_get.enabledis the existing kill switch for the mixin. The newapi.conditional_get.max_age_endpointsdefaults to[], and endpoints are added to it one at a time. Rollback means removing the endpoint from the list. Browsers keep what they already cached for up tocache_max_ageseconds, which is why it starts at 5 minutes.Not
immutableon purpose. Reprocessing, merges, release updates, deletion, and permission changes can all change or revoke a response under the same URL. Details are in the spike comment on #128818.Tests run locally
.venv/bin/pytest -q --reuse-db tests/sentry/api/test_conditional_get.py tests/sentry/api/endpoints/test_project_trace_item_details.py tests/snuba/api/endpoints/test_organization_event_details.py tests/snuba/api/endpoints/test_project_trace_item_details.py tests/sentry/seer/endpoints/test_group_ai_autofix.py: 165 passed, 1 xpassed. Snuba came fromdevservices up..venv/bin/prek run -qand the pre-pushmypyhook on the changed files both passed.Refs #128818
via BYK.
--
View Junior Session in Sentry