Skip to content

feat(automations): Keep both Automation kinds in one table - #2179

Merged
dcramer merged 3 commits into
mainfrom
feat/automations-table
Oct 17, 2026
Merged

dcramer merged 3 commits into
mainfrom
feat/automations-table

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

This is PR 1 of 3 for #2176.

What changed

  • A new table, junior_automations, holds Scheduled automations and event automations. A kind column tells them apart.
  • Fields that queries filter or search on have their own columns. The other fields stay in the record JSON.
  • Automation versions now key on the Automation id and the version number. A foreign key connects each version to its Automation.
  • Migration 0055 copies all rows from junior_scheduler_tasks and junior_event_tasks into the new table. If one id is in both old tables, the migration stops.
  • All code now reads and writes only the new table. The old tables stay until PR 3.
  • The scheduler now repairs one stuck state. Sometimes a run finishes, but the save that moves the Automation to its next run does not happen. Before, the Automation then stayed on that run and did not run again.

Why

With two tables, a lookup by Automation id must check both tables. One table lets later code use direct joins.

During the deploy

Old workers can run while the new code starts.

  • An old worker saves edits to the old tables. These edits are lost.
  • An old worker that creates an Automation gets an error from the new foreign key. The user sees the error, so the Automation is not lost without notice.

Known risk

The migration does not stop for a malformed old row. If a row has no channel or no instruction, the copy gets an empty value. The code skips or rejects these rows, as it did before.

Next PRs

  • PR 2 adds the run rows and links each run to its Conversation.
  • PR 3 drops junior_scheduler_tasks, junior_event_tasks, and the kind column of junior_automation_versions.

via David Cramer.

--

View Junior Session [Sentry]

Add junior_automations with a kind column and copy Scheduled and event
automations into it. Versions now key on automation_id and version, with a
foreign key to the new table. All readers and writers use the new table.

The old tables stay for workers that run during the deploy. A later change
drops them.

Refs #2176

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

vercel Bot commented Oct 17, 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 17, 2026 1:28am UTC

Request Review

Inline the copied column values in each store and remove the shared helper.
Drop the cross-kind save guard and the exported kind and status types. Remove
backfill fallbacks that earlier migrations already applied. Shorten comments
and name what PR 3 removes.

Refs #2176

Co-Authored-By: David Cramer <[email protected]>
@sentry-junior sentry-junior Bot changed the title feat(automations): Store both Automation kinds in one table feat(automations): Keep both Automation kinds in one table Oct 17, 2026
@dcramer
dcramer marked this pull request as ready for review October 17, 2026 01:19
@github-actions github-actions Bot added the risk: high PR risk score: high label Oct 17, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 2 potential issues.

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 3922544. Configure here.

The old reader fell back to record.creatorIdentityId when the column was
null. Keep that fallback in the copy so those Scheduled automations stay
visible.

Refs #2176
@dcramer
dcramer merged commit 61da443 into main Oct 17, 2026
44 checks passed
@dcramer
dcramer deleted the feat/automations-table branch October 17, 2026 13:35
dcramer added a commit that referenced this pull request Oct 18, 2026
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.

<!-- 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 — 08c08aca Deployed Oct 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant