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

Sentinel: queue:deploy was degraded 60 minutes today: The deploy queue has waited over 30 minutes: 2 queued, 0 running. #16987

Merged opened this

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

Merged

mason/forge:mason/16964-sentinel-queue-deploy-was-degraded-60-mi → main 0 commits fork

  • Merged. mason/16964-sentinel-queue-deploy-was-degraded-60-mi was merged into main as fc639f6.

Review

Sign in to review this change.
3 files changed +74 −2
src/apps/runtime.ts +5 −2
@@ -35,7 +35,7 @@ import { requeueAbandonedChecks } from "../checks/service.ts";
3535 import { listPulls } from "../core/pulls.ts";
3636 import { canEnterApp, getRepoById, type Repo } from "../core/repos.ts";
3737 import type { User } from "../core/users.ts";
38 import { cancelRun, failAbandonedRuns, STOPPED_SUMMARY } from "../core/runs.ts";
38 import { cancelQueuedDeploys, cancelRun, failAbandonedRuns, STOPPED_SUMMARY } from "../core/runs.ts";
3939 import { Gate } from "../git/env.ts";
4040 import { resolveOid } from "../git/merge.ts";
4141 import { exactRefOid } from "../git/branches.ts";
@@ -227,7 +227,10 @@ export class AppsRuntime {
227227 // Deploys are failed; a check the last forge left is queued again while
228228 // its commit still heads an open pull; an agent run is the crew's,
229229 // which queues it again rather than failing it.
230 const deploys = failAbandonedRuns(this.app.db, STALE_AFTER_MS, ["deploy"]);
230 // A deploy still queued waited on the last forge's chain, which is gone: cancelled as its
231 // stop would have, and the reconcile below asks again for what each environment runs (#16964).
232 const deploys =
233 failAbandonedRuns(this.app.db, STALE_AFTER_MS, ["deploy"]) + cancelQueuedDeploys(this.app.db);
231234 const cut = requeueAbandonedChecks(this.app, STALE_AFTER_MS);
232235 if (deploys + cut > 0) log.info("settled abandoned runs", { count: deploys + cut });
233236 // After an unclean stop: one line says how many checks were cut and queued again (#12594).
src/core/runs.ts +15
@@ -499,6 +499,21 @@ export function cancelRunsForPull(
499499 return out;
500500 }
501501
502 /**
503 * Every queued deploy, cancelled as a clean stop would have (`STOPPED_SUMMARY`): a deploy waits
504 * on the in-memory chain of the forge that queued it, so one a forge left queued (killed, not
505 * stopped) has no process to claim it and would hold the deploy queue for ever (#16964). Called
506 * at boot, before the boot asks for what each environment should run. Answers how many.
507 */
508 export function cancelQueuedDeploys(db: Database): number {
509 const ids = db
510 .query<{ id: string }, []>(
511 "SELECT id FROM run INDEXED BY run_queued WHERE kind = 'deploy' AND state = 'queued' ORDER BY id",
512 )
513 .all();
514 return ids.filter(({ id }) => cancelRun(db, id, STOPPED_SUMMARY) !== undefined).length;
515 }
516
502517 /** Record spend and the session as a run goes, so a cut-off run still reports it. */
503518 export function noteRunProgress(
504519 db: Database,
test/deploy-orphan-boot.test.ts added +54
@@ -0,0 +1,54 @@
1 /**
2 * A deploy left queued by a forge that was killed, not stopped, is settled at the next boot
3 * (#16964): it waited on the dead forge's in-memory chain, so nothing would ever claim it, and
4 * it held `queue:deploy` degraded until someone cleared it by hand. A queued check is the
5 * checks service's own and stays queued.
6 */
7 import { afterAll, beforeAll, expect, test } from "bun:test";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { createApp, type App } from "../src/app.ts";
12 import { createRepo } from "../src/actions/repos.ts";
13 import { AppsRuntime } from "../src/apps/runtime.ts";
14 import type { Repo } from "../src/core/repos.ts";
15 import { createRun, getRun, queueDepth, STOPPED_SUMMARY } from "../src/core/runs.ts";
16 import { promote } from "./helpers/members.ts";
17 import { signUpProven as signUp } from "./helpers/verified.ts";
18
19 let dataDir: string;
20 let app: App;
21 let repo: Repo;
22
23 beforeAll(async () => {
24 dataDir = await mkdtemp(join(tmpdir(), "forge-deploy-orphan-"));
25 app = createApp({ dataDir, port: 0 });
26 const made = await signUp(app, { username: "alice", email: "[email protected]", password: "a-long-passphrase" });
27 if (!made.ok) throw new Error("sign-up");
28 promote(app.db, made.value);
29 const r = await createRepo(app, made.value, { owner: "alice", name: "site", visibility: "public" });
30 if (!r.ok) throw new Error(String(r.error));
31 repo = r.value;
32 }, 30_000);
33 afterAll(async () => {
34 app.close();
35 await rm(dataDir, { recursive: true, force: true });
36 });
37
38 test("the boot cancels a deploy the last forge left queued, and leaves a queued check", async () => {
39 const oid = "a".repeat(40);
40 const orphan = createRun(app.db, { repoId: repo.id, kind: "deploy", env: "production", commitOid: oid, reason: "merge" });
41 const check = createRun(app.db, { repoId: repo.id, kind: "check", env: "", commitOid: oid, reason: "push" });
42 expect(queueDepth(app.db).find((q) => q.kind === "deploy")?.queued).toBe(1);
43
44 const runtime = new AppsRuntime(app, { domain: "apps.test", scheme: "http", forgeUrl: "http://forge.test" });
45 await runtime.start();
46 await runtime.stop();
47
48 const settled = getRun(app.db, orphan.id)!;
49 expect(settled.state).toBe("cancelled");
50 expect(settled.summary).toBe(STOPPED_SUMMARY);
51 expect(settled.finishedAt).not.toBeNull();
52 expect(getRun(app.db, check.id)!.state).toBe("queued");
53 expect(queueDepth(app.db).find((q) => q.kind === "deploy")).toBeUndefined();
54 }, 30_000);

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

Keyboard shortcuts

Docs