Skip to content

feat(cli): resume api pagination without repeating arguments - #1691

Open
betegon wants to merge 1 commit into
mainfrom
bt/api-pagination-resume
Open

betegon wants to merge 1 commit into
mainfrom
bt/api-pagination-resume

Conversation

@betegon

@betegon betegon commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Continuing an API query currently requires copying its endpoint and every request argument. This adds sentry api --cursor next, prev, and first without an endpoint when there is one recent paginated query in the current working directory, configured host, and authenticated identity.

Builds on the pagination support merged in #1659. This PR targets main and contains only endpoint-free continuation.

Before

sentry api organizations/ -f per_page=2 --json
sentry api organizations/ -f per_page=2 --cursor next --json
sentry api organizations/ -f per_page=2 --cursor prev --json

After

sentry api organizations/ -f per_page=2 --json
sentry api --cursor next --json
sentry api --cursor prev --json

The saved request URL shares the existing cursor stack and five-minute expiry. It retains the original query parameters, including repeated parameters and the context needed for custom cursors. Presentation options apply to the current invocation.

If multiple paginated queries are saved, the command asks for an explicit endpoint and filters. Exhausted queries and requests requiring explicit headers or a body still count, so navigation cannot silently switch to another query. Header/body values are not saved; configured headers are re-read and checked against the original request. Detail requests without pagination do not replace a saved query. Dry-runs and failed requests do not advance it.

Uses published @sentry/[email protected], already adopted on main. The SDK prepares the request used for preview and dispatch. Saved context uses the caller's URL before a custom bookmark overrides its cursor or page size; storage, query selection, and navigation remain CLI policy.

Validation

  • Rebased only the continuation commit onto main after feat(cli): expose api pagination and shared cursor navigation #1659 merged. range-diff confirms the feature diff is unchanged; the PR contains no duplicate parent changes.
  • Workspace typecheck and lint pass. Review and cleanup found no remaining integration concerns.
  • All 337 focused API command, cursor-history, pagination, and schema migration tests pass.
  • All 64 API/library E2E tests pass against a freshly built CLI bundle, including restored requests, custom/legacy bookmarks, ambiguity/concurrency, and host/identity/directory/header isolation.
  • The full workspace suite was not repeated for this mechanical rebase. This PR remains a draft for review of the endpoint-free continuation flow.

@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Oct 30, 2026 12:59pm UTC

Request Review

@betegon
betegon force-pushed the bt/api-pagination-cursor branch from f2d8d61 to dae73bb Compare October 29, 2026 16:29
@betegon
betegon force-pushed the bt/api-pagination-cursor branch from dae73bb to 58fdcac Compare October 29, 2026 16:32
@betegon
betegon force-pushed the bt/api-pagination-resume branch from 082354f to 6f2f6e0 Compare October 29, 2026 16:37
@betegon
betegon force-pushed the bt/api-pagination-cursor branch from 58fdcac to 76ea3f5 Compare October 29, 2026 21:06
@betegon
betegon force-pushed the bt/api-pagination-resume branch from 6f2f6e0 to 5e048bf Compare October 29, 2026 21:38
@betegon
betegon force-pushed the bt/api-pagination-cursor branch from 76ea3f5 to 880d622 Compare October 29, 2026 21:50
@betegon
betegon force-pushed the bt/api-pagination-resume branch from 5e048bf to ba01419 Compare October 29, 2026 21:51
@betegon
betegon force-pushed the bt/api-pagination-cursor branch from 880d622 to ac63354 Compare October 30, 2026 09:06
@betegon
betegon force-pushed the bt/api-pagination-resume branch from ba01419 to d188a55 Compare October 30, 2026 09:06
@betegon
betegon force-pushed the bt/api-pagination-resume branch from d188a55 to e34210a Compare October 30, 2026 10:02
betegon added a commit that referenced this pull request Oct 30, 2026
`sentry api --json` discarded pagination metadata, leaving agents
without a way to continue a successful query. It now exposes
continuation metadata and uses the CLI's shared cursor history for
`next`, `prev`, and `first`.

### Before

```sh
sentry api organizations/ -f per_page=1 --json
```

Even when another page existed, the output had no continuation (bodies
abbreviated):

```json
{"status":200,"statusText":"OK","body":[{"slug":"example-org"}]}
```

### After

The same command includes navigation metadata:

```json
{"status":200,"statusText":"OK","body":[{"slug":"example-org"}],"pagination":{"nextCursor":"1:1:0","hasPrev":false}}
```

Repeat the endpoint and filters to navigate:

```sh
sentry api organizations/ -f per_page=1 --cursor next --json
sentry api organizations/ -f per_page=1 --cursor prev --json
sentry api organizations/ -f per_page=1 --cursor first --json
```

Raw cursors and shared custom bookmarks are accepted, including legacy
`cli1~` bookmarks. Resuming restores the required page size and skips
rows already read; forward/back navigation retains that exact bookmark.
Arrays and Events `{data, meta}` envelopes are supported, preserving
envelope metadata.

### Shared SDK ownership

Uses published `@sentry/[email protected]`, including
getsentry/sentry-api-schema#116 and getsentry/sentry-api-schema#117. The
SDK owns generic URL, header, and body preparation through
`client.prepareRequest()`, plus partial-page consumption and bounded
traversal through `consumePage` and `paginateUpTo`. The API command uses
the same prepared `Request` for preview and dispatch, removing its
duplicate URL/header builders.

Toolkit keeps authentication and trusted-host checks, raw response
decoding, request/identity fingerprints, bookmark encoding, page-sizing
policy, and navigation history. The SDK accepts decoded server cursors
and offsets without depending on CLI storage or cursor formats. Existing
MCP and frontend consumers do not need to opt into request preparation.

Each `api` invocation still fetches one server page, and the endpoint
remains required. History is scoped to the request and identity;
dry-runs and failed requests do not advance it. `hasPrev` describes
local navigation, while `prevCursor` is server-provided. `--fields`
filters only the body. Raw text, binary downloads, explicit Content-Type
headers, and non-2xx response bodies retain their behavior. URL
fragments are excluded without losing encoded `#` characters. Command
help, docs, and the generated skill reference are updated.

Continuing without an endpoint is stacked in #1691. Native logs
pagination remains a separate follow-up.

Generic request preparation is tested in `@sentry/api`. Additional
coverage for continuation across short and empty pages is in
getsentry/sentry-api-schema#118, a tests-only follow-up that requires no
SDK release. The consumer tests concentrate on CLI navigation/history,
identity isolation, raw response policy, and bookmark adaptation.

### Validation

- Workspace typecheck and lint pass with published
`@sentry/[email protected]`.
- API and library E2E pass against the bundled CLI. Consolidated flows
retain navigation, dry-run/error recovery, raw-file preview and
dispatch, shared/legacy bookmarks, Events metadata, and request/identity
isolation. The silent request starts without JSON mode, then resumes
through the same saved history.
- Full workspace `pnpm run test` passes on Linux x64 on the final
source: 12,669 CLI tests, 337 shared tests, and all MCP, Cloudflare,
frontend, and remaining workspace suites. Existing skips remain
unchanged.
- Review and cleanup completed with no remaining findings. Production
code is unchanged by the test consolidation.
Base automatically changed from bt/api-pagination-cursor to main October 30, 2026 12:28
@betegon
betegon force-pushed the bt/api-pagination-resume branch from e34210a to d4498e0 Compare October 30, 2026 12:59
@betegon
betegon marked this pull request as ready for review October 30, 2026 13:02
@betegon
betegon requested a review from BYK October 30, 2026 13:02
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 30, 2026

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the best way to do this is get a snapshot of the initial api call including the CWD etc if needed, serialize that deterministically along with deterministic keys and go from there. If we get the full invocation state and manage to serialize/deserialize it, it should be trivial to implement this feature properly and it may even be extended to other commands.

choose the most recent query or switch to another when a query reaches its end.

Only successful GETs save a query. The saved URL expires with its cursor history
after five minutes. Explicit headers (`-H`) and request bodies are not saved;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y THO?

This breaks the reliability. We can still cache them on disk if DB is too expensive. This can be a follow up but I think we should either go all in or none otherwise people won't use it if they cannot trust it will work every time.

});

describe("runMigrations", () => {
test("migration 20→21 preserves cursor stacks without assigning a request", () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really a useful test?

This branch was previously deployed

1 inactive deployment
Preview — d4498e05 Deployed Oct 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants