Skip to content

fix(automations): Settle runs of deleted Scheduled automations - #2185

Merged
dcramer merged 1 commit into
mainfrom
fix/automation-cleanup
Oct 18, 2026
Merged

dcramer merged 1 commit into
mainfrom
fix/automation-cleanup

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up cleanup after the Automation table migrations (#2179, #2183, #2184).

Bug

The heartbeat settled Scheduled automation runs only for automations that were not deleted. It did this through listIncompleteScheduledRuns → listScheduledAutomations, which filters status <> 'deleted'. Delete marks only pending runs as skipped. So when an automation was deleted while its run was dispatched, the run stayed running forever and never became an execution. Event runs already settle in this case.

listIncompleteScheduledRuns now reads junior_automation_runs joined to kind = 'scheduled', with no status filter. One function now covers both the heartbeat and the per-automation claim check. This also stops the heartbeat from loading and decoding every Scheduled automation on each tick. The new heartbeat integration case fails on main (the run stays running) and passes with this change.

Dead code

  • scheduled-automations/personal.ts: removed listViewerScheduledAutomations and its cursor code. collection.ts replaced it, and it had no callers.
  • Removed scheduledAutomationPrincipalLabel and ScheduledAutomationCredentialMode, which had no callers.
  • Removed the scheduled-automations/index.ts and tools.ts barrels. Their two consumers now import the tool files directly, as AGENTS.md asks.
  • Removed the "adopts deployed Scheduler rows" component test. It builds the dropped legacy tables to test migration SQL, which the testing policy rules out.
  • Removed the kind tie-breaker from the Automation collection order. Ids are unique in one table, so it never decided anything.
  • Removed README notes about older workers during rolling deploys.

Not in this PR

These change behavior or contracts, so they need their own PRs:

  • executionActor is written and never read. The schema is .strict() and stored rows contain the field, so removing it needs a data migration first.
  • Ownership uses two rules: creator_identity_id for scheduled rows, team_id + creator_slack_user_id for event rows.
  • Remove kind from /api/automations/:kind/:id and the dashboard /automations/:kind/:id/... URLs. Both already have it today; ids are unique, so the routes can key on id alone.
  • Two locking schemes: an advisory lock for scheduled rows, FOR UPDATE for event rows.
  • Run writes are split across execution-stats.ts and the two runs.ts files. recordAutomationExecution also swallows write errors.
  • Migration 0058, which drops junior_automation_versions.kind and junior_conversations.origin_*.

Checks

  • pnpm typecheck passed.
  • pnpm lint passed. It includes the file-length, migration-metadata and test-architecture checks.
  • vitest: heartbeat, scheduled-automations-sql, api/automations and api/automation-edits all pass.
  • slack-schedule-tools and event-automations: everything passes with --testTimeout=30000, except "delivers the current automation card and retains its reference in web history". That test fails the same way on main in my sandbox. At the default 5s timeout, unrelated tests in these files time out in my sandbox on main too.

via David Cramer.

--

View Junior Session [Sentry]

The heartbeat listed incomplete runs only for Scheduled automations that
were not deleted. A run that was dispatched before its automation was
deleted stayed running forever and never became an execution. List the
runs from junior_automation_runs instead, joined to scheduled rows with
no status filter. This also stops the heartbeat from loading every
Scheduled automation on each tick.

Also remove code that the single Automation table left unused:

- listViewerScheduledAutomations and its cursor code
- scheduledAutomationPrincipalLabel and ScheduledAutomationCredentialMode
- the scheduled-automations index.ts and tools.ts barrels
- the legacy Scheduler table adoption test, which tests migration SQL
- the kind tie-breaker in the Automation collection order
- README rollout notes about older workers

Co-Authored-By: David Cramer <[email protected]>
@vercel

vercel Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Oct 18, 2026 9:01am UTC

Request Review

@dcramer
dcramer merged commit d6b2ea1 into main Oct 18, 2026
45 checks passed
@dcramer
dcramer deleted the fix/automation-cleanup branch October 18, 2026 09:08
dcramer added a commit that referenced this pull request Oct 18, 2026
Follow-up to #2185. Automation IDs are unique in `junior_automations`,
so the API and dashboard URLs do not need `kind`. The server now reads
the kind from the stored row.

**URL changes (hard cutover, old URLs return 404):**
- API:
`/api/automations/:kind/:id{,/edit,/executions,/versions,/versions/:version/activate,/lifecycle}`
→ `/api/automations/:id/...`. `PATCH` and `DELETE` use
`/api/automations/:id`.
- API preview: `/api/automations/scheduled/:id/preview` →
`/api/automations/:id/preview`.
- Dashboard:
`/automations/:kind/:automationId/{executions,versions,edit}` →
`/automations/:automationId/...`.

**Server:**
- `resolveViewerTaskCandidate(user, id)` reads the row once and parses
it by its stored kind. `readViewerAutomationSummary` no longer tries
scheduled and then event.
- The edit, lifecycle, version, execution and delete helpers take an ID
only. Access rules do not change: owners or public Destination readers
can read and edit, and only creators can pause, resume or delete.
- `PATCH` still rejects a body `kind` that differs from the stored kind
(400 on `kind`).
- Preview on an event Automation now returns a 400 edit error. Before,
it returned 404.

**Not in this PR:** the two ownership rules, the two lock schemes, the
different handling of invalid rows, and the run-write split. Each of
these changes behavior, so each needs its own PR.

**Checks:** `pnpm typecheck` and `pnpm lint` pass. The automation API,
automation edit, conversation detail and Slack automation-details tests
pass, and so does the dashboard vitest suite (334 tests). I updated the
dashboard E2E fixtures, but I could not run them locally because the
sandbox has no Chrome. CI must run them.

<!-- junior-request-attribution:start -->
via **David Cramer**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0B595QDZLL%3A1792312176.174969 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0B595QDZLL%3A1792312176.174969)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0B595QDZLL%3A1792312176.174969/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — bc85bce0 Deployed Oct 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant