Skip to content

Bug: deleting an organization leaves its automation schedule triggers enabled — the minutely scan then crashes in orgSlugFromId forever #3022

Closed

Description

@larryro

Problem

Deleting an organization cascades a lot — audit log, personalization hard-delete, the org's file/config directory, memberMirror (convex/organizations/delete_cleanup.ts, convex/auth.ts:531-547) — but automationTriggers rows are never disabled or deleted.

If a deleted org leaves behind a schedule trigger with enabled: true:

  • the minutely cron keeps firing it (convex/crons.ts:40-46 → scanScheduledTriggers, which scans by_kind_enabled — convex/automations/triggers.ts:79-110);
  • each run reaches the throwing slug resolver orgSlugFromId in convex/automations/agent_host.ts:638 → one uncaught OrgSlugUnresolvableError per scheduled occurrence, forever, plus the wasted runs.

Contrast: the crawler already handles this state gracefully — convex/knowledge/crawl_action.ts:377 resolves with orgSlugFromIdOrNull and skips deleted orgs.

Context

Split from the deleted-org incident #3019. That incident's org happened to have no schedule triggers (its noise cadence was human-shaped, not cron-shaped), so this gap is latent today — but it becomes real the first time anyone deletes an org that has scheduled automations, and unlike #3019 it needs no returning visitor: it self-sustains on every scheduled occurrence.

Suggested

  • In the deletion cascade (prepareOrganizationDeletion, convex/organizations/delete_cleanup.ts:20, or the /organization/delete middleware), disable or delete the org's automationTriggers.
  • Defense in depth: have the trigger scan / agent host resolve with orgSlugFromIdOrNull and auto-disable any trigger whose org no longer resolves, so a missed cascade can't error forever.
  • While there, audit the other org-scoped tables (e.g. websites) for orphan-row policy after org deletion.

Activity

  1. added
    priority: medium
    bug
    service: platform
    on Aug 20, 2026
  2. larryro commented on Sep 4, 2026

    @larryro
    ContributorAuthor

    Status after the 0.5 rewrite (main @ 1ea4cc9): the Convex-era fix in #3025 is obsolete and closed, but the gap itself is still open in the Postgres backend.

    • backend/domains/organizations/service.ts deleteOrganization cascades preferences, memories, session pointers, Better Auth rows and enqueues org.cleanup_files — it never touches app.automation_triggers / app.automations / app.automation_versions, and none of those tables has an FK to organization (see db/migrations/0019_automations.sql), so the rows survive.
    • backend/domains/automations/triggers.ts scanScheduledTriggers walks every enabled = true schedule and claims + beginRuns a due occurrence without checking that the org still exists; beginRunInTx only needs a deployed version, which the orphan still has.

    So a deleted org's schedules keep starting runs on every occurrence. Same fix shape as #3025 applies to 0.5: delete the org's automation rows inside deleteOrganization (same transaction), and have the scan disable a due trigger whose org no longer resolves. Needs an integration-check probe (backend/integration-check.ts).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority: mediumservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions