Skip to content

ref(api)!: Move the response cache and retry policy out of @sentry/api/client - #132687

Merged
BYK merged 5 commits into
masterfrom
feat/api-drop-generic-http
Nov 26, 2026
Merged

BYK merged 5 commits into
masterfrom
feat/api-drop-generic-http

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Breaking change: this needs a major release (3.0.0).

@sentry/api stops shipping a generic HTTP cache and retry policy. The host that consumes it now owns both and plugs them into the transport: the cache option (TransportCache) and a new retry hook. The toolkit CLI and MCP already work this way through @sentry/http since getsentry/toolkit#2509. @sentry/api gains no new dependency, and http-cache-semantics goes away.

Removed from @sentry/api/client

  • Cache: lookupResponse, storeResponse, buildCacheKey, normalizeUrl, createMemoryStore, REVALIDATION_WINDOW_MS, plus the types CacheStore, CacheEntry, BodyCodec, BodyEncoding, EncodedBody, MemoryStore, MemoryStoreOptions, LookupOptions and StoreOptions.
  • Retry: nextRetryDelayMs, sleep and RetryPolicy.
  • Transport option: retry changes from a RetryPolicy object to an optional hook.

Retry hook

type TransportRetry = (
  attempt: () => Promise<Response>,
  request: { method: string; url: string; idempotent: boolean; signal: AbortSignal | undefined },
) => Promise<Response>;

The transport calls retry once per request, after the cache lookup and the credential's lookup and prepare, and inside the host span. The hook calls attempt() as often as its policy allows and returns the final response.

Each attempt() sends once with the transport's timeout, body buffering, redirect checks, and 401 refresh. That refresh replay happens inside the attempt, so it never counts as a retry. It resolves with the response, failed or not. Otherwise it throws: ApiTimeoutError when the transport's own timeout fired, the caller's abort reason, the host's errors.fatal or redirect-rejection error, or what the fetch threw.

The cache store, write invalidation, errors.rateLimited, and errors.timeout apply once, to what the hook returns or throws. Without the hook, each request is sent once.

The hook owns the loop and the wait, so @sentry/api has no retry policy, loop, or @sentry/http dependency. @sentry/http's fetchWithRetry(send, options) implements it directly:

retry: (attempt, { method, idempotent, signal }) =>
  fetchWithRetry(attempt, {
    policy, method, idempotent, ...(signal ? { signal } : {}),
    retryableStatuses: SENTRY_RETRYABLE_STATUSES,
    serverDelayMs: (r) => parseRetryDelayMs(r.status, r.headers),
  }),

Kept

These are plain data and functions, and none of them depends on @sentry/http:

  • The TransportCache seam. CacheLookup is now defined in transport.ts.
  • Credential refresh and trusted-origin redirects.
  • classifyUrl, FALLBACK_TTL_MS, TtlTier and computeInvalidationPrefixes.
  • parseRetryDelayMs, which moved to rate-limit.ts. It still reads Retry-After and X-Sentry-Rate-Limit-Reset, and the transport still passes its value to errors.rateLimited.
  • isIdempotentRequest, which moved to idempotent-operations.ts, plus selectIdempotentWrites and createIdempotentOperationMatcher.

Migration

  • Replace retry: policy with a retry hook. With @sentry/http, wrap fetchWithRetry as shown above.
  • To keep caching, implement TransportCache on a cache of your own.

Toolkit follow-up, after 3.0.0 is published

  • toolkit-core builds the retry hook on @sentry/http's fetchWithRetry, with SENTRY_RETRYABLE_STATUSES and parseRetryDelayMs, and passes it to createApiTransport.
  • withSentryRetry stops wrapping transport.request, and its outer wrapping goes away.
  • Delete TRANSPORT_SENDS_ONCE and the retry: lines that use it in the CLI's sentry-client.ts and MCP's api-client/client.ts.
  • @sentry/http needs no new export, since fetchWithRetry already matches the hook. A named adapter, such as retryHook(options), is optional sugar.

Breaking changes may remove exports

test/consumers/exports.mjs now allows removed exports when the change is marked breaking: type(scope)!: in the PR title, or a BREAKING CHANGE: footer. That's the signal Craft reads to pick a major bump. The script reads the PR title, or the commit message after merge or in the merge queue, from the run's GitHub event, so no workflow changes. The script still lists the removals, and any change not marked breaking still fails.

Release

openapi.yml's automatic release should publish this as 3.0.0 after merge. If a spec change lands before that release runs, its preflight forces a minor bump and this would ship as 2.x instead.

via @BYK.

--

View Session [Sentry]

@sentry/api stays dependency-free: the host that consumes it owns its
cache and retry policy and plugs them in through the transport's `cache`
seam and `fetch`. The toolkit CLI and MCP already do, through
@sentry/http (getsentry/toolkit#2509).

Removed from @sentry/api/client: lookupResponse, storeResponse,
buildCacheKey, normalizeUrl, createMemoryStore, REVALIDATION_WINDOW_MS,
the CacheStore, CacheEntry, BodyCodec, and memory-store types,
nextRetryDelayMs, sleep, and RetryPolicy. createApiTransport no longer
takes `retry` and sends each request once, plus one replay after a
credential refresh. The http-cache-semantics dependency is gone.

Kept: the TransportCache seam (CacheLookup is now defined in
transport.ts), credential refresh, trusted-origin redirects, the TTL
tiers, invalidation prefixes, parseRetryDelayMs (now in rate-limit.ts),
isIdempotentRequest, and the idempotent-operation matchers.

BREAKING CHANGE: the response-cache and retry exports above are gone,
and `createApiTransport` rejects a `retry` option. Hosts that relied on
the built-in retries wrap `transport.request` or `fetch` instead.

Co-Authored-By: BYK <burak.kaya@sentry.io>
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Nov 26, 2026
A change marked breaking (`type(scope)!:` or a `BREAKING CHANGE:`
footer) releases as a major, so the removed-exports check lists its
removals and passes. CI reads the PR title, or the commit message after
merge. Other changes still fail on a removed export.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 26, 2026
The exports check now reads the PR title, or the merged commit's
message, from the run's event payload (GITHUB_EVENT_PATH) instead of a
CHANGE_MESSAGE variable that the workflow sets. backend.yml stays
unchanged, so this package-only PR no longer counts as a backend change.
@github-actions github-actions Bot removed the Scope: Backend Automatically applied to PRs that change backend components label Nov 26, 2026
@sentry-junior
sentry-junior Bot requested a review from BYK November 26, 2026 17:16
`createApiTransport` takes an optional `retry(failure)` that returns the
delay before the next attempt, or undefined to stop. The transport calls
it per attempt, after the cache lookup and credential preparation, with
the failed status or error, the attempt count, the time waited, and the
server's requested delay. It owns the loop, the abortable wait, and the
body replay; the host owns the policy. Without `retry` it sends once.

A host that wraps `transport.request` repeats the cache lookup,
credential lookup and refresh, and span on every attempt, so this hook
replaces that wrapping.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@sentry-junior sentry-junior Bot changed the title ref(api)!: Remove the response cache and retries from @sentry/api/client ref(api)!: Move the response cache and retry policy out of @sentry/api/client Nov 26, 2026
`retry(attempt, { method, url, idempotent, signal })` now runs once per
request, after the cache lookup and credential preparation, and returns
the final response. `attempt()` sends once with the transport's timeout,
body buffering, redirect checks, and 401 refresh, and resolves with the
response or throws, with ApiTimeoutError for the transport's own
timeout. The cache store, write invalidation, `errors.rateLimited`, and
`errors.timeout` apply once to the result.

The host's policy now owns the loop and the wait, so @sentry/http's
fetchWithRetry implements the hook directly, and the transport keeps no
loop or sleep of its own.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@BYK
BYK marked this pull request as ready for review November 26, 2026 17:37
@BYK
BYK requested review from a team as code owners November 26, 2026 17:37
@BYK
BYK merged commit 593c847 into master Nov 26, 2026
90 checks passed
@BYK
BYK deleted the feat/api-drop-generic-http branch November 26, 2026 18:41
BYK added a commit to getsentry/toolkit that referenced this pull request Nov 26, 2026
…ok (#2542)

Bumps `@sentry/api` to 3.0.0 and moves the CLI and MCP retries onto the
transport's new `retry` hook, added in getsentry/sentry#132687.

### What changes
- **toolkit-core:** `withSentryRetry` and `TRANSPORT_SENDS_ONCE` are
replaced by `sentryRetry(options): TransportRetry`. It builds the hook
on `@sentry/http`'s `fetchWithRetry`, using `SENTRY_RETRYABLE_STATUSES`
and `@sentry/api`'s `parseRetryDelayMs`. `SentryRetryOptions` takes
`policy`, `isRetryableError`, and an `onRetry` that also gets the
retried request's method and URL.
- **CLI and MCP:** both pass `retry: sentryRetry({ policy })` to
`createApiTransport` instead of wrapping `transport.request`. The
transport now runs the hook after the cache lookup and the credential's
`prepare`. A retried request looks up the cache and the credential once,
and it gets one host span instead of one per attempt. Each attempt still
has its own timeout, body buffering, redirect checks, and 401 refresh,
and the refresh doesn't count as a retry.
- **Idempotency:** the hook gets `idempotent` from the transport, which
already combines the per-request flag with the operation catalog
(`isIdempotent`). So the wrapper's separate `isIdempotent` option goes
away.
- **CLI `isRetryableError`:** the `TimeoutError` case is gone. An
attempt now throws the transport's `ApiTimeoutError`, which isn't a
`CliError`, so it still retries. `errors.timeout` maps the final timeout
to `TimeoutError` once, after the hook gives up.
- **MCP issue-event read:** 3.0.0 types `event_id` as a string, so the
cast for 32-character event IDs is removed. Without it, lint fails with
an unnecessary-assertion error.
- **`pnpm-workspace.yaml`:** the catalog entry and the
`minimumReleaseAgeExclude` entry move to `@sentry/api@3.0.0`.

### Also picked up from 2.16.0
The bump from 2.15.0 includes getsentry/sentry#131779, which sends and
reads Objectstore batches as FormData. Each operation is a JSON part
named by its index, and an insert's bytes go in `<index>.payload`. The
CLI's snapshot uploads use that batch client, so their wire format
changes with this PR. The CLI's objectstore test fixtures now build
responses in that format.

`@sentry/http` needs no new export: `fetchWithRetry(send, options)`
already fits the hook.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A672bf07a67118adf395d2ead4a7cd9aa -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A672bf07a67118adf395d2ead4a7cd9aa)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A672bf07a67118adf395d2ead4a7cd9aa/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <126780+BYK@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
Preview — e723d51f Deployed Nov 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant