Public: anyone can read this; the crew can change it.
The home's lanes and figures never wait on a 44 s statement, and three things… #16513
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16189-the-home-s-lanes-and-figures-never-wait → main 0 commits fork 1 thread · 1 unresolved
7 files
changed +28
−51
docs/features/runners.md +4 −5
| @@ -34,11 +34,10 @@ started by hand are in addition: an admin removes them with | ||
| 34 | 34 | `DELETE /api/v1/admin/runners/<id>`. Every `local-*` row created by `forge` is |
| 35 | 35 | deleted at each boot, so never name a hand-made runner `local-N`. |
| 36 | 36 | |
| 37 | `checks.concurrency` counts the forge's own cells; under the runner placement | |
| 38 | each runner seen in the last minute adds the jobs it runs at once | |
| 39 | (`FORGE_RUNNER_JOBS`, which every claim tells the forge), up to the setting's | |
| 40 | ceiling of 16. One that stops asking stops counting a minute later, with no | |
| 41 | restart (#15253). | |
| 37 | `checks.concurrency` is the most checks running at once, whoever runs them: the forge's own | |
| 38 | cells or any number of runners. Runners only decide where a check runs, never how many | |
| 39 | (#16189). What a runner says it runs at once (`FORGE_RUNNER_JOBS`, told in every claim) is | |
| 40 | shown beside it in Settings → Runners and the terminal, and limits nothing. | |
| 42 | 41 | |
| 43 | 42 | Settings → Runners (`/settings/runners`) and the terminal's **Runners** list the same rows, with |
| 44 | 43 | a remove for a hand-made one: [](settings-runners.md). |
src/checks/lane_state.ts +5 −9
| @@ -8,7 +8,6 @@ import { Gate } from "../git/env.ts"; | ||
| 8 | 8 | import { runStep } from "../apps/process.ts"; |
| 9 | 9 | import type { DeepsecDeps } from "./deepsec_step.ts"; |
| 10 | 10 | import { CAPACITY, capacityCount } from "../core/capacity.ts"; |
| 11 | import { liveRunnerJobs } from "./runner_jobs.ts"; | |
| 12 | 11 | import type { Placement } from "./placement.ts"; |
| 13 | 12 | import type { PodRoom } from "./pod_room.ts"; |
| 14 | 13 | import type { GateStage } from "./gate_reason.ts"; |
| @@ -224,13 +223,10 @@ export const CHECKS_CEILING = ((kind) => (kind.type === "count" ? kind.max : 16) | ||
| 224 | 223 | |
| 225 | 224 | /** |
| 226 | 225 | * How many checks may run at once, read on every pick (`core/capacity.ts`): an admin's change is |
| 227 | * honoured by the next check, not the next boot. `concurrency` is the boot default. Under the | |
| 228 | * runner placement the jobs of every live runner add to it (`liveRunnerJobs`), so one that | |
| 229 | * connects raises it at the next tick and one gone quiet drops out once `SEEN_FRESH_MS` passes; | |
| 230 | * never above `CHECKS_CEILING`, so a crowd of runners cannot overload this machine's lane. | |
| 226 | * honoured by the next check, not the next boot. `concurrency` is the boot default. The setting is | |
| 227 | * the most checks at once, whoever runs them: live runners only decide where a check runs, never | |
| 228 | * how many (#16189; adding their jobs ran 16 at once where the setting said 6). | |
| 231 | 229 | */ |
| 232 | export function capacity(lane: LaneState, now: number = Date.now()): number { | |
| 233 | const setting = capacityCount(lane.app.db, "checks.concurrency", lane.options.concurrency ?? 1); | |
| 234 | const runners = lane.placement.mode === "runner" ? liveRunnerJobs(lane.app.db, now) : 0; | |
| 235 | return Math.min(CHECKS_CEILING, setting + runners); | |
| 230 | export function capacity(lane: LaneState): number { | |
| 231 | return Math.min(CHECKS_CEILING, capacityCount(lane.app.db, "checks.concurrency", lane.options.concurrency ?? 1)); | |
| 236 | 232 | } |
src/checks/runner_jobs.ts −12
| @@ -222,18 +222,6 @@ export function noteRunnerJobs(db: Database, runnerId: string, said: unknown): v | ||
| 222 | 222 | db.query("UPDATE check_runner SET jobs = ?2 WHERE id = ?1 AND jobs != ?2").run(runnerId, said); |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | /** | |
| 226 | * The jobs the live runners run at once: the sum of each one's count over those seen within | |
| 227 | * `SEEN_FRESH_MS`. One not seen since stops counting on the next read, with no restart. | |
| 228 | */ | |
| 229 | export function liveRunnerJobs(db: Database, now: number): number { | |
| 230 | return ( | |
| 231 | db | |
| 232 | .query<{ n: number | null }, [number]>("SELECT SUM(jobs) AS n FROM check_runner WHERE seen_at > ?1") | |
| 233 | .get(now - SEEN_FRESH_MS)?.n ?? 0 | |
| 234 | ); | |
| 235 | } | |
| 236 | ||
| 237 | 225 | /** |
| 238 | 226 | * Put a check's steps on the desk. `dir` is the bare repository the commit is in; it stays here. |
| 239 | 227 | */ |
src/core/capacity.ts +1 −1
| @@ -74,7 +74,7 @@ export const CAPACITY: Record<CapacityKey, Definition> = { | ||
| 74 | 74 | fallback: "1", |
| 75 | 75 | sized: (cpus) => checksForCpus(cpus - servingCoresForCpus(cpus), shardsForCpus(cpus)), |
| 76 | 76 | reason: "A check runs a whole test suite; more at once starve the web process of CPU.", |
| 77 | help: "How many repository checks run at once on this forge's own cells; each runner seen in the last minute adds the jobs it runs at once, up to 16 in all. Lowering it lets running ones finish; the next one waits. Empty: the pod's CPUs less the ones kept for the forge itself (cells.servingCores' default), over three per shard (shards × 3), from 1 to 16 — 80 CPUs keep 4 and give 76 / 12 = 6.", | |
| 77 | help: "The most repository checks running at once, whoever runs them: runners decide where a check runs, never how many. Lowering it lets running ones finish; the next one waits. Empty: the pod's CPUs less the ones kept for the forge itself (cells.servingCores' default), over three per shard (shards × 3), from 1 to 16 — 80 CPUs keep 4 and give 76 / 12 = 6.", | |
| 78 | 78 | }, |
| 79 | 79 | "checks.shards": { |
| 80 | 80 | label: "Test shards per check", |
src/flow/ship_time.ts +1 −1
| @@ -136,7 +136,7 @@ function shipped(db: Database, since: string, to: string): { issue: Closed; ship | ||
| 136 | 136 | const issues = db |
| 137 | 137 | .query<Closed, [string, string]>( |
| 138 | 138 | `SELECT i.id, i.repo_id, i.number, i.title, i.closed_at, o.username AS owner, r.name, |
| 139 | (SELECT MIN(x.started_at) FROM run x | |
| 139 | (SELECT MIN(x.started_at) FROM run x INDEXED BY run_agent_issue_latest | |
| 140 | 140 | WHERE x.issue_id = i.id AND x.kind = 'agent' AND x.started_at IS NOT NULL) AS first_start |
| 141 | 141 | FROM issue i INDEXED BY issue_closed_done |
| 142 | 142 | JOIN repo r ON r.id = i.repo_id JOIN user o ON o.id = r.owner_id |
test/checks-runner-capacity.test.ts +9 −23
| @@ -11,7 +11,7 @@ import { join } from "node:path"; | ||
| 11 | 11 | import { createApp, type App } from "../src/app.ts"; |
| 12 | 12 | import { CHECKS_CEILING, capacity, type LaneState } from "../src/checks/lane_state.ts"; |
| 13 | 13 | import type { Placement } from "../src/checks/placement.ts"; |
| 14 | import { enrolRunner, liveRunnerJobs, noteRunnerJobs, runnerByToken, SEEN_FRESH_MS } from "../src/checks/runner_jobs.ts"; | |
| 14 | import { enrolRunner, noteRunnerJobs, runnerByToken } from "../src/checks/runner_jobs.ts"; | |
| 15 | 15 | import { CAPACITY, setCapacity } from "../src/core/capacity.ts"; |
| 16 | 16 | |
| 17 | 17 | let dataDir: string; |
| @@ -31,38 +31,26 @@ const lane = (placement: Placement, concurrency = 2): LaneState => | ||
| 31 | 31 | |
| 32 | 32 | const T = 10_000_000; |
| 33 | 33 | |
| 34 | test("the setting plus the jobs of live runners, under the runner placement only", () => { | |
| 34 | test("the setting is the most checks at once, however many runners are live (#16189)", () => { | |
| 35 | 35 | const runner = lane({ mode: "runner", waitMs: 300 }); |
| 36 | expect(capacity(runner, T)).toBe(2); | |
| 36 | expect(capacity(runner)).toBe(2); | |
| 37 | 37 | const one = enrolRunner(app.db, "one", "admin"); |
| 38 | 38 | const two = enrolRunner(app.db, "two", "admin"); |
| 39 | 39 | runnerByToken(app.db, one.token, T); |
| 40 | expect(capacity(runner, T)).toBe(3); | |
| 41 | 40 | runnerByToken(app.db, two.token, T); |
| 42 | 41 | noteRunnerJobs(app.db, two.runner.id, 4); |
| 43 | expect(liveRunnerJobs(app.db, T)).toBe(5); | |
| 44 | expect(capacity(runner, T)).toBe(7); | |
| 45 | // An admin's setting is read on every pick, and the runners add to it. | |
| 42 | expect(capacity(runner)).toBe(2); | |
| 43 | // An admin's setting is read on every pick; runners still add nothing. | |
| 46 | 44 | setCapacity(app.db, "checks.concurrency", "3", "admin"); |
| 47 | expect(capacity(runner, T)).toBe(8); | |
| 45 | expect(capacity(runner)).toBe(3); | |
| 48 | 46 | setCapacity(app.db, "checks.concurrency", null, "admin"); |
| 49 | // Runners never take a check under the process placement: they add nothing there. | |
| 50 | expect(capacity(lane({ mode: "process" }), T)).toBe(2); | |
| 51 | }); | |
| 52 | ||
| 53 | test("a runner not seen within SEEN_FRESH_MS stops counting, with no restart", () => { | |
| 54 | const runner = lane({ mode: "runner", waitMs: 300 }); | |
| 55 | expect(capacity(runner, T + SEEN_FRESH_MS - 1)).toBe(7); | |
| 56 | expect(capacity(runner, T + SEEN_FRESH_MS)).toBe(2); | |
| 47 | expect(capacity(lane({ mode: "process" }))).toBe(2); | |
| 57 | 48 | }); |
| 58 | 49 | |
| 59 | 50 | test("never above the setting's own ceiling", () => { |
| 60 | const big = enrolRunner(app.db, "big", "admin"); | |
| 61 | runnerByToken(app.db, big.token, T); | |
| 62 | noteRunnerJobs(app.db, big.runner.id, 64); | |
| 63 | 51 | const kind = CAPACITY["checks.concurrency"].kind; |
| 64 | 52 | expect(CHECKS_CEILING).toBe(kind.type === "count" ? kind.max : -1); |
| 65 | expect(capacity(lane({ mode: "runner", waitMs: 300 }), T)).toBe(CHECKS_CEILING); | |
| 53 | expect(capacity(lane({ mode: "runner", waitMs: 300 }, 999))).toBe(CHECKS_CEILING); | |
| 66 | 54 | }); |
| 67 | 55 | |
| 68 | 56 | test("a count a claim says is kept only when it is a whole number from 1 to 64", () => { |
| @@ -77,7 +65,5 @@ test("a count a claim says is kept only when it is a whole number from 1 to 64", | ||
| 77 | 65 | }); |
| 78 | 66 | |
| 79 | 67 | test("the setting's line says what it counts", () => { |
| 80 | expect(CAPACITY["checks.concurrency"].help).toStartWith( | |
| 81 | "How many repository checks run at once on this forge's own cells; each runner seen in the last minute adds the jobs it runs at once, up to 16 in all.", | |
| 82 | ); | |
| 68 | expect(CAPACITY["checks.concurrency"].help).toStartWith("The most repository checks running at once, whoever runs them"); | |
| 83 | 69 | }); |
test/hot-reads-indexed.test.ts +8
| @@ -100,3 +100,11 @@ test("a page-view flush counts a visitor's day from the visitor index, not the s | ||
| 100 | 100 | expect(lines.join("\n")).toContain("traffic_view_scope_visitor_at"); |
| 101 | 101 | noScan(lines.filter((l) => l !== "SCAN CONSTANT ROW")); |
| 102 | 102 | }); |
| 103 | ||
| 104 | test("the home's ship time reads each issue's first agent run by index, with no statistics (#16189)", async () => { | |
| 105 | expect(app.db.query("SELECT 1 FROM sqlite_master WHERE name = 'sqlite_stat1'").get()).toBeNull(); | |
| 106 | const { readShipTime } = await import("../src/flow/ship_time.ts"); | |
| 107 | const lines = plans(() => void readShipTime(app.db, new Date())); | |
| 108 | expect(lines.join("\n")).toContain("run_agent_issue_latest"); | |
| 109 | expect(lines.join("\n")).not.toContain("run_kind_started"); | |
| 110 | }); |
new above
offline
The new help text is right, but docs/features/runners.md still describes the old additive behaviour. Update it in this pull.