feat(environments): daily environment builds (SUPER-3017)

Draft
SA
16d ago
+189-0

Milestone 2 of plans/20261030-0017-environment-builds.md (#9104). Stacked on #9110.

What it does

  • POST /api/environments/jobs/daily-builds, verified as a QStash request, runs queueDailyBuilds() under a Sentry cron monitor (environment-daily-builds).
  • For every environment that is not archived, it starts a daily build through the same startEnvironmentBuild the button and CLI use. It skips:
    • organizations on the free plan (checked once per organization);
    • environments whose last three finished builds all failed (plan decision D6). A successful manual build ends the pause;
    • anything startEnvironmentBuild refuses: no [install], already running, no repositories. Counted by reason.
  • No change check: an unchanged environment is built too (design doc, about $0.05 per environment per day).
  • Returns { queued, skipped: { reason: count }, failed }.

Needs doing by hand after merge: create the QStash schedule in the Upstash console, daily at 09:00 UTC (0 9 * * *, to match the Sentry monitor), POSTing to https://<api>/api/environments/jobs/daily-builds. Like reconcile-usage, the schedule is not in this repo.

Verified

  • Unit tests with injected dependencies: paid built and free skipped; paused after three failures; a refusal counted by reason without stopping the loop.
  • packages/trpc and apps/api typecheck; Biome clean.

Not verified: a real scheduled run. That needs the Upstash schedule, which only exists after merge.

Linear: SUPER-3017


Summary by cubic

Adds a QStash-scheduled job that starts a build of every environment that can have one — non-archived, on a paid plan, with [install], and not paused — including unchanged environments.

  • POST /api/environments/jobs/daily-builds verifies the QStash signature, then runs queueDailyBuilds() under a Sentry cron monitor.
  • The job skips free organizations (checked once per org), environments whose last three finished builds all failed — a successful manual build ends the pause — and anything startEnvironmentBuild refuses, counting each refusal by reason.
  • Returns { queued, skipped: { reason: count }, failed }.
  • After merge, create the QStash schedule in the Upstash console at 0 9 * * * posting to /api/environments/jobs/daily-builds; the schedule lives outside this repo, like reconcile-usage.