Repository navigation
Commit 6fe02ce
feat(toolkit-core): Let a request scope bypass cached reads (#1720)
This adds a request-scoped fresh-read bypass to the shared API transport
in `@sentry/toolkit-core/api-transport`. It is task **5.3** of #1669
(`unify-sentry-api-layer`) and builds on the shared transport from
#1719.
### What's shared
`createApiTransport` accepts a new optional `fresh?(): boolean` hook.
While the hook returns true:
- GETs skip the cache lookup and go to the network.
- The response is still stored, so it replaces the cached entry and
later reads see the new data.
A host backs the hook with request-scoped state, for example
`AsyncLocalStorage` around a single MCP tool call that asked for `fresh:
true`. That keeps the bypass to one call rather than the whole process.
This is the transport side of the MCP's `fresh` input planned in 6.3.
### Behavior changes
None for current callers. The hook is optional, and no host sets it yet.
The CLI's `--fresh` flag keeps its existing process-wide bypass in
`cli/src/lib/response-cache.ts`, with reads skipped and writes kept as
before. This PR leaves that unchanged.
### Relation to #1669
- Done: 5.0 shared retry policy (#1673, #1710), and 5.1 + 5.2 shared
transport with the CLI switch (#1719).
- This PR: 5.3.
- Next, stacked on this branch and opened once it merges: 6.1. That adds
`fetch` to `McpServerOptions` and routes all `SentryApiService` and
`@sentry/api` requests through it. `SentryApiService` drops its own
retry loop, so retries happen in the shared transport only.
### Verification
- New transport test `skips the cache in a fresh scope and replaces the
entry`. It stores v1, then reads in a fresh scope and gets v2 from the
network. Once the fresh scope ends, the next read is a cache hit for v2.
- `toolkit-core`: 21 files and 270 tests pass.
- CLI request, cache and API tests (`test/lib/sentry-client*`,
`test/lib/response-cache*`, `test/lib/api`): 49 files and 1,049 tests
pass.
- `tsc --noEmit` passes for `toolkit-core` and `cli`.
- `oxlint`, `oxfmt --check` and `ast-grep scan` are clean on the changed
files.
<!-- junior-request-attribution:start -->
via **BYK**.
<!-- junior-request-attribution:end -->
<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3Aa6eddc0161cff61914454da9f74fcdf1 -->
--
[View Junior Session in
Sentry](https://sentry.sentry.io/explore/conversations/agent%3Aa6eddc0161cff61914454da9f74fcdf1/?project=4510944073809921)
<!-- junior-session-footer:end -->
Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <burak.kaya@sentry.io>1 parent cbe5e87 commit 6fe02ce
3 files changed
Lines changed: 44 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
539 | 570 | | |
540 | 571 | | |
541 | 572 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
109 | 115 | | |
110 | 116 | | |
111 | 117 | | |
| |||
663 | 669 | | |
664 | 670 | | |
665 | 671 | | |
666 | | - | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
667 | 676 | | |
668 | 677 | | |
669 | 678 | | |
| |||
0 commit comments