Skip to content

feat(apidocs): Publish mobile build assemble and snapshot archive endpoints - #130371

Merged
BYK merged 2 commits into
masterfrom
byk/feat/apidocs-publish-preprod-assemble-snapshot-archive
Nov 7, 2026
Merged

BYK merged 2 commits into
masterfrom
byk/feat/apidocs-publish-preprod-assemble-snapshot-archive

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Part of the #130351 proposal to publish endpoints that the Sentry CLI (getsentry/toolkit) calls with raw requests today, so they appear in the public OpenAPI schema and in the generated @sentry/api SDK.

This PR covers the Emerge Tools endpoints:

Endpoint Status
POST /api/0/projects/{org}/{project}/files/preprodartifacts/assemble/ (ProjectPreprodArtifactAssembleEndpoint) EXPERIMENTAL → PUBLIC
GET and POST /api/0/organizations/{org}/preprodartifacts/snapshots/{snapshot_id}/archive/ (OrganizationPreprodSnapshotArchiveEndpoint) PRIVATE → PUBLIC_EXPERIMENTAL
POST /api/0/projects/{org}/{project}/preprodartifacts/snapshots/ (ProjectPreprodSnapshotEndpoint) already PUBLIC, docs-only fix

Evidence

Behavior fix: snapshot archive POST from a service account

  • Before this PR, the archive POST passed request.user.id to the build task. For a service account that value is a ServiceAccountId, which msgpack can't serialize (TypeError: can not serialize 'ServiceAccountId' object). Those requests returned 503 "Couldn't start the build".
  • The POST now passes acting_user_id(request.user). A service account gets the archive built but no email. Requests from users don't change.
  • The agent-token permission matrix found this once the endpoint was published. Its service-account row fails without the fix.

Changes

  • Assemble (assembleProjectPreprodArtifact, Mobile Builds tag):
    • The request body schema now lives in one constant, PREPROD_ARTIFACT_ASSEMBLE_REQUEST_SCHEMA. Request validation and the OpenAPI request body both use it, so they can't drift apart.
    • New PreprodArtifactAssembleResponse TypedDict: state, missingChunks, and artifactUrl, which is only set when the state is created.
    • idempotent_methods = frozenset(): each successful request creates a build and queues the assembly and status-check tasks again, so a client must not resend it.
    • The chunk-upload prerequisites, ChunkUploadEndpoint and DifAssembleEndpoint, are still PUBLIC_EXPERIMENTAL. A client needs them to upload the chunks before it calls assemble.
  • Snapshot archive:
    • New SnapshotArchiveStatusResponse ({ready}) for the GET readiness check (getOrganizationPreprodSnapshotArchiveStatus).
    • New SnapshotArchiveBuildResponse for the POST 202 (startOrganizationPreprodSnapshotArchive).
    • idempotent_methods = frozenset(): every POST queues another build and sends another email.
    • ?download stays undocumented on purpose. It streams the zip as a binary body. It's a CLI transport exception, and the published schema only describes the JSON readiness response. A code comment says so.
  • Snapshot upload (docs only):
    • request=None is replaced with a real request body built from SNAPSHOT_POST_REQUEST_SCHEMA. The per-image metadata that ImageMetadata checks is described too.
    • The OpenAPI copy uses the OpenAPI 3.0 boolean form of exclusiveMaximum. Validation still uses the JSON Schema one.
    • The docstring now says that the body may be sent with Content-Encoding: zstd, up to 256 MiB after decompression.
  • Shared VCS fields: VCS_SCHEMA_PROPERTIES gets descriptions. Validation doesn't change.
  • Tests:
    • Adds examples and apidocs tests for all four operations. The snapshot upload test also checks that the request body the endpoint accepts passes the documented request schema.
    • AgentTokenPublicGetMatrixTest gets a status-poll payload for the assemble POST and a real snapshot id for the archive rows.

Verification

  • I ran make build-api-docs on this branch and on master (ac2d476) and diffed openapi-derefed.json. The only changes are the three new operations (assemble POST, archive GET and POST), the snapshot upload POST's requestBody and description, and the three new response components.
  • python -m sentry.apidocs.response_coverage: 0 new gaps.
  • pnpm run validate-api-examples: no errors.
  • pytest tests/apidocs: 159 passed.
  • Preprod assemble, snapshot and archive endpoint tests, plus the new apidocs tests: 175 passed.
  • tests/sentry/seer/endpoints/test_organization_agent_token.py: 327 passed, 23 xfailed. That's 2 more rows than on master.
  • prek and mypy (pre-push stage) pass on the changed files.

The "(Optional) Shows the difference between the prod and dev schema" check is expected to fail because this PR changes the schema.

via @BYK.

--

View Session [Sentry]

…points

Make POST .../files/preprodartifacts/assemble/ PUBLIC and the snapshot
archive GET and POST PUBLIC_EXPERIMENTAL, with typed responses,
examples and apidocs tests. Document the snapshot upload request body
from SNAPSHOT_POST_REQUEST_SCHEMA instead of request=None.

The archive POST now passes acting_user_id() to the build task. It
passed request.user.id, which is a ServiceAccountId for service
accounts and can't be serialized, so those requests returned 503.

Part of #130351.

Co-Authored-By: BYK <[email protected]>
@sentry-junior
sentry-junior Bot requested review from a team as code owners November 7, 2026 17:01
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 7, 2026
@BYK
BYK enabled auto-merge (squash) November 7, 2026 17:10
The snapshot archive endpoint now reads acting_user_id(request.user)
instead of getattr(request.user, "id", None), so the ratchet drops by one.

