Skip to content

feat(ops): Vercel Schedules backstop for time-sensitive workflows - #260

Open
NickAltstein wants to merge 2 commits into
mainfrom
feat/vercel-schedule-dispatch
Open

NickAltstein wants to merge 2 commits into
mainfrom
feat/vercel-schedule-dispatch

Conversation

@NickAltstein

@NickAltstein NickAltstein commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

GitHub's scheduled triggers drop and delay ticks, which shows up as staleness alarms. This adds Vercel Schedules as an outside trigger for the time-sensitive workflows. The GitHub crons stay as a second trigger.

What changed

Schedule (vercel.json) Cron (UTC) Dispatches
odds-freshness 7,22,37,52 * * * * odds_freshness.yml
game-context-rollover 0 6 * * 2 game_context_ingest.yml
game-context-daily 30 10 * * * game_context_ingest.yml
close-quality-capture 3,18,33,48 0-5,12-23 * * * close_quality_capture.yml
  • No public endpoint. api/schedules/dispatch.mjs has a schedule/v1beta trigger. The @vercel/schedules README says: "A function with the schedule/v1beta trigger is private: only the scheduler can invoke it, so there is no public endpoint to protect." That leaves no shared secret to check or rotate. A test fails if any schedule is switched to a public path target.
  • Failures page you. A missing token, a failed run lookup, a GitHub 401/403, or any non-2xx POSTs to ALARM_WEBHOOK_URL (the same {"content","text"} shape feed_age.py uses), then fails the run. So an expired token alerts on the next tick, not hours later through the freshness alarm. A broken webhook never hides the dispatch failure, and neither the token nor the webhook URL is ever logged or sent.
  • No double data PRs. Before dispatching, the function asks GitHub for runs of that workflow created since the slot's scheduled time, minus 2 minutes of clock slack. If one is queued, in progress or succeeded, it skips. Failed or cancelled runs don't count, so a failed GitHub run gets a fresh Vercel run. The window is anchored to the scheduled time, not delivery time, because Hobby can deliver up to 15 minutes late.
  • No replay after outages. Occurrences delivered more than 25 min late are skipped.
  • Token scope. Dispatch uses GITHUB_DISPATCH_TOKEN, a fine-grained PAT for this repo with Actions: Read and write only (read for the run lookup, write to dispatch), separate from DATA_BOT_TOKEN.
  • .vercelignore. It now ignores api/*.py and api/__pycache__/ instead of all of api/. .vercelignore doesn't honour ! re-includes; I confirmed with a local vercel build that the negated form dropped the function.

Before merging

  1. Create a fine-grained PAT: this repo only, Actions: Read and write, nothing else, with an expiry date. Set a calendar reminder before it expires.
  2. In Vercel → propstein → Settings → Environment Variables, Production only, add:
    • GITHUB_DISPATCH_TOKEN: the PAT
    • ALARM_WEBHOOK_URL: the same webhook the GitHub workflows use
  3. Merge. The static schedules go active in production when the deployment becomes current.
  4. Wait for the next 15-minute window, then check GitHub → Actions → Odds Feed Freshness for a run whose trigger is workflow_dispatch. Or force a run right away:
vercel schedules invoke odds-freshness

Dependencies

  • Adds @vercel/schedules@0.0.3, pinned exactly. It's in beta on all plans, and limits may change before GA.
  • It pulls 25 transitive packages, mostly @vercel/oidc's CLI helpers, all locked.
  • npm audit flagged GHSA-mrhx-c7xc-m3w5 (zod < 4.6.6, memory exhaustion) via @vercel/oidc → @vercel/cli-config. An overrides entry pins zod to 4.6.7 (same major). npm audit now reports 0 vulnerabilities. I kept this instead of npm audit fix, which would have downgraded @vercel/oidc from 3.8.10 to 3.5.0.
  • Not in the client bundle. In a local vercel build, the packages appear only in functions/api/schedules/dispatch.func; static/ has no node_modules and no reference to the SDK.

Reviewer notes

  • What dedupe can't prevent. A GitHub cron run that starts after the Vercel dispatch for the same slot. The workflow's concurrency group (cancel-in-progress: false) then runs the two back to back, and both open data PRs. Closing that gap needs a check inside the workflows or in open_automerge_data_pr.sh. That's left out to keep this PR scoped.
  • If Schedules stops. The existing freshness alarm fires, so it's monitored by the pipeline it feeds.
  • Hobby-safe cadence. No two runs are closer than 15 min, so close_quality_capture runs every 15 min here vs every 10 on GitHub.

Testing

  • npm test: 231 passed, 0 failed, 3 skipped (Chrome-only; these pass in CI). Includes 19 tests in test/schedule-dispatch.test.mjs: dispatch, webhook on every failure mode, slot dedupe, the lateness skip, and vercel.json / .vercelignore / workflow wiring.
  • pytest tests --ignore=tests/ledger: 735 passed, 3 skipped.
  • Local vercel build: one function, schedule/v1beta trigger, all four schedules in config.json, no Python files.

🤖 Generated with Claude Code

GitHub's scheduled triggers drop and delay ticks, which shows up as
staleness alarms. Vercel Schedules now calls a private function on the
same cadence, and it fires workflow_dispatch for odds_freshness,
game_context_ingest (Tuesday rollover and daily pre-pricing) and
close_quality_capture. The GitHub crons stay as the second trigger; each
workflow's concurrency group queues an overlapping run.

- api/schedules/dispatch.mjs has a schedule/v1beta trigger, so it has no
  public URL: only Vercel's scheduler can invoke it. No shared secret to
  check or rotate.
- Dispatch uses GITHUB_DISPATCH_TOKEN, a fine-grained PAT for this repo
  with Actions: write only, separate from DATA_BOT_TOKEN. A missing token
  or a GitHub rejection fails the run (500 in Vercel's execution history)
  instead of succeeding quietly; the token is never echoed.
- Occurrences delivered more than 25 minutes late (outage catch-up) are
  skipped rather than replayed.
- Cadences are Hobby-legal (no two runs closer than the 15-minute jitter);
  close_quality_capture runs every 15 minutes instead of its GitHub 10.
- .vercelignore now ignores api/*.py and api/__pycache__/ instead of all
  of api/. It does not honour "!" re-includes, so the old rule would have
  dropped the dispatch function.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
propstein Ignored Ignored Nov 24, 2026 7:05pm UTC

- Any dispatch failure (missing token, failed run lookup, GitHub 401/403,
  any non-2xx) now POSTs to ALARM_WEBHOOK_URL in the {"content","text"}
  shape feed_age.py uses, then fails the run. An expired token alerts at
  the next tick instead of hours later via the freshness alarm. A broken
  webhook never masks the dispatch failure, and neither the token nor the
  webhook URL is ever logged or sent.
- Before dispatching, the function asks GitHub for runs of the workflow
  created since the slot's scheduled time (less 2 minutes of clock slack)
  and skips if one is queued, in progress or succeeded. This stops the
  Vercel trigger from opening a second data PR for a slot the GitHub cron
  already covered. The window is anchored to scheduledAt, not delivery
  time, because Hobby delivers up to 15 minutes late. Failed or cancelled
  runs do not cover the slot.
- npm audit flagged GHSA-mrhx-c7xc-m3w5 (zod < 4.6.6) via @vercel/oidc ->
  @vercel/cli-config. An overrides entry pins zod to 4.6.7 (same major);
  npm audit now reports 0 vulnerabilities. None of the new packages are in
  the static site output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 24, 2026

Copy link
Copy Markdown

Deployment failed for project propstein with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/nicks-projects-ec56abd4?upgradeToPro=build-rate-limit

This branch has not been deployed

No deployments
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