Skip to content

Share one HTTP response cache library with getsentry/toolkit #4397

Backlog

Description

@sentry-junior

#4393 adds a core HTTP cache in packages/junior/src/chat/egress/http-cache.ts. getsentry/toolkit already has one for its CLI and MCP server. We are building the same parts twice, and compression would be one more.

What each side has

@sentry/api/client response cache (published; getsentry/toolkit uses it, and Junior already depends on @sentry/api 2.16.0):

  • Freshness and revalidation through http-cache-semantics (lookupResponse, storeResponse).
  • A CacheStore interface (get, set, deleteMatching), a byte-budgeted memory store, identity-scoped keys (buildCacheKey) and a BodyCodec type.
  • Sentry-specific parts: the classifyUrl TTL tiers and computeInvalidationPrefixes for Sentry API URLs.

@sentry/toolkit-core/response-cache/codec (private to getsentry/toolkit):

  • zstd level 3, with brotli when the runtime has no zstd.
  • Bodies under 256 bytes stay uncompressed.
  • Decompression never goes past the recorded size.

Junior's HTTP cache:

  • Keys by credential scope and request, and saves entries in the Redis state adapter for 6 h.
  • TTLs come from the link type or plugin.
  • staleIfError serves the last entry on errors, 429 and 5xx. onStale gives cards their fetchedAt.
  • Bodies are plain JSON strings, up to 256 KiB. Junior has its own zstd code in chat/cache-warming/snapshot.ts.

Decided

  • The shared library is a new package, not part of @sentry/api or toolkit-core.
  • The plugin TTL wins over server cache headers. Server headers can only shorten freshness, never extend it. For example, GitHub card reads use TTL 0 and depend on webhooks, so a server max-age must not make them skip revalidation.

Plan

  1. Create the new package from the provider-neutral parts of the @sentry/api/client response cache: the policy, CacheStore, the memory store and identity-scoped keys. TTL tiers and invalidation prefixes become options, and Sentry's are a preset.
  2. Add stale-if-error and an onStale signal. Add the TTL rule above, so a caller's TTL caps the freshness that server headers give.
  3. Move the toolkit body codec into the new package.
  4. Move getsentry/toolkit onto the new package.
  5. Move Junior's chat/egress/http-cache.ts onto it, as a CacheStore over the state adapter that is keyed by credential scope. Plugin TTLs and GitHub webhook invalidation stay in Junior.
  6. Store bodies compressed, which saves Redis memory. State values are JSON, so compressed bytes are stored as base64, the same way cache-warming snapshots are. The 256 KiB body limit can then apply to the stored size.

via @BYK.

--

View Session [Sentry]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions