Repository navigation
feat(seer): Redesign the automation service account section - #130820
Merged
Merged
Conversation
PUT now takes enabled for every strategy. It requires access to every project the automation covers, and sending the current value leaves the version unchanged.
Automations now own their service account. Workflow create and set_agent take agent settings and create or update the account through service_account_service, deleting it if the config fails. The configs endpoint takes agent on create and update, checks the grant, writes audit entries, and returns agent with a read-only serviceAccountId.
Duplicate scopes and project IDs in an agent request are now collapsed before the account is written. Agent projectIds in responses are limited to projects the viewer can access, matching projects and monitorIds.
…metric-automation-agent-settings # Conflicts: # src/sentry/seer/endpoints/organization_seer_workflow_configs.py # src/sentry/seer/workflows/workflow.py # tests/sentry/seer/endpoints/test_organization_seer_workflow_configs.py
Deleting an automation left its service account active with its scopes and projects. The account is now deleted first, so a failed config delete can't leave a live account without an automation, and the removal is audited as SERVICE_ACCOUNT_REMOVE.
The method sets the scopes and projects of the automation's service account rather than attaching an agent, so SeerAgent becomes SeerAgentAccess too. The API's agent field is unchanged.
Only the endpoint checked that an agent's projects belong to the automation's organization, so any other caller could link another organization's project to the account. Creating or updating an agent now runs the same org check as the config's own projects. Also renames the *_agent_account helpers to *_agent_service_account.
Config creation now creates the agent's service account itself instead of taking an optional account ID, so agent is required on create. Creating the account no longer needs service_account:write, since the automation owns it, but callers can still only grant scopes and projects they have. An agent update now keeps the account's projects the caller can't access, like projectIds.
A caller without a global role could replace an all-projects agent with only the projects they can see. Narrowing now needs the same role as granting all projects. The agent project merge also runs before any project or monitor writes, so a denied agent change leaves the automation untouched.
Two first-time agent saves each created an account and the last link won, orphaning the other with its grants. The link now rechecks service_account_id under the config lock; on a change, the new account is deleted and the save updates the account that won.
PUT no longer takes an agent, so this PR covers creating, reading, and deleting an automation's service account. Changing agent access on an existing automation moves to a stacked PR that can build on the single-transaction PUT refactor. Create-side checks that were only tested through PUT now have POST tests.
PUT takes an agent again to replace the scopes and projects of the automation's service account, creating one if the automation has none. Saves keep the account's projects the caller can't access, narrowing an all-projects agent needs a global role, and a concurrent first save updates the account that won instead of orphaning one.
…to telkins/seer-automation-agent-updates
…tion-agent-updates # Conflicts: # src/sentry/seer/endpoints/organization_seer_workflow_configs.py # src/sentry/seer/workflows/breached_metrics.py # src/sentry/seer/workflows/workflow.py # tests/sentry/seer/endpoints/test_organization_seer_workflow_configs.py # tests/sentry/seer/workflows/test_breached_metrics.py # tests/sentry/seer/workflows/test_workflow.py
PUT takes serviceAccount again, matching the rename on POST. An existing account is updated over RPC; an automation without a live account gets one through the create outbox, the same path new automations use. Saves keep projects the caller can't access, and narrowing an all-projects account needs a global role.
…ects A PUT that adds scopes to an automation's service account now fails when the account keeps projects the caller can't access, so a caller can't grant scopes on projects they can't see. Removing scopes and editing projects still work. Kept projects are now limited to active projects in the organization. Before, a project deleted before the tombstone cascade removed its link failed the save with a 400.
PUT no longer creates a service account for an automation without a live one. It returns a 400 instead. Every automation should have an account, and AIML-3850 tracks disabling the ones that lose it. POST and PUT failures past request validation now return a generic detail instead of the exception's message. The error is still logged. Refs AIML-3850
Catch only WorkflowUpdateError instead of any ValueError, so unexpected errors are no longer turned into 400s. Log rejections at info, with the organization, config and reason, instead of logging an ERROR with a traceback for an expected 400.
Add a SERVICE_ACCOUNT_GRANT_UPDATE cell outbox that replaces an account's scopes and projects in control. An owner saves it in its own transaction, so a grant change commits with the owner's other changes.
…utbox' into claude/sentry-pr-129997-review-284bc8
A serviceAccount change on PUT now saves a grant update outbox inside update_config(), so it commits with the other fields, sets updatedBy and bumps the version once. The account is updated in control when the transaction commits. Resending the current grant changes nothing.
Add ServiceAccountCreatePayload and ServiceAccountGrantUpdatePayload TypedDicts, shared by the outbox builders and their receivers, so a field mismatch between them fails type checking.
…utbox' into claude/sentry-pr-129997-review-284bc8
…account tests Replace the separate outbox test file with one test next to the update RPC tests, which already cover the update itself.
…utbox' into claude/sentry-pr-129997-review-284bc8
…utbox' into claude/sentry-pr-129997-review-284bc8 # Conflicts: # src/sentry/seer/endpoints/organization_seer_workflow_configs.py # src/sentry/seer/workflows/workflow.py
…utbox' into claude/sentry-pr-129997-review-284bc8
…9997-review-284bc8
The PUT reads the current account over RPC before taking the config lock, because RPCs can't run inside the transaction. If another save landed in between, the merged grant was built from an outdated account and could undo that save. Compare the config version under the lock and return a 409.
…lock The PUT read the account from control over RPC, which can't run inside the config transaction, so the grant was merged before the lock and a version check returned a 409 when another save landed in between. ConfigUpdate now reads the current grant from the cell replica, so the PUT merges and saves it under the lock like projectIds. set_service_account_grant skips an unchanged grant and returns whether it changed, and the edit is audited from the account read back after the save.
The current grant is read from the cell replica, which can lag control. A PUT that matched a stale replica was skipped as a no-op, so a real change could be dropped. The grant update outbox is now always saved, and the replica comparison only decides the version bump and audit entry. The audit entry and the response are built from the saved grant instead of a re-read of control, which returns the old grant when the outbox flush fails. SeerServiceAccountGrant sorts and dedupes itself so grants compare with ==. The hidden-project helper is split into the lookup and the permission check, and a missing service account logs a warning again.
Merge the hidden-project and deleted-project cases into one test and the two caller-access cases into another, and drop assertions that other tests already cover.
…9997-review-a62210 # Conflicts: # src/sentry/seer/endpoints/organization_seer_workflow_configs.py
Collapse the section to a summary of project and permission counts, and expand it to the full settings. Projects of connected monitors are always granted and shown as locked rows, with other projects added on top, so the grant stays a superset of the monitor projects. Permissions are picked per resource instead of as raw scopes, limited to what the editing user can grant.
Contributor
📊 Type Coverage Diff✅ no issues found |
trevor-e
marked this pull request as ready for review
November 11, 2026 19:50
Base automatically changed from
telkins/seer-automation-agent-updates
to
master
November 12, 2026 18:15
…r-automation-service-account-ux # Conflicts: # src/sentry/seer/endpoints/organization_seer_workflow_configs.py # src/sentry/seer/workflows/workflow.py
gricha
approved these changes
Nov 12, 2026
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 b37a8ab. Configure here.
Disconnecting a monitor on a saved automation left its project granted and listed as added manually, because the saved grant doesn't record where a project came from.
This branch was successfully deployed
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.

Reworks the service account settings on the Seer metric automation form.
The section is collapsed by default to a count of projects and permissions. Expanded, projects of connected monitors are always granted, with other projects added on top, and permissions are picked per resource instead of as raw scopes. The form only offers projects and access levels the editing user can grant.