Public: anyone can read this; the crew can change it.

Production deploys stop interrupting people: batched (one per 15 min), not while busy, and swapped with zero downtime #16867

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

Production deploys are now batched to one per 15 minutes and wait while the app is busy. This covers checks 1 and 2 of the sharpened scope. It does not cover the issue's wider list (items 3–8, listed below).

Notes

opened this

Production deploys are now batched to one per 15 minutes and wait while the app is busy. This covers checks 1 and 2 of the sharpened scope. It does not cover the issue's wider list (items 3–8, listed below).

The new unit tests, apps-api (12 tests, run last, after the default moved to main.ts) and the manifest tests pass. The earlier run of five app suites had 3 failures. I cleared apps-api's "write-only values" test by moving the default to main.ts. I did not re-run apps-busy, apps-adversarial, apps-archive-race or apps-build-preview afterwards. I did not look into the migration-14 failure, so I can't say whether it is related. I did not run the full suite, and I haven't measured arm deploys per hour before and after.

What changed

  • A push or merge to the default branch no longer restarts production immediately. It waits until app.deploy.every minutes (default 15) after the running version began serving.
  • A newer landing replaces the waiting one, so ten landings in five minutes make one deploy of the newest commit.
  • Previews, restarts, out-of-memory restarts, boot and redeploys someone asked for are never held.
  • The hold also waits while the app is busy: a stream open through the proxy, a child still working, or the app's own app.deploy.busy path answering 409.
  • After app.deploy.maxWait minutes (default 10) of busy, it deploys anyway and the run log says so. The log also says when a deploy is held and when it is waiting for a safe moment.
  • forge.json accepts app.deploy with every, maxWait (minutes) and busy (a path). Invalid values are rejected.
  • FORGE_DEPLOY_EVERY_MIN and FORGE_DEPLOY_MAX_WAIT_MIN set the forge-wide defaults in src/main.ts. The runtime itself defaults to no batching, so existing tests that push to production twice still pass.
  • The policy is read from the running version's manifest, so a change to app.deploy takes effect from the deploy after it lands.
  • The logic is in the new src/apps/deploy_hold.ts, wired into requestDeploy's chain in src/apps/runtime_events.ts. It reuses busyReason from src/apps/busy.ts. The pace is documented in docs/APPS.md.
  • Tests are in test/deploy-hold.test.ts. They use a fake clock and cover:
    • ten landings in five minutes giving one deploy;
    • a busy app waiting until idle;
    • a busy app deploying anyway at maxWait;
    • a replaced run dropping out;
    • which deploy reasons are held;
    • parsing of the manifest fields;
    • the 409 probe.

Left out

  • Zero-downtime swap: I didn't check whether it already holds.
  • Rolls handing apps over without a cold restart, and the git-serving fix during a roll.
  • The "next deploy at HH:MM, N waiting" line and "deploy now" button on the app page.
  • The reconnecting client helper, the per-app state directory, and arm#202 as the reference.
  • Counting runs of production deploys per hour before and after.
  • No integration test with a real server and a real push. A held deploy with no page, TUI or API door added is the only change visible from outside, and it is in the run log.

Try it Add "deploy": {"every": 1, "maxWait": 1, "busy": "/busy"} under app in forge.json. Push twice to main within a minute. Production shows one deploy after the window, and the run log says "held for the next production deploy at HH:MMZ".

Closes #3967

8 earlier comments
commented

Production deploys are now batched to one per 15 minutes and wait while the app is busy. This covers checks 1 and 2 of the sharpened scope. It does not cover the issue's wider list (items 3–8, listed below).

The new unit tests, apps-api (12 tests, run last, after the default moved to main.ts) and the manifest tests pass. The earlier run of five app suites had 3 failures. I cleared apps-api's "write-only values" test by moving the default to main.ts. I did not re-run apps-busy, apps-adversarial, apps-archive-race or apps-build-preview afterwards. I did not look into the migration-14 failure, so I can't say whether it is related. I did not run the full suite, and I haven't measured arm deploys per hour before and after.

What changed

  • A push or merge to the default branch no longer restarts production immediately. It waits until app.deploy.every minutes (default 15) after the running version began serving.
  • A newer landing replaces the waiting one, so ten landings in five minutes make one deploy of the newest commit.
  • Previews, restarts, out-of-memory restarts, boot and redeploys someone asked for are never held.
  • The hold also waits while the app is busy: a stream open through the proxy, a child still working, or the app's own app.deploy.busy path answering 409.
  • After app.deploy.maxWait minutes (default 10) of busy, it deploys anyway and the run log says so. The log also says when a deploy is held and when it is waiting for a safe moment.
  • forge.json accepts app.deploy with every, maxWait (minutes) and busy (a path). Invalid values are rejected.
  • FORGE_DEPLOY_EVERY_MIN and FORGE_DEPLOY_MAX_WAIT_MIN set the forge-wide defaults in src/main.ts. The runtime itself defaults to no batching, so existing tests that push to production twice still pass.
  • The policy is read from the running version's manifest, so a change to app.deploy takes effect from the deploy after it lands.
  • The logic is in the new src/apps/deploy_hold.ts, wired into requestDeploy's chain in src/apps/runtime_events.ts. It reuses busyReason from src/apps/busy.ts. The pace is documented in docs/APPS.md.
  • Tests are in test/deploy-hold.test.ts. They use a fake clock and cover:
    • ten landings in five minutes giving one deploy;
    • a busy app waiting until idle;
    • a busy app deploying anyway at maxWait;
    • a replaced run dropping out;
    • which deploy reasons are held;
    • parsing of the manifest fields;
    • the 409 probe.

Left out

  • Zero-downtime swap: I didn't check whether it already holds.
  • Rolls handing apps over without a cold restart, and the git-serving fix during a roll.
  • The "next deploy at HH:MM, N waiting" line and "deploy now" button on the app page.
  • The reconnecting client helper, the per-app state directory, and arm#202 as the reference.
  • Counting runs of production deploys per hour before and after.
  • No integration test with a real server and a real push. A held deploy with no page, TUI or API door added is the only change visible from outside, and it is in the run log.

Try it Add "deploy": {"every": 1, "maxWait": 1, "busy": "/busy"} under app in forge.json. Push twice to main within a minute. Production shows one deploy after the window, and the run log says "held for the next production deploy at HH:MMZ".

commented

One more effect to cover here: main's full check that started 18:59Z was cancelled at 19:50Z after ~51m with "interrupted by a release; queued again", so main got no verdict for another hour. With releases every few minutes, main's full check may never finish. When you batch production deploys, make sure a release does not cancel a main full check already running (let it finish, or release only between main verdicts), and add a test for that.

commented

A release no longer cuts off main's full check that is already running. Before the forge swaps itself in, it now waits until no full check of the default branch is running. The new tests and the existing release-deploy and deploy-hold tests pass. tsc --noEmit was clean. gate.ts --fix rewrapped comments in one file, which is in the commit. The plain gate.ts run flagged the new test fixture as resembling test/ledger-health.test.ts#admin. I didn't change it.

Production app deploys were already batched to one per 15 minutes and wait for a safe moment. The interruptions behind the 18:59Z main check came from forge self-releases, which abort running checks and requeue them. This change is on that path.

  • The wait: src/release/main_check_idle.ts is new. mainCheckRunning looks for a running full check of the default branch. Pull fast-tier checks, issue-linked checks and other branches don't count. untilMainIdle polls for it to finish.
  • Where it applies: deployWhenChecked in src/checks/landing.ts runs the wait after the commit's own check goes green and before swap. It is an optional idle dependency, so existing callers behave as before when nothing is running. Re-arming after a restart goes through the same path.
  • Tests: test/release-waits-for-main-check.test.ts covers which runs count, a release that waits and swaps only after the check finishes, the bounded wait, and an immediate swap when idle.
  • Bounded wait: The wait is capped at 2 hours, after which the release goes ahead. I chose that so a hung check can't block every release. The catch is that a main check running past 2 hours can still be cut off.
  • Back-to-back checks: If main's checks run back to back with no gap, releases wait until the cap.
  • Release latency: Releases can now land later, behind main's checks. Since deploys wait for a green check of the commit, a push usually releases right after its own check finishes.
  • Not done: I didn't add a way to set the cap, and no docs changed. This is forge-internal timing, so I used "No door" in the commit.
commented

Both failures came from my change and are fixed in the new commit, which is pushed. The tests below pass, but I haven't re-run the full check.

  • Timer rule: my two new timers, the deploy-hold sleep in src/apps/runtime_events.ts and the main-check wait in src/release/main_check_idle.ts, were bare setTimeouts. They are now wrapped in during(...) and .unref()'d, the same way src/actions/pinned_watch.ts does it. test/timers-named.test.ts passes.
  • App tokens test (the 90-second hang): this test pushes a commit while a page stream is open on purpose. The new "wait for a safe moment" hold, which waits up to 10 minutes while a stream is open, was making the deploy wait. I set deployMaxWaitMs: 0 on that test's runtime, so it deploys at once as before. The test was wrong only in not knowing about the hold. test/apps-token.test.ts now passes (9 tests).
  • Other tests: apps-api, apps-busy, probe and apps-adversarial pass when run one at a time. apps-api had 4 failures when I ran it together with apps-busy, probe and apps-adversarial in one command, and 0 failures alone. I didn't find out why.
  • Still open: gate.ts still flags the fixture in my new test file as resembling test/ledger-health.test.ts#admin. I left it, since the two fixtures set up different things.

The forge's full check ran only the rule and scan tests before stopping, so about 955 behaviour test files were not run. Other tests that push to production with a stream open could hit the same hold, and I only checked the ones above.

commented

The check failed because two timers I added earlier, deploy-hold and release-main-idle, weren't listed in test/job-slices.test.ts. That test requires every job run under during to be timed or named in UNTIMED with a reason. I added both to UNTIMED, each with its reason: it's a one-shot sleep timer that does no work of its own. Nothing under src/ changed.

test/job-slices.test.ts now passes (3 pass, 0 fail), and the fix is pushed. I did not run tsc or the rest of the suite, so the forge's full check is the first run of everything else.

bun scripts/gate.ts --fix printed a similarity warning: fixture in test/release-waits-for-main-check.test.ts is 0.65 like admin in test/ledger-health.test.ts. It didn't block the push and I left it alone.

commented

The check fails the UNTIMED-jobs rule (test/job-slices.test.ts): this pull adds during("deploy-hold", done) and during("release-main-idle", done) around sleeps. Each needs an UNTIMED entry in test/job-slices.test.ts with its reason (e.g. "a sleep; its caller's work is the caller's"). Plain main passes this test.

commented

The UNTIMED entries trevato asked for were already on the branch, pushed in 89c7f2c94. deploy-hold and release-main-idle are each named in test/job-slices.test.ts with a one-sentence reason, and that test passes.

I checked the other items on the list against this pull's changes only (the diff from where the branch left main):

  • as never: none of this pull's changes adds one. The one hit in the raw diff against current main comes from main moving on, not from this branch.
  • Dead code: test/unused-exports.test.ts, which holds the "every export under src/ has a caller, or is allowed" test, passes.
  • Type check: bun x tsc --noEmit is clean.
  • Screen share/budgets test: I didn't find or run a test by that name. This pull doesn't touch that screen.
  • Direction line: this pull has no Direction: commit line, and I'm not sure what it should name. The branch name carries issue #3967, and the existing commits mention it. If you want a commit line in that form, say which issue it should cite.

Nothing new to push. The only warning left is the gate's similarity note between two test helpers, fixture in test/release-waits-for-main-check.test.ts and admin in test/ledger-health.test.ts. It doesn't block the push.

commented

Pushed to scout/3967-production-deploys-stop-interrupting-peo (90ec94380), with two items deliberately left open: the zero-downtime claim and the app page. The title, "swapped with zero downtime", should be narrowed, because this pull paces and holds production deploys and does not change the swap.

On the whole branch, tsc is clean and gate --fix reports no rule refusal (it still prints three similar-helper warnings). I ran the tests this pull touches (deploy-hold, deploy-hold-runtime, release-waits-for-main-check, job-slices, unused-exports), and they pass. The check on the push is the first run of everything else.

One run of the new runtime test failed under load: the held deploy ended failed while other test and tsc runs were going in the background. I couldn't tell why, because the run log wasn't captured. The test now prints the run's log on failure, and it passed on four runs on a quiet machine.

What changed, against the review's eight points

  1. Scope: The swap itself (new process serves before the old one stops, in-flight requests answered, websockets told to reconnect with 1012) already existed in apps/handoff.ts (#4496), and this pull doesn't change it. docs/APPS.md now says what it does and does not claim, and "zero downtime" is no longer claimed. I did not build the app page's "next deploy at HH:MM, N waiting" line, the "deploy now" button, or the git-serving fix during a roll. Each is its own piece of work, so please file them as linked issues or tell me to.
  2. Runtime wiring test: test/deploy-hold-runtime.test.ts uses the real runtime with deployEveryMs 1.5 s and deployPollMs 20 ms. It checks that:
    • a redeploy goes ahead under an open stream;
    • a push waits ("waiting for a safe moment" in the log, from the open-stream busy check) until the stream closes;
    • a newer landing replaces the held one, whose run is cancelled "superseded" and never deployed;
    • after the stream closes, the newest serves.
  3. holdDeploy unit test: the "ten landings" test now runs ten concurrent holds on a virtual clock, each landing superseding the last. Exactly one run goes ahead, the newest, no earlier than 15 minutes. It would fail if batching were broken.
  4. src/main.ts: the deploy-hold import now sits below ./kernel/bun_guard.ts.
  5. src/checks/landing.ts: the realDeps.idle! assertion is gone. The default is defined once as mainIdle.
  6. 2 h main-check wait: I documented it in docs/APPS.md, including that a check running back to back can still be cut off after two hours. I did not make the check resume across a swap, since that is a larger change. I'd file it separately.
  7. Duplicated fixture: it now uses the shared seedAdmin from test/helpers/admin.ts. The gate still warns about it and two other helpers (until, land), but did not refuse the push.
  8. FORGE_DEPLOY_EVERY_MIN: it now accepts 0 (no batching) through a small minutes() parser. Unreadable values fall back to the default.

I added no Direction: line to any commit, because I don't know which issue it should name. The as never and dead-code points are covered: none of this pull's changes adds an as never, and unused-exports passes.

commented

Production deploys now wait for open streams to close, and the check's 2 s budget failure on the deploy-hold test is fixed. I pushed the fix; the check hasn't run on it yet.

  • Cause: test/deploy-hold-runtime.test.ts used a 1.5 s batch window, so the "a push waits for the open stream, and a newer landing replaces the held one" test could not finish in under 2 s.
  • Fix: I cut deployEveryMs from 1500 to 300. The test still lands two pushes, holds the newest under an open stream, cancels the older one as superseded, and serves v3 after the stream closes. The file passes locally (2 tests).
  • Not fixed: two import-cost tests (src/web/client.ts and src/web/asset.ts import without the data graph) failed in shard 56. This change doesn't touch them. They pass alone (test/web-import-cost.test.ts, 6 pass), so I'm treating them as timing flakes under shard load. If they fail again on the next check, that needs its own look.
  • Gate output: bun scripts/gate.ts --fix changed nothing. It printed notes that until and land in this test resemble helpers in other test files; I left them as they are.
Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs