Skip to content

feat(seer): Redesign the automation service account section - #130820

Merged
trevor-e merged 45 commits into
masterfrom
telkins/seer-automation-service-account-ux
Nov 12, 2026
Merged

trevor-e merged 45 commits into
masterfrom
telkins/seer-automation-service-account-ux

Conversation

@trevor-e

@trevor-e trevor-e commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

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.

Screenshot 2026-11-11 at 2 08 05 PM Screenshot 2026-11-11 at 2 22 47 PM

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

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

📊 Type Coverage Diff

✅ no issues found

@trevor-e
trevor-e marked this pull request as ready for review November 11, 2026 19:50
@trevor-e
trevor-e requested a review from a team as a code owner November 11, 2026 19:50
Base automatically changed from telkins/seer-automation-agent-updates to master November 12, 2026 18:15
@trevor-e
trevor-e requested review from a team as code owners 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

@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 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.
@trevor-e
trevor-e merged commit 442b0ec into master Nov 12, 2026
77 checks passed
@trevor-e
trevor-e deleted the telkins/seer-automation-service-account-ux branch November 12, 2026 18:43

This branch was successfully deployed

1 active deployment
Preview — f29cf7e4 Deployed Nov 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants