Skip to content

fix(traffic): connect auto-creates the traffic-sync schedule so a new source actually syncs#679

Merged
arberx merged 1 commit into
mainfrom
fix/vercel-connect-autoschedule
Jun 4, 2026
Merged

fix(traffic): connect auto-creates the traffic-sync schedule so a new source actually syncs#679
arberx merged 1 commit into
mainfrom
fix/vercel-connect-autoschedule

Conversation

@arberx

@arberx arberx commented Jun 4, 2026

Copy link
Copy Markdown
Member

Problem

A freshly connected Vercel traffic source seeds lastSyncedAt = NOW (#634), but traffic connect never creates the traffic-sync schedule that consumes it. With no schedule, the watermark never advances, so the next sync (dashboard- or manually-triggered) pulls an unbounded window and wedges — the other half of the first-sync trap #634 thought it closed. The source reads "connected" but ingests nothing, and recovery requires the operator to know about cnry schedule set --kind traffic-sync plus traffic reset --advance-to-now.

Fix

traffic connect now creates the project's traffic-sync schedule in the same transaction as the source upsert, and registers it with the live scheduler via onScheduleUpdated:

  • Cadence */30 * * * * (retunable via schedule set).
  • Idempotent: a reconnect, or a project that already has a traffic-sync schedule, is left untouched — aligns with the unique (project, kind) index.
  • Seeding lastSyncedAt = NOW keeps only the FIRST window tight; the schedule is what keeps the watermark from drifting on later triggers.

No API surface change (no new endpoint/field), so no SDK regen.

Tests

packages/api-routes/test/traffic.test.ts (api-routes project, 96 passing):

  • connect creates a traffic-sync schedule bound to the new source (*/30, enabled, UTC)
  • connect fires onScheduleUpdated('upsert', …, 'traffic-sync')
  • reconnect does not create or re-register a second schedule (idempotent)

typecheck + lint clean. Patch bump 4.69.2 → 4.69.3.

Follow-ups (not in this PR)

  • Defense in depth: cap the per-sync window so even a drifted watermark can't produce an unbounded pull (has a data-gap product implication; deserves its own review).
  • Symmetric cleanup: remove/disable the traffic-sync schedule when a source is disconnected/archived.

🤖 Generated with Claude Code

… source actually syncs

A freshly connected Vercel source seeded `lastSyncedAt = NOW` (#634) but
nothing advanced that watermark, because `traffic connect` never created the
traffic-sync schedule. An unscheduled source's watermark drifts, and the next
sync (dashboard- or manually-triggered) pulls an unbounded window that wedges:
the other half of the first-sync trap #634 thought it closed. Operators had to
know to run `cnry schedule set --kind traffic-sync` by hand, and a source that
looked "connected" silently ingested nothing.

Connect now creates the project's traffic-sync schedule (`*/30 * * * *`,
idempotent via the unique `(project, kind)` index) in the same transaction as
the source upsert, and registers it with the live scheduler via
`onScheduleUpdated`. Seeding `lastSyncedAt = NOW` only keeps the FIRST window
tight; the schedule is what keeps the watermark from drifting. Reconnects, and
projects that already have a traffic-sync schedule, are left untouched.

- Thread `onScheduleUpdated` into `TrafficRoutesOptions`, wired from `ApiRoutesOptions`.
- Tests: schedule created + bound to the source, `onScheduleUpdated` fired,
  idempotent on reconnect.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@arberx arberx merged commit e558a96 into main Jun 4, 2026
12 checks passed
@arberx arberx deleted the fix/vercel-connect-autoschedule branch June 4, 2026 01:18
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