Skip to content

[AISAGE-758] feat(gateway): split direct BYOK provider sync into its own cron job - #8498

Merged
chrarnoldus merged 1 commit into
mainfrom
kilo/next-trail-fdb
Oct 22, 2026
Merged

chrarnoldus merged 1 commit into
mainfrom
kilo/next-trail-fdb

Conversation

@chrarnoldus

Copy link
Copy Markdown
Contributor

Summary

Direct BYOK model list syncing ran inside the /api/cron/sync-providers job, after the OpenRouter/Vercel catalog sync. A failure or slowdown in either part blocked or failed the other. This PR moves direct BYOK syncing into its own cron job.

  • syncAndStoreProviders no longer calls syncDirectByokModels.
  • New cron /api/cron/sync-direct-byok-providers runs every 5 minutes (maxDuration 120 s) and emits scheduled-job events as web.sync_direct_byok_providers.
  • Both jobs keep the stale-sync Slack alert. The alert module now takes a job id (providers or direct_byok). Each job has its own copy, its own Sentry and log names, and its own completion and alert-suppression timestamps.
  • Migration 0292 adds direct_byok_last_completed_at and direct_byok_stale_alert_last_posted_at to ai_gateway_sync_providers_state. The change only adds columns.
  • Admin /admin/sync-providers shows when the last direct BYOK sync completed. It adds a manual "Run direct BYOK sync" button (disabled in production, like the existing one) and a direct BYOK test-alert button. postTestStaleAlert now takes { job }.

Behavior notes

  • The direct BYOK stale timestamp starts empty. After deploy, the first direct BYOK cron run checks staleness before it syncs, so production can post one "never recorded" direct BYOK alert. That alert suppresses repeats until a sync completes or 3 days pass.
  • The main sync's completion timestamp no longer waits for direct BYOK, so a direct BYOK failure no longer delays the catalog sync or triggers a false catalog stale alert.

Verification

  • tsgo --noEmit for apps/web: passes
  • oxlint on the changed files: passes
  • jest for the cron route tests (both jobs), sync-providers-stale-alert.test.ts (including new DB-backed per-job persistence tests), sync-direct-byok.test.ts (including new completion-recording tests), sync-providers.test.ts, and the admin-router sync tests: all pass
  • @kilocode/db jest suite, which includes the schema and migration consistency tests: passes

@chrarnoldus chrarnoldus self-assigned this Oct 21, 2026
@kilo-code-bot

kilo-code-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Reviewed all 16 changed files and found no defects: the direct BYOK sync split, per-job sync-state persistence, cron route, admin triggers, and additive migration are internally consistent and preserve existing behavior. tsgo/test claims were cross-checked against the code and migration snapshot delta.

Assumptions: [INFERENCE] Runtime behavior on Vercel (120 s maxDuration for the new job) and the DB-backed jest suites were not executed in this read-only review; the 0292 snapshot was verified to differ from 0291 only by the two new nullable timestamp columns.

Files Reviewed (16 files)
  • apps/web/src/app/admin/sync-providers/SyncProvidersContent.tsx
  • apps/web/src/app/api/cron/sync-direct-byok-providers/route.ts
  • apps/web/src/app/api/cron/sync-direct-byok-providers/route.test.ts
  • apps/web/src/app/api/cron/sync-providers/route.ts
  • apps/web/src/app/api/cron/sync-providers/route.test.ts
  • apps/web/src/lib/providers/direct-byok/sync-direct-byok.ts
  • apps/web/src/lib/providers/direct-byok/sync-direct-byok.test.ts
  • apps/web/src/lib/providers/openrouter/sync-providers-stale-alert.ts
  • apps/web/src/lib/providers/openrouter/sync-providers-stale-alert.test.ts
  • apps/web/src/lib/providers/openrouter/sync-providers.ts
  • apps/web/src/routers/admin-router.ts
  • apps/web/src/routers/admin-router.test.ts
  • apps/web/vercel.json
  • packages/db/src/migrations/0292_direct_byok_sync_state.sql
  • packages/db/src/migrations/meta/0292_snapshot.json
  • packages/db/src/migrations/meta/_journal.json
  • packages/db/src/schema.ts
Review Notes
  • All postTestStaleAlert / alertIfSyncProvidersStale call sites were updated; no stale references remain.
  • postTestStaleAlert input change is admin-internal only (no MCP catalog or external consumer).
  • recordSyncCompleted reuses the existing row-locked, max-wins transaction, so concurrent provider and direct BYOK completions cannot clobber each other.
  • Migration is additive and nullable on a singleton table, and the snapshot/journal match the schema change.

Reviewed by deepseek-flash-latest · Input: 100.7K · Output: 19.9K · Cached: 1.8M

Review guidance: REVIEW.md from base branch main

@chrarnoldus chrarnoldus changed the title feat(gateway): split direct BYOK provider sync into its own cron job [AISAGE-758] feat(gateway): split direct BYOK provider sync into its own cron job Oct 22, 2026
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.

2 participants