Repository navigation
ref(api): Skip per-user serializer lookups when no user is calling - #129254
Merged
Merged
Conversation
This was referenced Oct 29, 2026
Contributor
Sentry Snapshot Testing
|
gricha
force-pushed
the
ref/sa-serializer-viewer
branch
from
October 29, 2026 22:33
b45263d to
7861c76
Compare
gricha
force-pushed
the
ref/sa-serializer-viewer
branch
from
October 29, 2026 22:39
7861c76 to
3db525d
Compare
gricha
force-pushed
the
ref/sa-serializer-viewer
branch
from
October 29, 2026 23:26
3db525d to
84109b1
Compare
This was referenced Oct 29, 2026
gricha
force-pushed
the
ref/sa-serializer-viewer
branch
from
October 29, 2026 23:53
84109b1 to
aa2c828
Compare
gricha
force-pushed
the
ref/sa-serializer-viewer
branch
from
October 30, 2026 18:40
f4f96a9 to
610b425
Compare
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
) On a DRF request, a service account's `request.user` is a `ServiceAccountPrincipal` instead of `AnonymousUser`. Service accounts are gated by `organizations:service-accounts`, which is now checked at authentication too (`authenticate_service_account`), so that flag is the one switch. Before, only service-account creation and the token endpoint checked it, and anything holding the shared secret could sign a service-account viewer context. The principal has no user, so `has_user()` is False and `acting_user_id()` is None, and its actor is `SERVICE_ACCOUNT`. Its `id` is a `ServiceAccountId` that never equals an int and raises `UserRequired` (403 `user-required`) when converted to one, so no `request.user.id` call site can reach the user with the same number. **Temporary:** `ServiceAccountId` is a runtime guard, because about 490 `request.user.id` reads still assume a user. It's deleted, along with the RPC pass-through for `UserRequired`, once mypy types `request.user` to include `ServiceAccountPrincipal` (plugin, shrinking per-module allowlist) and those reads are migrated. This PR sits right above the chokepoint on purpose: every PR after it is written and tested against the real principal. Endpoints aren't blocked up front. What breaks for a service account shows up in the auth matrix, and the PRs above fix it or mark the endpoint `requires_user`. What else this changes: - **Web views:** `set_request_principal` sets a service account only on a DRF `Request` (its setter also copies it to Django's `request.user`). Until DRF authenticates it, Django's `request.user` is anonymous, and session auth never sees it, since `ViewerContextAuthentication` runs before `SessionAuthentication`. The check reads the credential (`is_service_account_auth(auth)`), not `isinstance(user, ...)`: the middleware passes Django's lazy user, and loading it reads the session, which adds `Vary: Cookie` to every response. `test_leaves_lazy_user_unloaded` guards it. - **Access:** `SentryPermission.determine_access` asks `has_user()` and `acting_user_id()`, so a service account keeps the credential-based access (`from_rpc_auth`) it had as `AnonymousUser`, instead of its `ServiceAccountId` reaching the org lookup. - **Sudo:** neither the decorator nor the sudo middleware treats a service account as sudo; both ask `has_user()` before `has_usable_password()`. Sudo re-authenticates a person, so `require_sudo()` answers a caller with no user with a 403 `user-required` instead of a sudo prompt, from `@sudo_required` and from project delete. Org, team and project delete and project transfer stay user-only. - **Rate limits:** service accounts get their own bucket. - **RPC:** `UserRequired` passes through as an API error. The auth matrix enables the flag for its service-account rows and records what still fails at this point in the stack. Rows that don't match the oracle are strict xfails, so the PR that fixes a row has to remove it. At this point 89 service-account rows are known gaps: 28 audit actors, 21 per-user serializer lookups, 20 `request.user.id` reads, 2 `serialize_generic_user`, 1 project creation that needs `require_user`, 12 control-silo endpoints and 5 that check the caller's own membership or org role. The PRs above remove them. At the top of the stack, 17 remain: the control-silo and membership ones. This replaces #128983, split per review. It builds on #128779, now landed. **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 610b425. Configure here.
Serializers look up the viewer's own state by user id: team and org roles, access requests, bookmarks, seen and subscriptions, broadcasts seen, and starred and last-visited saved queries. They now gate those lookups on has_user() instead of is_authenticated, so a caller with no human behind it, e.g. a service account, gets them empty instead of a user-required 403. Discover and Explore saved queries had no gate; they get the same one.
A service account without open membership lists only its linked projects, and one with open membership also lists projects that have no team.
gricha
force-pushed
the
ref/sa-serializer-viewer
branch
from
October 30, 2026 19:18
610b425 to
48fff90
Compare
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
Checks that meant "is there a user" asked "is logged in" (`is_authenticated`) or read `request.user.id`. They now ask `has_user()` or call `acting_user_id(request.user)`. Every existing caller gets the same answer; only a `ServiceAccountPrincipal`, which is authenticated but has no user, changes. Nothing here is the runtime fix for service accounts: that's `determine_access` in #129146. These change for consistency and defense: - **Control-silo org lookups** use `acting_user_id()`. - **`users/me`** is a defensive 404 for a service account. - **`normalize_valid_user`** returns None unless `has_user()`, so `from_request` with no org gives a service account no access instead of an `OrganizationlessAccess`. - **Rate limits** ask `has_user` instead of `isinstance(AnonymousUser)`. The viewer-context middleware now builds its actor with `resolve_actor` instead of a copy of it. That's deduplication: the only difference is that a service-account credential gets `SERVICE_ACCOUNT` instead of `UNKNOWN`, and the signed header overrides that anyway. Service accounts are gated by `organizations:service-accounts`. **Matrix:** fixes no service-account rows (known gaps stay at 89). **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
Endpoints accept every caller by default: users, agents and service accounts. One that only works for a user sets `requires_user = True`, and a `ServiceAccountPrincipal` (authenticated, no user) gets a 403 `user-required` before the handler runs. `UserEndpoint` and `RegionSiloUserEndpoint` set it, so most account routes are covered by inheritance. Which one to use: - **Browser-only endpoints** use `SessionNoAuthTokenAuthentication`, which refuses every token, so a service account never authenticates there. - **`requires_user`** is for endpoints people may call with any credential, API tokens included, but a caller with no user may not. - **`require_user(request)`** is for one user-only path inside an otherwise shared endpoint. It returns the user, or raises `NotAuthenticated` (anonymous) or `UserRequired` (no user). Creating a project calls it, since the new project's default team is the creator's own. Every `UserRequired` increments `api.user_required`, tagged by endpoint class (the same tag `record_deprecated_scope_translation` uses). That gives a burn-down list of endpoints service accounts still can't use. **Matrix:** fixes 1 service-account row (known gaps 89 → 88). The row is project creation, which now answers `user-required` instead of a 500 reading the principal's `email`. **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
…user (#129144) A `ServiceAccountPrincipal` on `request.user` has no user (`acting_user_id()` is None), and its `id` is a `ServiceAccountId`, not a user id. These checks keep new code from relying on either: - **S032** (flake8, enforced; no existing hits): `acting_user_id()` used as a queryset lookup (`filter`, `exclude`, `get`, `get_or_create`, `update_or_create`). It's None for a service account, so the lookup matches rows with no user. Writing None, e.g. to `created_by_id`, is allowed, because that's how a caller with no user is recorded. - **S033** (flake8, enforced; no existing hits): assigning `request.user` or `request.auth`, plainly, annotated, augmented, by tuple unpacking or with `setattr`, anywhere but `set_request_principal`. It replaces the AST test from #129133, so the check lives in one place. Tests may still assign them. - **`request.user.id` / `.pk`** (test, exact baseline 492): not a user id for a service account. New uses fail, and the baseline only goes down. - **`isinstance` / `hasattr` / `getattr` on `request.user`** (test, exact baseline 31): sniffing the class instead of branching on `has_user()`. The two baselines are exact, so a fix also has to lower them and they can't drift back up. **Matrix:** fixes no service-account rows (known gaps stay at 88). **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
…ts (#129154) A `ServiceAccountPrincipal` is authenticated but has no user, and its `id` is a `ServiceAccountId` that raises `UserRequired` when used as a user id. Org details, org index, teams, project index, organization projects, `Team` lookups, the org deletion actor and `auth_organization_config` treated `is_authenticated` as "is there a user" or read `request.user.id`. They now ask `has_user(request.user)`, or call `acting_user_id(request.user)` where they need the id, so a service account records no user instead of getting a 403 `user-required`. The organization projects checks moved here from the core PR. `RpcAuditLogEntryActor.actor_id` becomes optional to match. Nothing changes for users and agents. Split out so the owning team can review its slice. `organizations/{org}/projects/` lists a service account's projects the way it lists an agent's: every project in the org that its access reaches. One without open membership sees only its linked projects, and projects with no team are included, which the org-token branch it used to share left out. `projects/` scopes a credential without global access to `accessible_project_ids`; org tokens have global access, so they're unaffected. Per warden and Bugbot; the tests land in #129254, where service accounts first get past the project serializer. Deleting an organization now calls `require_user(request)`, as its docs say it needs a user. Sudo already keeps a service account out; this keeps the rule in place if sudo ever opens to service accounts. Per warden. **Matrix:** fixes 1 service-account row (known gaps 88 → 87). **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
…9155) A `ServiceAccountPrincipal` is authenticated but has no user, and its `id` is a `ServiceAccountId` that raises `UserRequired` when used as a user id. `update_groups`' acting user, group integration and external-issue activity, and per-user issue defaults treated `is_authenticated` as "is there a user" or read `request.user.id`. They now ask `has_user()`, or call `acting_user_id(request.user)` where they need the id, so a service account records no user instead of getting a 403 `user-required`. Nothing changes for users and agents. Split out so the owning team can review its slice. Bookmarking or subscribing with no user behind the caller now raises `UserRequired` before any group changes. Before, it wrote a bookmark or subscription with no user and answered 500, which on master already happens for org API keys. Per warden. **Matrix:** fixes 3 service-account rows (known gaps 87 → 84). **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
… events (#129149) A `ServiceAccountPrincipal` is authenticated but has no user, and its `id` is a `ServiceAccountId` that raises `UserRequired` when used as a user id. Discover and Explore saved queries, saved formulas, and the events base treated `is_authenticated` as "is there a user" or read `request.user.id`. They now ask `has_user(request.user)`, or call `acting_user_id(request.user)` where they need the id, so a service account records no creator instead of getting a 403 `user-required`. Nothing changes for users and agents. Split out so the owning team can review its slice. **Matrix:** fixes 15 service-account rows (known gaps 84 → 69). **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
) A `ServiceAccountPrincipal` is authenticated but has no user, and its `id` is a `ServiceAccountId` that raises `UserRequired` when used as a user id. `DashboardRevision` read `user.id` for its creator, and `get_creator_reference` (#129219), which fills a new dashboard's creator columns, read `request.user.id` for the user one. Both now call `acting_user_id(...)`. `get_creator_reference` checks the credential first, so a service account is recorded in `created_by_service_account_id`; a revision it makes records no creator instead of a 403 `user-required`. Nothing changes for users and agents. Split out so the owning team can review its slice. **Matrix:** fixes no service-account rows (known gaps stay at 69). **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
…eator (#129150) A `ServiceAccountPrincipal` is authenticated but has no user, and its `id` is a `ServiceAccountId` that raises `UserRequired` when used as a user id. The detector and workflow validators treated `is_authenticated` as "is there a user" for the audit actor and read `request.user.id` for the creator. They now ask `has_user(request.user)` and call `acting_user_id(request.user)`, so a service account records no creator instead of getting a 403 `user-required`. Nothing changes for users and agents. Split out so the owning team can review its slice. **Matrix:** fixes no service-account rows (known gaps stay at 69). **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
A `ServiceAccountPrincipal` is authenticated but has no user, and its `id` is a `ServiceAccountId` that raises `UserRequired` when used as a user id. `has_viewed` and viewed-by on replay details read `request.user.id`. They now call `acting_user_id(request.user)`, so a service account isn't recorded as a viewer instead of getting a 403 `user-required`. Nothing changes for users and agents. Split out so the owning team can review its slice. **Matrix:** fixes 1 service-account row (known gaps 69 → 68). The row is `OrganizationReplayDetails`; locally it also fails for every credential on an objectstore error, so CI is the check. **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
A `ServiceAccountPrincipal` is authenticated but has no user, and its `id` is a `ServiceAccountId` that raises `UserRequired` when used as a user id. The snapshot uploader on preprod snapshot endpoints read `request.user.id` when authenticated. It now calls `acting_user_id(request.user)`, so a service account records no uploader instead of getting a 403 `user-required`. Nothing changes for users and agents. Split out so the owning team can review its slice. **Matrix:** fixes no service-account rows (known gaps stay at 68). **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
azulus
approved these changes
Oct 30, 2026
| ) | ||
| starred_queries: dict[int, int | None] = {} | ||
| user_last_visited: dict[int, datetime] = {} | ||
| if has_user(user): |
Member
There was a problem hiding this comment.
is the ideal behavior here to not do this work or to do nothing? seems fine, just making sure
Member
Author
There was a problem hiding this comment.
yeah i think this is fine, we just wanna skip the starring/user last visited updated because that requires user, but saved queries are org wide so i wouldnt skip completely
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
…nts (#129153) A `ServiceAccountPrincipal` is authenticated but has no user, and its `id` is a `ServiceAccountId` that raises `UserRequired` when used as a user id. The scheduled deletion actor, onboarding, Tempest credentials, Seer agentic triage and integration direct-enable treated `is_authenticated` as "is there a user" or read `request.user.id`. They now ask `has_user()`, or call `acting_user_id()` where they need the id, so a service account records no user instead of getting a 403 `user-required`. Nothing changes for users and agents. Split out so the owning team can review its slice. `get_owner_id` in onboarding asks `has_user()` too, so a project created by a service account falls back to the org's default owner. Per warden. **Matrix:** fixes no service-account rows (known gaps stay at 68). **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
`create_audit_entry` records `request.user` as the actor only when `has_user()` says a user is behind the caller. A `ServiceAccountPrincipal` gets no actor (`actor_id` stays null) and is labeled `service_account:<id> (<name>)`, so the log says which account did it, survives renames, and can't pass for a person. Generic actor type + id columns on the audit log replace the label later (follow-up). Before this, the service account's `id` reached `AuditLogEntry.actor_id` and raised `UserRequired`, so every audited write answered 403 `user-required`. `ProjectOwnershipEndpoint` and `ProjectPerformanceIssueSettingsEndpoint` passed `actor=request.user` explicitly; they now use the default. **Matrix:** fixes 28 service-account rows (known gaps 68 → 40). **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
) `serialize_generic_user` returns None when no user is behind the caller, checked with `acting_user_id(user) is None` instead of `user.id is None`. A service account's `id` is a `ServiceAccountId`, not None, so it fell through to the `TypeError` for unknown types and the endpoint answered 500 (release details PUT, replay viewed-by). A deleted user still serializes to None, since it has no id (`test_client_config_deleted_user`). **Matrix:** fixes 2 service-account rows (known gaps 19 → 17). **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
gricha
added a commit
that referenced
this pull request
Oct 30, 2026
Flagpole's user context is empty when no user is behind the actor, checked with `has_user()` instead of `isinstance(user, AnonymousUser)`. A service account passed as `actor=request.user` failed the actor type check, and `features.has()` swallows that error and returns False, so every flagpole flag read as off for it. The type check goes, since `has_user()` narrows to `User | RpcUser`. **Matrix:** fixes no service-account rows (known gaps stay at 17). Flagpole runs in getsentry, so the sentry matrix can't see this. **Stack** (each PR is based on the one above it): 1. #128982 Shared `request.user` interface 2. #129133 Set `request.user` / `request.auth` through one helper 3. #129146 Service accounts on `request.user` 4. #129136 `has_user()` in access, org lookups and `users/me` 5. #129143 `requires_user` / `require_user()` 6. #129144 Lints for patterns that break for a service account 7. #129154 Orgs, teams, projects 8. #129155 Issues 9. #129149 Discover, Explore 10. #129156 Dashboards 11. #129150 Workflow engine 12. #129151 Replays 13. #129152 Preprod 14. #129153 Remaining endpoints 15. #129253 Audit entries 16. #129254 Per-user serializer lookups 17. #129255 `serialize_generic_user` 18. #129256 Flagpole user context
sentry-junior Bot
added a commit
that referenced
this pull request
Oct 30, 2026
Co-Authored-By: Joshua Li <[email protected]>
sentry-junior Bot
added a commit
that referenced
this pull request
Oct 30, 2026
Co-Authored-By: Joshua Li <[email protected]>
joshuarli
added a commit
that referenced
this pull request
Nov 2, 2026
…lowest job (#129398) Stacked on #129387 (Arm runners for PRs), which is stacked on #129338 (4 xdist workers). Aims for a slowest selective backend job of about 3 minutes on the Arm PR runners. **Headline:** on two real PR selections, the slowest selective backend job dropped from 267–369s to 191–215s (−31% and −41%), running exactly the same tests. ## Rollout order Land these in order. Each is stacked on the one before, so after one merges, retarget the next PR's base to `master` and rebase it. Each can be reverted on its own. 1. **#129338: 4 xdist workers, `ubuntu-26.04`** - **Scope:** backend tests on pull requests and master (PRs 2 → 4 workers, master 3 → 4). `backend test` and `acceptance` move to x64 `ubuntu-26.04`. Also adds the Kafka healthcheck shim, the assert-rewrite prewarm, Postgres with durability off, and the resource monitor. - **Expected impact:** backend test time about **−6% (±2%)** compared with 3 workers on the same code, after correcting for runner CPU type. PRs gain more, since they ran 2 workers. Acceptance jobs about **−5%** compared with master. - **getsentry:** not affected. It has its own scripts and Namespace runners. 2. **#129387: Arm runners for pull requests, faster Selenium waits** - **Scope:** `backend test` and `acceptance` run on `ubuntu-26.04-arm` **for pull requests only**; master stays on amd64. Also includes the Chromium snap for Arm acceptance, the compiled Arm pydantic wheels in `uv.lock`, and in `selenium.py` 0.1s wait polling plus debug capture only on failure. - **Expected impact on PRs, compared with 4-worker x64:** backend test time **−27%**, slowest shard **−33%**, median job **−25%**. Acceptance is about **−10%** compared with master. - **Selenium change:** cuts acceptance test time about **−7%** more on Arm. It isn't Arm-specific, so it also applies to master's x64 acceptance runs and to getsentry's acceptance tests, which use the same fixture. The `uv.lock` change only adds Arm wheels, which x64 installs ignore. 3. **#129398: size selective shards by test duration** **← this PR** - **Scope:** only selective backend runs on PRs. Full runs (master, and PRs with `Trigger: Override Selective Testing`) are unchanged. - **Expected impact:** measured at a 45s per-worker budget, the slowest selective job went from 267–369s to **191–215s** (−31% / −41%). The final 40s budget targets about **3 minutes**; that's modelled, not measured. - **Runner time:** −23% on a large selection, +40% on a small one that includes the 794s `test_organization_agent_token.py`. - **getsentry:** not affected. It has its own shard scripts. **Whole stack, on pull requests:** backend test time is about **−40%** compared with master today, the slowest shard about −45% and the median job about −31%. Roughly a quarter of the gain comes from the 4th worker and most of the rest from Arm. Selective PR runs should land near a 3-minute slowest job. ## Why test counts weren't enough Two selective runs on #129387 (files from #129352 and #129254): | | #129391 (51 files) | #129392 (173 files) | |---|---|---| | Shards (2,550 / 6,893 tests ÷ 300) | 9 | 23 | | Slowest test step / median | 161s / 143s | 261s / 99s | | Slowest job | 267s | 369s | - **Shards are packed by test count, not time.** The 369s job had 12 files worth 468s in the durations file; the median shard had about 150s. - **A split file runs on one xdist worker.** With `--dist=loadfile`, each shard that got a slice of `tests/sentry/seer/endpoints/test_organization_agent_token.py` (794s, picked by both PRs) ran it on 1 of 4 workers for ~150s. - **About 145s of every job is fixed**: ~100s setup, ~10s teardown and ~35s pytest startup and collection. A 3-minute job leaves each worker about 40–45s of tests, timed as in `backend-test-durations.json`. Arm runs them about 25% faster than that. ## What changes - `pytest-selected.py`: selective runs use the same plan as full runs, `plan_full_shards`, over just the selected files and weighted by duration. Slow files get sliced across shards so every slice can go to a different worker. Slices are coarser than in full runs (`SELECTED_PIECES_PER_SHARD = 8` instead of 48), so shards don't all import the same files. Without the durations file, it falls back to the old count-based plan. - `calculate-backend-test-shards.py`: when it has the selected files, it picks enough shards that no xdist worker gets more than `WORKER_SECONDS_PER_SHARD = 40` seconds, and enough for the slowest file's slices to fit too. The 30-shard cap stays. If the selected files are missing, the item-count path (`TESTS_PER_SHARD = 300`) is still the fallback. - `count_test_items.py`: `estimate_file_seconds`, shared by both scripts. It's the existing `file_weights` logic moved so `calculate-backend-test-shards.py` can use it without pytest. - `backend.yml`: `calculate test shards` downloads the selected-tests artifact. Full runs (master, and PRs with `Trigger: Override Selective Testing`) are unchanged. ## Measured with a 45s budget (both experiments re-run on this branch, same selected files, Arm, 4 workers) | | #129391 files: before (2 runs) | after ([41143869940](https://github.com/getsentry/sentry/actions/runs/41143869940)) | #129392 files: before (2 runs) | after ([41143871561](https://github.com/getsentry/sentry/actions/runs/41143871561)) | |---|---|---|---|---| | Shards | 9 | 18 | 23–24 | 22 | | Slowest job | 267–288s | **191s (−31%)** | 358–369s | **215s (−41%)** | | Median job | 247–253s | 163s | 202–207s | 178s | | Slowest test step | 161–172s | 75s | 254–261s | 111s | | Test step, summed | 1,107–1,157s | 1,162s | 2,515–2,632s | 1,697s | | Runner minutes | 35–36 | 49 (+40%) | 84–86 | 66 (−23%) | | Tests run | 2,894 passed, 17 xfailed | identical | 7,231 passed, 20 skipped, 21 xfailed, 2 xpassed | identical | - The model predicted ~184s and ~193s. The real slowest jobs landed 7–22s above that, so the final commit lowers `WORKER_SECONDS_PER_SHARD` from 45 to **40**. On the same two selections that plans 20 and 25 shards (from 18 and 22), to put the slowest job at about 3 minutes. That last step is modelled, not re-measured. - The bigger selection gets cheaper as well as faster, because shards no longer wait on a single worker. - The smaller one costs more runner time, all from slicing `test_organization_agent_token.py` (794s) into 18 pieces. Speeding up that file would cut both the shard count and about 5% of all backend CI time. <!-- junior-request-attribution:start --> via @joshuarli. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AD0BQC9WSQ2E%3A1793386300.592079 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AD0BQC9WSQ2E%3A1793386300.592079) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AD0BQC9WSQ2E%3A1793386300.592079/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Joshua Li <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Serializers that look up the viewer's own state by user id now gate those lookups on
has_user(user)instead ofuser.is_authenticated: team memberships, org roles, access requests, project bookmarks, issue bookmarks, seen and subscriptions, and broadcasts seen. Discover and Explore saved queries had no gate on starred and last-visited, and passedas_userwheneveruser.idwas truthy; they use the same check.A caller with no user behind it, e.g. a service account, gets those per-user fields empty, as an anonymous viewer does, instead of a 403
user-requiredfrom itsServiceAccountIdreaching the ORM. The object itself is still serialized in full.get_member_totalskeepsis_authenticated: member counts aren't per-viewer. Dashboard, issue view and Sentry App serializers still readuser.idand aren't covered here.Also adds the tests for #129154's project listing: a service account without open membership lists only its linked projects, and one with open membership also lists projects with no team. They can't pass below this PR, because the project serializer is what still refused service accounts.
Matrix: fixes 21 service-account rows (known gaps 40 → 19).
Stack (each PR is based on the one above it):
request.userinterfacerequest.user/request.auththrough one helperrequest.userhas_user()in access, org lookups andusers/merequires_user/require_user()serialize_generic_user