Co-Authored-By: BYK <[email protected]>
@sentry-junior
sentry-junior Bot requested review from a team as code owners November 7, 2026 17:26
@BYK
BYK merged commit 9f3408b into master Nov 7, 2026
66 of 67 checks passed
@BYK
BYK deleted the byk/feat/apidocs-publish-preprod-assemble-snapshot-archive branch November 7, 2026 17:31
BYK pushed a commit to getsentry/toolkit that referenced this pull request Nov 7, 2026
…-release and shared-issue operations (#2095)

Next batch of moving the CLI onto `@sentry/api` generated operations.
Stacked on #2093 (1.49.0). It gets retargeted to `main` once #2093
merges.

`@sentry/api` 1.50.0 publishes five endpoints the CLI already calls:

| CLI function | Endpoint | Operation | Published by |
| --- | --- | --- | --- |
| `listOrgAuthTokens` (`token list`) | `GET
/organizations/{org}/org-auth-tokens/` | `listOrganizationAuthTokens` |
getsentry/sentry#130360 |
| `createOrgAuthToken` (`token create`) | `POST
/organizations/{org}/org-auth-tokens/` | `createOrganizationAuthToken` |
getsentry/sentry#130360 |
| `deleteOrgAuthToken` (`token delete`) | `DELETE
/organizations/{org}/org-auth-tokens/{id}/` |
`deleteOrganizationAuthToken` | getsentry/sentry#130360 |
| `getPreviousReleaseCommit` (`release set-commits`) | `GET
/organizations/{org}/releases/{version}/previous-with-commits/` |
`getOrganizationPreviousReleaseWithCommits` | getsentry/sentry#130359 |
| `getSharedIssue` (share links in `issue view`), raw `customFetch`
until now | `GET /organizations/{org}/shared/issues/{share_id}/` |
`getOrganizationSharedIssue` | getsentry/sentry#130359 |

All five operations have `experimental: false`.

Behavior is unchanged:
- **Org auth tokens** still go to the control silo, and
`OrgAuthTokenSchema` still validates the responses. 401/403 errors are
still enriched by `unwrapResult`. The token id goes into the path as-is,
with the same `as unknown as number` cast as the other numeric-string
ids.
- **Previous release** routes by org through `getOrgSdkConfig`. The SDK
encodes the version, and the silent fallback to `undefined` stays.
- **Shared issue** calls the operation with `customFetch` rather than
the authenticated transport, because a share URL's host may not be the
logged-in one and must never get a bearer token. Custom headers stay
URL-scoped (`applyCustomHeaders`). The CLI's "TLS certificate error",
"Share link not found or expired", "Failed to resolve share link",
"Share link returned invalid JSON" and missing-issue-ID errors are the
same as before.

The bump regenerates
`plugins/sentry-cli/skills/sentry-cli/references/event.md`, which
reorders the event fields from the schema regen. No fields were added or
removed.

### Still on the helpers

| Call site | Endpoint | Waiting on |
| --- | --- | --- |
| `preprod-artifacts.ts` | build assemble, snapshot archive status and
start, snapshot create (zstd body) | shipped in 1.51.0
(getsentry/sentry#130371). The next stacked branch,
`ref/cli-sentry-api-1.51`, is ready |
| `projects.ts` dsn-lookup | `GET /organizations/{org}/dsn-lookup/` |
getsentry/sentry#130367 |
| `auth.ts` | `GET /api/0/` (control silo) | getsentry/sentry#130369 |
| `users.ts` | `GET /auth/` → `GET /users/me/` | getsentry/sentry#130368
|
| `organizations.ts` | `GET /users/me/regions/` | #2091 replaces it with
`listOrganizations` |
| `traces.ts` / `logs.ts` | `GET
/projects/{org}/{project}/trace-items/{id}/` | sentry publish PR still
to come |
| `replays.ts` replay list | `GET /organizations/{org}/replays/` |
`replay list --json` prints `info_ids`/`warning_ids`, which the
generated `field` enum leaves out. Needs a sentry docs fix or a decision
|
| `projects.ts` | `GET /projects/?query=dsn:` fallback for old
self-hosted servers | not public; needs a decision (see #2093) |

These are the agreed exceptions: `trials.ts` (`/customers/*` and the
product-trial PUT), snapshot `upload-options` and archive `?download`,
`downloadBuildArtifact`'s install URL, chunk-upload server URLs, and
`rawApiRequest` for `sentry api`.

### Testing

- `pnpm run tsc` and `pnpm run lint` pass.
- `pnpm run test` fails only on the 5 file-permission tests that also
fail on `main` in the sandbox (`completions` ×2, `upgrade`,
`db/resilient`, `dsn/code-scanner`), plus `@sentry/cli3to4`, whose
codemod binary needs GLIBC 2.35.
- The org-auth-token tests now go through the mocked SDK fetch and check
the control-silo URL, method, body and error naming. The existing
shared-issue tests (404, TLS, invalid JSON, missing id, header scoping)
pass unchanged.

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

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

--

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

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

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
BYK pushed a commit to getsentry/toolkit that referenced this pull request Nov 7, 2026
…hot calls (#2097)

Next batch of moving the CLI onto `@sentry/api` generated operations.
Stacked on #2095 (1.50.0), which is stacked on #2093 (1.49.0). Each PR
gets retargeted as the one below it merges.

`@sentry/api` 1.51.0 carries getsentry/sentry#130371, which publishes
the mobile build assemble endpoint and the snapshot archive endpoints,
and adds a typed body for snapshot create. These call sites in
`lib/api/preprod-artifacts.ts` move onto the generated operations:

| CLI function | Endpoint | Operation | `experimental` |
| --- | --- | --- | --- |
| `uploadBuild` assemble poll loop (`build upload`) | `POST
/projects/{org}/{project}/files/preprodartifacts/assemble/` |
`assembleProjectPreprodArtifact` | false |
| `createPreprodSnapshot` (`snapshots upload`) | `POST
/projects/{org}/{project}/preprodartifacts/snapshots/` |
`uploadProjectPreprodArtifactSnapshot` | false |
| `getSnapshotArchiveReady` (`snapshots download`) | `GET
/organizations/{org}/preprodartifacts/snapshots/{id}/archive/` |
`getOrganizationPreprodSnapshotArchiveStatus` | **true** |
| `triggerSnapshotArchiveBuild` (`snapshots download`) | `POST
/organizations/{org}/preprodartifacts/snapshots/{id}/archive/` (202
`{detail}`) | `startOrganizationPreprodSnapshotArchive` | **true** |

The two archive operations are marked experimental
(`PUBLIC_EXPERIMENTAL` in sentry). They still move, and the planned lint
rule will warn on them.

Behavior is unchanged:
- The CLI's valibot schemas still validate each response
(`BuildAssembleResponseSchema`, which also reads `detail` on error
states, `CreateSnapshotResponseSchema` and
`SnapshotArchiveStatusSchema`). Error messages, 401/403 enrichment and
org region routing (`getOrgSdkConfig`) are the same.
- Snapshot create is still zstd-compressed with `Content-Encoding:
zstd`, and still falls back to plain JSON when the runtime lacks zstd.
That was the only user of the `bodyEncoding` option on
`apiRequestToRegion`, so this PR removes the option.
- Chunk uploads still go to the org region from `resolveOrgRegion`. Only
the assemble call moved.
- The build and snapshot request bodies are now typed from the schema
instead of `Record<string, unknown>`. `vcsInfoToBody` returns a new
`VcsBody` type, and `snapshots upload` builds a typed
`SnapshotManifest`.

### Question for the reviewer: assemble transport retries

The CLI still lets the transport retry the assemble POST, through
`getOrgSdkConfig({ idempotent: true })`, as it did before this PR.
Sentry now declares the opposite: the endpoint sets `idempotent_methods
= frozenset()`, with a comment that a resend after the build leaves the
uploading state creates another build, and the 1.51 docs say not to
resend a request that succeeded.

Server-side, `create_preprod_artifact` does `get_or_create(...,
state=UPLOADING)`, so a resend that arrives while the build is still
uploading reuses the same row. The poll loop returns as soon as it gets
`artifactUrl`, so polling never re-sends after creation. The only risk
is a transport retry after a lost response that lands once assembly has
moved the build out of `UPLOADING`.

I kept the retry so behavior doesn't change in this PR. Dropping it is a
one-line change (`getOrgSdkConfig()`) if you'd rather follow Sentry's
declaration.

### Still on the helpers

| Call site | Endpoint | Waiting on |
| --- | --- | --- |
| `projects.ts` dsn-lookup | `GET /organizations/{org}/dsn-lookup/` |
getsentry/sentry#130367 |
| `auth.ts` | `GET /api/0/` (control silo) | getsentry/sentry#130369 |
| `users.ts` | `GET /auth/` → `GET /users/me/` | getsentry/sentry#130368
|
| `organizations.ts` | `GET /users/me/regions/` | #2091 replaces it with
`listOrganizations` |
| `traces.ts` / `logs.ts` | `GET
/projects/{org}/{project}/trace-items/{id}/` | sentry publish PR still
to come |
| `replays.ts` replay list | `GET /organizations/{org}/replays/` |
`replay list --json` prints `info_ids`/`warning_ids`, which the
generated `field` enum leaves out. Needs a sentry docs fix or a decision
|
| `projects.ts` | `GET /projects/?query=dsn:` fallback for old
self-hosted servers | not public; needs a decision (see #2093) |

These are the agreed exceptions: `trials.ts` (`/customers/*` and the
product-trial PUT), snapshot `upload-options` and archive `?download`,
`downloadBuildArtifact`'s install URL, chunk-upload server URLs, and
`rawApiRequest` for `sentry api`.

`apiRequestToRegionNoContent` has no callers in `src` after this PR.
It's still exported and used by `script/lib/source-api-usage.ts` and two
tests, so it'll be removed with the other helpers in the lint-rule PR.

### Testing

- `pnpm run tsc` and `pnpm run lint` pass. Generated docs and
`command-api.json` don't change.
- `pnpm run test` fails only on the 5 file-permission tests that also
fail on `main` in the sandbox (`completions` ×2, `upgrade`,
`db/resilient`, `dsn/code-scanner`), plus `@sentry/cli3to4`, whose
codemod binary needs GLIBC 2.35.
- `test/lib/api/preprod-artifacts.test.ts` now goes through the mocked
SDK fetch. It checks the method, URL and decoded body for assemble, the
zstd header and the decompressed manifest for snapshot create, the GET →
POST → GET sequence for the archive wait, and a new case where a failed
archive start throws `ApiError`. The `build` and `snapshots` command
tests pass unchanged.

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

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

--

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

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

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant