Skip to content

ci(api): Regenerate the frontend API URLs and contracts on backend changes - #129766

Closed
billyvg wants to merge 3 commits into
billyvg/feat/api-contracts-generatedfrom
billyvg/feat/api-contracts-ci
Closed

billyvg wants to merge 3 commits into
billyvg/feat/api-contracts-generatedfrom
billyvg/feat/api-contracts-ci

Conversation

@billyvg

@billyvg billyvg commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Why?

apiContracts.generated.ts is built from backend serializers and response annotations, so it goes stale whenever a backend response changes. Right now it's only regenerated when someone runs make build-api-contracts by hand.

How?

One backend job, api typescript generation, replaces the API URL job. On every backend change it regenerates knownSentryApiUrls.generated.ts, then the contracts from those URLs, and commits both back to the PR in one commit. Before committing, it typechecks the frontend against the new contracts, so a backend change that breaks a frontend consumer fails the job instead of being committed.

build-api-contracts now depends on a new build-api-urls make target, so the contracts are never built against stale URLs, in CI or locally.

Decisions

  • The URL and contracts syncs are one job because the contracts generator keys its response types on the known URLs file. Run side by side, the contracts were built against the old URLs and dropped any new route. Each job also committed separately, and each bot commit cancelled and restarted the whole backend run.
  • It runs on every backend change, not only urls.py, since response types can come from anywhere in the backend. The URL sync only takes seconds once the job has set up.
  • It isn't part of the required Backend check yet, while the contracts are new. If the contracts fail to build, typecheck or lint, the job fails but drops them and still commits the URLs, so the existing URL sync keeps working.
  • On PRs it runs on ubuntu-26.04-arm, like the other backend jobs.
  • Fork PRs get no secrets, so there it still regenerates and typechecks but skips the commit. The app token is minted only after the PR's own code has run. The old URL job minted it before checkout.
  • Like the API URL file, the generated file has no CODEOWNERS owner and doesn't count toward the frontend/backend scope warning, so the bot's commit doesn't request frontend review on backend PRs.
  • Catching drift on master (e.g. two PRs merging out of order) and making the job required are left for a follow-up.

🤖 Generated with Claude Code

@billyvg
billyvg requested review from a team as code owners November 3, 2026 20:26
@github-actions github-actions Bot added Scope: Frontend Automatically applied to PRs that change frontend components Scope: Backend Automatically applied to PRs that change backend components labels Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9e112ec. Configure here.

# consumer of its response type, so the failure shows on the change that
# caused it and the contracts are never committed broken.
- name: Typecheck API contracts and consumers
run: pnpm run typecheck

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typecheck missing Node heap limit

Medium Severity

The new required job runs pnpm run typecheck without the NODE_OPTIONS heap limit that frontend.yml and type-coverage-diff.yml set for the same command. Combined with backend-ci services on ubuntu-26.04-arm, tsc can exhaust the Node heap and fail the Backend check on backend-only PRs.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9e112ec. Configure here.

@linear-code

linear-code Bot commented Nov 3, 2026

Copy link
Copy Markdown

CW-3039

@billyvg
billyvg force-pushed the billyvg/feat/api-contracts-ci branch from 9e112ec to f835977 Compare November 3, 2026 20:44
@billyvg
billyvg force-pushed the billyvg/feat/api-contracts-generated branch from 17d1fc8 to b5413db Compare November 3, 2026 20:44
@getsantry
getsantry Bot requested a review from a team as a code owner November 3, 2026 20:48
@billyvg
billyvg force-pushed the billyvg/feat/api-contracts-ci branch from 39c7466 to f86e91d Compare November 3, 2026 21:05
@billyvg
billyvg force-pushed the billyvg/feat/api-contracts-generated branch from b5413db to 36eef60 Compare November 3, 2026 21:05
@sentry

sentry Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Sentry Snapshot Testing

Name Added Removed Changed Renamed Unchanged Skipped Status
sentry-frontend
sentry-frontend
0 0 0 0 780 0 ✅ Unchanged

⚙️ sentry-frontend Snapshot Settings

Add an api-contracts-typescript backend job that runs `make build-api-contracts`,
typechecks and lints the result, and commits the regenerated
apiContracts.generated.ts back to the PR, like api-url-typescript does for
knownSentryApiUrls.generated.ts. It runs on every API docs change because response
types come from serializers anywhere in the backend, and it's part of the required
Backend check.

The app token is minted only after the PR's own code has run, and fork PRs, which
get no secrets, skip the commit instead of failing. The file is exempt from the
frontend/backend scope warning and has no CODEOWNERS owner, like the API URL file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@billyvg
billyvg force-pushed the billyvg/feat/api-contracts-ci branch from f86e91d to ff8b731 Compare November 3, 2026 22:59

@joshuarli joshuarli 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.

cool

@scttcper scttcper 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.

feels like we might combine these jobs that all run when an api changes, like the knownApi thing

@billyvg
billyvg marked this pull request as draft November 4, 2026 15:56
The contracts generator keys its response types on knownSentryApiUrls.generated.ts, so running the URL and contracts jobs side by side built the contracts against the old URLs and dropped any new route. Each job also committed back to the PR, and each bot commit cancelled and restarted the whole backend run.

One job now syncs the URLs, then the contracts against them, and commits both at once. build-api-contracts depends on a new build-api-urls make target, so the local build can't use stale URLs either.

The job is left out of backend-required-check while the contracts are new. If the contracts fail to build, typecheck, or lint, the job drops them and still commits the URLs, so the existing URL sync keeps working.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@billyvg billyvg changed the title ci(api): Regenerate the frontend API contracts on backend changes ci(api): Regenerate the frontend API URLs and contracts on backend changes Nov 4, 2026
tsc and eslint run in this job without the --max-old-space-size that
frontend.yml and type-coverage-diff.yml set for the same commands, and
next to backend-ci's services they can run out of heap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@billyvg billyvg closed this Nov 9, 2026
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 Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants