Skip to content

feat(seer): Backfill SeerAgentRun.group_id from autofix category_value#117561

Merged
trevor-e merged 1 commit into
masterfrom
trevorelkins/aiml-2954-backfill-seeragentrungroup_id
Jun 12, 2026
Merged

feat(seer): Backfill SeerAgentRun.group_id from autofix category_value#117561
trevor-e merged 1 commit into
masterfrom
trevorelkins/aiml-2954-backfill-seeragentrungroup_id

Conversation

@trevor-e

@trevor-e trevor-e commented Jun 12, 2026

Copy link
Copy Markdown
Member

Summary

Backfills SeerAgentRun.group_id for historical autofix rows. group_id was only recently wired up, so existing rows lack it — a prerequisite for the local group_id lookup in the autofix issue-details path.

For autofix runs, extras["category_value"] is the stringified group id. The migration sets group_id from it for rows where source="autofix" and group_id IS NULL. (The source filter is load-bearing: other sources like dashboard_generate put unrelated ids in category_value.)

Defensive guarantees

Given this is a multi-tenant table, the backfill validates before linking rather than trusting category_value:

  • Tenant isolation: only links when the resolved group's org (group.project.organization_id) matches the run's org. A corrupt or foreign category_value can never link a run to another org's group — it's skipped. This also backstops the assumption that an autofix row's category_value really is a group id.
  • Existence: a group that no longer exists is skipped rather than written as a stale id.
  • Parse safety: category_value is parsed with int() + bigint-range bound rather than str.isdigit() (which returns True for unicode digits like "²" that int() then rejects), so malformed data is skipped instead of crashing the migration.

Counts for each skip reason (bad_value / missing_group / org_mismatch) and the linked total are logged. is_post_deployment = True — run manually after deploy.

Test plan

tests/sentry/seer/migrations/test_0018_... covers: same-org autofix row (linked), cross-org group (skipped), missing group (skipped), already-set group_id (untouched), non-autofix source (skipped), and missing / non-numeric / unicode-digit / oversized category_value (skipped). Passes with pytest --migrations.

Refs AIML-2954

@linear-code

linear-code Bot commented Jun 12, 2026

Copy link
Copy Markdown

AIML-2954

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

Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/seer/migrations/0018_backfill_seer_agent_run_group_id.py

for 0018_backfill_seer_agent_run_group_id in seer

--
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL

@trevor-e trevor-e force-pushed the trevorelkins/aiml-2954-backfill-seeragentrungroup_id branch 5 times, most recently from 3d7c390 to 3518493 Compare June 12, 2026 20:03
SeerAgentRun.group_id was only recently wired up, so historical autofix
rows have it unset. For autofix runs, extras["category_value"] holds the
stringified group id, so use it to recover group_id in batches.

Only link when the resolved group's org matches the run's org. In a healthy
system category_value is always the run's own group, so this only ever rejects
corrupt or foreign data — but as a tenant-isolation guard it guarantees the
backfill can never link a run to another org's group, and it backstops the
assumption that an autofix row's category_value really is a group id. A group
that no longer exists is skipped rather than written as a stale id.

category_value is parsed defensively (str.isdigit() is not a safe int() guard
for unicode digits) and bounded to the bigint range so malformed data is
skipped, never crashing the migration.

This is a prerequisite for switching the autofix issue-details path to a local
group_id lookup.

Refs AIML-2954
Co-Authored-By: Claude <noreply@anthropic.com>
@trevor-e trevor-e force-pushed the trevorelkins/aiml-2954-backfill-seeragentrungroup_id branch from 3518493 to f4458a7 Compare June 12, 2026 20:28
@trevor-e trevor-e marked this pull request as ready for review June 12, 2026 20:47
@trevor-e trevor-e requested review from a team as code owners June 12, 2026 20:47
@trevor-e trevor-e merged commit bb429b8 into master Jun 12, 2026
84 of 85 checks passed
@trevor-e trevor-e deleted the trevorelkins/aiml-2954-backfill-seeragentrungroup_id branch June 12, 2026 20:55
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