Skip to content

feat(apidocs): Add a command that writes the API exceptions baseline - #131088

Merged
akhilp117 merged 12 commits into
masterfrom
akhilpindiprolu/eng-8866-put-every-existing-api-flake-error
Nov 18, 2026
Merged

akhilp117 merged 12 commits into
masterfrom
akhilpindiprolu/eng-8866-put-every-existing-api-flake-error

Conversation

@akhilp117

@akhilp117 akhilp117 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

This PR introduces make api-baseline, a new make command that writes every S025-S028 finding to api_exceptions/exceptions.json. The report card and the upcoming CI job will read from this file. The scan and owner lookup it uses are in #131117. Each entry is one finding (an error founds by flake) signature (rule, path, scope, key) with its count, owner, status, reason and when it was first seen

Here's a list of the arguments that can be passed in:

  • --files only rescans the files you pass and keeps everything else as is. Existing entries keep their status, reason and first_seen. It prints what's new, fixed, or changed
  • --root scans another checkout (i.e, an older commit) with the current rules (used for demoing)
  • --force is needed to regenerate the whole file since that resets statuses

Renames, deletions, and bad paths with --files:

  • Entries for a file that's no longer in the checkout are removed and reported as fixed, whether or not that file was listed. So a plain git diff --name-only works and --no-renames isn't needed anymore
  • If a removed entry and a new one share the same rule, scope and key, it warns "Possibly moved", since the status and reason don't carry over to the new path
  • If a file is gone and wasn't listed, it warns that its new path probably needs a rescan, or those findings will show up as new on the next run
  • Paths that can't be rescanned (outside src/, not .py, or missing with no entries, like a typo) are printed to stderr, and the run exits 1 if none of them can be used

@akhilp117
akhilp117 requested review from a team as code owners November 13, 2026 18:10
@linear-code

linear-code Bot commented Nov 13, 2026

Copy link
Copy Markdown

ENG-8866

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 13, 2026
@akhilp117

Copy link
Copy Markdown
Contributor Author

@cursor review

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

Stale Bugbot comment from a previous run.

@akhilp117 akhilp117 self-assigned this Nov 13, 2026
@akhilp117
akhilp117 marked this pull request as draft November 13, 2026 20:27
@akhilp117
akhilp117 force-pushed the akhilpindiprolu/eng-8866-put-every-existing-api-flake-error branch from 53c8335 to 9b329a1 Compare November 13, 2026 20:54
@akhilp117
akhilp117 changed the base branch from master to akhilpindiprolu/eng-8866-add-api-findings-scan November 13, 2026 20:54
@akhilp117
akhilp117 removed request for a team November 13, 2026 20:54
@akhilp117
akhilp117 force-pushed the akhilpindiprolu/eng-8866-put-every-existing-api-flake-error branch from 72f2fd5 to 3fcafb3 Compare November 16, 2026 19:38
@akhilp117
akhilp117 marked this pull request as ready for review November 16, 2026 20:31
@akhilp117
akhilp117 requested a review from a team November 17, 2026 18:43

@sentry-junior sentry-junior 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.

The full-scan path is solid. The count cross-check against flake8 is a good guard, and the tests pass locally (36 passed). --files mode has two problems I'd fix before the CI job starts relying on this file:

  • Renames silently orphan entries and drop reviewed statuses. In main, kept_entries keeps every old entry whose path isn't in rescan_paths, even when that file no longer exists. I reproduced it: generate a baseline, rename the endpoint file, then run --files <new path>, which is what a default git diff --name-only gives you. The file then has both the old-path entry and a new debt-breaking entry for the new path. Any accepted status or reason on the old entry is gone without a warning, and the summary says 0 fixed. The PR description calls out --no-renames as the workaround, but a convention that fails silently will get missed. A simple fix: in --files mode, also treat any kept entry whose args.root / entry["path"] no longer exists as removed, so it shows up under "fixed". Even better, warn when a removed and an added entry share the same (rule, scope, key), so someone can carry the status over by hand. Please add a test for the rename case.

  • Bad --files input is ignored, or it crashes. Paths that don't start with src/ or end in .py are dropped silently. A typo like sentry/api/endpoints/foo.py prints Rescanned 0 files and exits 0, so a CI or pre-commit caller can't tell that nothing happened. An absolute path inside a --root checkout also raises an uncaught ValueError from normalize_path, because it resolves against the current checkout, not --root. Print every skipped path to stderr. Consider returning 1 when none of the given paths were usable, and normalize against args.root (or catch the ValueError and report it as a bad path).

One non-blocking note: entries are dict[str, object] everywhere. That's why you need assert isinstance(count, int) and str(...) casts. It also gives you two separate ideas of identity: BaselineSignature for findings and the tuple from _entry_signature for entries, plus matching _sort_key and _entry_sort_key. An ExceptionEntry TypedDict, plus building entry identity through BaselineSignature, would remove the casts. It would also keep the two from drifting apart if signature normalization changes. Those asserts also disappear under python -O, so they can't be the only thing guarding the write.

The failing migration drift and openapi-diff checks look unrelated, since this PR touches no migrations or API code.

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

I would double check we've accounted for all edge cases like file renames, deletions, moving, etc.

@sentry-junior
sentry-junior Bot dismissed their stale review November 18, 2026 03:43

Addressed in 64036150457 (renamed/deleted files and bad --files paths). Follow-up review below.

@sentry-junior sentry-junior 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.

Follow-up on 64036150457: both earlier blockers are fixed.

  • Renamed or deleted files: --files now drops entries for files that no longer exist in --root and reports them as fixed. You get a "Possibly moved" warning when a new entry matches on rule, scope and key, and a "Removed N entries" warning when the gone file wasn't listed. With the new tests (renamed listed, renamed unlisted), a plain git diff --name-only is safe now, so --no-renames isn't needed.
  • Bad --files input: each unusable path (outside src/, not .py, outside --root, or missing with no entries, like a typo) is printed to stderr. The run exits 1 without writing when none are usable. Absolute paths outside the root no longer crash.

tests/tools/api_guidelines passes (62 tests) at this commit. The ExceptionEntry TypedDict suggestion is fine to leave for a follow-up.

The failing getsentry / backend checks come from the branch being behind master: missing sentry_protos billing modules and SalesConfig.soft_caps. They're not caused by this diff and should clear after a rebase.

@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 6403615. Configure here.

@akhilp117

Copy link
Copy Markdown
Contributor Author

I would double check we've accounted for all edge cases like file renames, deletions, moving, etc.

yeah thanks for bringing this up, I'd originally handled renames by having devs pass git diff --no-renames, but that was easy to get wrong, so I made --files handle it directly. Entries for files that no longer exist (deleted or moved) are dropped and reported as fixed even if the old path isn't listed. If a new entry matches a removed one on rule/scope/key, it warns "Possibly moved", since status and reason don't carry over automatically. Also iff a file is gone and its new path wasn't passed, it warns that the new path needs a rescan. I verified with JR and it seems good for now, no more edge cases

@akhilp117
akhilp117 force-pushed the akhilpindiprolu/eng-8866-put-every-existing-api-flake-error branch from 6403615 to a8383f4 Compare November 18, 2026 03:51
@akhilp117
akhilp117 requested review from a team as code owners November 18, 2026 03:51
@akhilp117
akhilp117 requested review from a team as code owners November 18, 2026 03:51
@akhilp117
akhilp117 requested review from JPeer264 and removed request for a team November 18, 2026 03:51
@cursor

cursor Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

This PR is too large for Bugbot to review. It changes 46,776 lines and 3,737,259 characters. Split the change into smaller pull requests to get a review.

@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Nov 18, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants