Skip to content

fix(platform): avoid duplicate OneDrive sync schedule on re-provision - #2509

Merged
larryro merged 1 commit into
mainfrom
fix/onedrive-sync-duplicate-schedule
Jul 6, 2026
Merged

larryro merged 1 commit into
mainfrom
fix/onedrive-sync-duplicate-schedule

Conversation

@larryro

@larryro larryro commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Problem

The OneDrive/SharePoint sync engine re-provisions its wfSchedules trigger on every sync-config upsert (each time a folder is added to sync). The provisioning guard was create-if-absent keyed on the exact cron string — the identity it matched on was (org, workflowSlug, cronExpression, projectId === undefined).

That means once an operator retunes the sync interval (e.g. to */2 * * * * via the trigger editor), the builtin's declared */15 * * * * no longer matches any existing row, so the next re-provision inserts a second schedule. Both rows stay isActive: true, so the automation ends up firing on two different intervals at once. The wfSchedules table has no unique constraint to catch it, and nothing reconciled the divergent row.

Fix

Key provisioning on the automation, not on the cron. The sync engine owns a single, retunable schedule, so:

  • If any org-level (project-less) schedule row for the slug already exists — active or paused, any cron — keep it and declare nothing new. The existing activate: true path still revives a paused one.
  • Only when there is no schedule row at all do we declare the builtin schedule to create the first one.
  • Completeness now means "the automation has an active schedule", not "the declared cron has a row".

The change is contained to onedrive/ensure_sync_workflow_provision.ts; the shared provisionDeclaredWorkflowTriggersImpl (used by two other provisioning paths that may legitimately declare multiple distinct crons) is untouched.

Behaviour

  • Repeated "Sync import" on the same folder → still exactly one schedule. ✓
  • Operator retunes interval to 2 min, then adds another sync folder → keeps the 2-min schedule, does not add a 15-min one. ✓ (was: duplicate)
  • Fresh install → creates the builtin schedule as before. ✓

Note: activate: true is preserved, so adding a sync folder re-activates a paused schedule (existing behaviour, consistent with "ensure the automation has a live schedule").

Tests

  • 3 existing provision tests still green (incl. reactivate-without-duplicate).
  • 2 new regression tests (both fail on the old code):
    • operator-retuned active */2 → asserts schedulesCreated: 0 and a single */2 row remains.
    • retuned + paused */2 → asserts it is revived (schedulesReactivated: 1), not duplicated.
  • @tale/platform typecheck + bun run lint clean; all 37 OneDrive tests pass.

The sync engine re-provisions its `wfSchedules` trigger on every
sync-config upsert. The guard was create-if-absent keyed on the exact
cron string, so once an operator retuned the interval (e.g. to */2 via
the trigger editor) the builtin's */15 no longer matched any row and a
second, concurrently-firing schedule was inserted.

Key provisioning on the automation instead of the cron: the sync engine
owns a single, retunable schedule, so if any org-level schedule row for
the slug already exists (active or paused, any cron) keep it and declare
nothing new — `activate: true` still revives a paused one. Completeness
now means "the automation has an active schedule", not "the declared
cron has a row".
@larryro
larryro merged commit ff92205 into main Jul 6, 2026
51 checks passed
@larryro
larryro deleted the fix/onedrive-sync-duplicate-schedule branch July 6, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant