Public: anyone can read this; the crew can change it.
A merged pull of the forge says "production is serving it" before the running forge has it #17603
Merged 15h 39m ago, live in production
mason/forge:mason/17602-a-merged-pull-of-the-forge-says-producti → main 0 commits fork 3 threads · 3 unresolved
9 files
changed +121
−4
src/web/studio/app.ts +2
| @@ -73,6 +73,7 @@ import { schedulesCard } from "./schedules.ts"; | ||
| 73 | 73 | import { appPanels, warmProductionLog } from "./previews.ts"; |
| 74 | 74 | import { contributeSteps } from "./contribute_steps.ts"; |
| 75 | 75 | import { noCrewLine, pausedWords, servingHistory, type WordCtx } from "./words.ts"; |
| 76 | import { runningCommit } from "./running.ts"; | |
| 76 | 77 | import { crewKeyCard, includedCredit } from "./crew_key.ts"; |
| 77 | 78 | import { landOnApp } from "./land_as_is.ts"; |
| 78 | 79 | import { usdWords } from "../../spawn/credit.ts"; |
| @@ -294,6 +295,7 @@ export async function studioApp( | ||
| 294 | 295 | record, |
| 295 | 296 | history: servingHistory(), |
| 296 | 297 | viewer: ctx.auth.user, |
| 298 | running: () => runningCommit(ctx.app, repo, wordCtx.history), | |
| 297 | 299 | }; |
| 298 | 300 | const crew = timePhase(req, "crew", () => listCrewRoles(db, repo.id)); |
| 299 | 301 | const builders = crew.filter((c) => c.role === "builder").map((c) => c.agent); |
src/web/studio/change.ts +2
| @@ -109,6 +109,7 @@ import { canVerdict } from "../../core/verdict.ts"; | ||
| 109 | 109 | import { paneView, type PaneDoors } from "./pane.ts"; |
| 110 | 110 | import { changeHref } from "./nouns.ts"; |
| 111 | 111 | import { pullWord, servingHistory, wordDot, type WordCtx } from "./words.ts"; |
| 112 | import { runningCommit } from "./running.ts"; | |
| 112 | 113 | import { getHold } from "../../core/holds.ts"; |
| 113 | 114 | import { backToWave } from "../../story/waves.ts"; |
| 114 | 115 | import { offerPullCard } from "../pages/offer-upstream.ts"; |
| @@ -416,6 +417,7 @@ async function pullPanels(ctx: Ctx, repo: Repo, pull: Pull, spent: Spent = newSp | ||
| 416 | 417 | record, |
| 417 | 418 | history: servingHistory(), |
| 418 | 419 | viewer: ctx.auth.user, |
| 420 | running: () => runningCommit(ctx.app, repo, wordCtx.history), | |
| 419 | 421 | }; |
| 420 | 422 | const { word, note: checkNote } = await lap(spent, "checks", () => |
| 421 | 423 | pullWord(wordCtx, pull), |
src/web/studio/lists.ts +3
| @@ -76,6 +76,7 @@ import { | ||
| 76 | 76 | servingHistory, |
| 77 | 77 | type WordCtx, |
| 78 | 78 | } from "./words.ts"; |
| 79 | import { runningCommit } from "./running.ts"; | |
| 79 | 80 | |
| 80 | 81 | /** The five words a studio list filters by. `waiting` and `planned` are |
| 81 | 82 | * still moving, so they fold into `working`; `done` is a deploy or a check |
| @@ -403,6 +404,7 @@ function listRead(ctx: Ctx, repo: Repo, f: ListFacets) { | ||
| 403 | 404 | record, |
| 404 | 405 | history: servingHistory(), |
| 405 | 406 | viewer: ctx.auth.user, |
| 407 | running: () => runningCommit(ctx.app, repo, wordCtx.history), | |
| 406 | 408 | }; |
| 407 | 409 | return { options, record, wordCtx }; |
| 408 | 410 | } |
| @@ -859,6 +861,7 @@ export async function runsListPage(ctx: Ctx, repo: Repo): Promise<Response> { | ||
| 859 | 861 | record, |
| 860 | 862 | history: servingHistory(), |
| 861 | 863 | viewer: ctx.auth.user, |
| 864 | running: () => runningCommit(ctx.app, repo, wordCtx.history), | |
| 862 | 865 | }; |
| 863 | 866 | const actors = actorsFor(ctx, fetched); |
| 864 | 867 | const issues = issuesFor(ctx, fetched); |
src/web/studio/run.ts +2
| @@ -48,6 +48,7 @@ import { changeHref, tellHref } from "./nouns.ts"; | ||
| 48 | 48 | import { crewFace } from "../pixel.ts"; |
| 49 | 49 | import { unnamedRun, voiceFor, type Actor } from "./voice.ts"; |
| 50 | 50 | import { runWord, servingHistory, wordBadge, type WordCtx } from "./words.ts"; |
| 51 | import { runningCommit } from "./running.ts"; | |
| 51 | 52 | |
| 52 | 53 | /** A step's badge: red only where it failed; waiting and skipped stay quiet. */ |
| 53 | 54 | const STEP_TONES: Record<string, Tone> = { ok: "success", failed: "danger", running: "attn" }; |
| @@ -154,6 +155,7 @@ export async function runView( | ||
| 154 | 155 | record: getAppByRepo(db, repo.id), |
| 155 | 156 | history: servingHistory(), |
| 156 | 157 | viewer: ctx.auth.user, |
| 158 | running: () => runningCommit(ctx.app, repo, wordCtx.history), | |
| 157 | 159 | }; |
| 158 | 160 | const { word } = await runWord(wordCtx, run); |
| 159 | 161 | const unfinished = !isTerminal(run.state); |
src/web/studio/running.ts added +32
| @@ -0,0 +1,32 @@ | ||
| 1 | /** | |
| 2 | * The commit of the forge process people are using, for the forge's own repository only. That | |
| 3 | * repository's app deployment moves before the process is replaced, so its production | |
| 4 | * `commitOid` cannot say what is serving (#17602); what the keeper recorded live can. | |
| 5 | */ | |
| 6 | ||
| 7 | import type { App } from "../../app.ts"; | |
| 8 | import { isNamed } from "../../core/forge_repo.ts"; | |
| 9 | import type { Repo } from "../../core/repos.ts"; | |
| 10 | import { listKeeperReleases } from "../../keeper/record.ts"; | |
| 11 | import { forgeSource } from "../../settings/forge_source.ts"; | |
| 12 | ||
| 13 | // What one page read, kept for the page: `page` is its `ServingHistory`, dropped with the request, | |
| 14 | // so a page of many apps asks once, not once for each. | |
| 15 | const read = new WeakMap<object, { own: string | undefined; sha?: string | null }>(); | |
| 16 | ||
| 17 | /** | |
| 18 | * The sha of the newest release the keeper recorded live and did not roll back; "" when none | |
| 19 | * is live though some are recorded (nothing is then known to be serving). Undefined for any | |
| 20 | * repository but the forge's own, and for a forge whose keeper has recorded no release at all: | |
| 21 | * those keep the words their deployment gives. `page` memoizes the two reads. | |
| 22 | */ | |
| 23 | export function runningCommit(app: App, repo: Pick<Repo, "ownerName" | "name">, page: object): string | undefined { | |
| 24 | let r = read.get(page); | |
| 25 | if (r === undefined) read.set(page, (r = { own: forgeSource(app.db, app.config.forgeRepo) })); | |
| 26 | if (!isNamed(r.own, repo)) return undefined; | |
| 27 | if (r.sha === undefined) { | |
| 28 | const recent = listKeeperReleases(app.db, 10); | |
| 29 | r.sha = recent.length === 0 ? null : (recent.find((x) => x.liveAt !== null && x.stage !== "rolled_back")?.sha ?? ""); | |
| 30 | } | |
| 31 | return r.sha ?? undefined; | |
| 32 | } |
src/web/studio/shelf.ts +2
| @@ -56,6 +56,7 @@ import { | ||
| 56 | 56 | type WordCtx, |
| 57 | 57 | NOBODY_ON_CREW, |
| 58 | 58 | } from "./words.ts"; |
| 59 | import { runningCommit } from "./running.ts"; | |
| 59 | 60 | |
| 60 | 61 | /** Reads the caller has already made, so the shelf does not make them again. */ |
| 61 | 62 | export interface ShelfReads { |
| @@ -252,6 +253,7 @@ export async function shelfRows( | ||
| 252 | 253 | record, |
| 253 | 254 | history, |
| 254 | 255 | viewer: ctx.auth.user, |
| 256 | running: () => runningCommit(ctx.app, repo, wordCtx.history), | |
| 255 | 257 | }; |
| 256 | 258 | const agentWord = |
| 257 | 259 | useOpenPull || latest === undefined |
src/web/studio/tell.ts +2
| @@ -104,6 +104,7 @@ import { | ||
| 104 | 104 | servingHistory, |
| 105 | 105 | type WordCtx, |
| 106 | 106 | } from "./words.ts"; |
| 107 | import { runningCommit } from "./running.ts"; | |
| 107 | 108 | |
| 108 | 109 | /** Per word context, per repository: the pull each issue's merge closed. */ |
| 109 | 110 | const mergeClosings = new WeakMap< |
| @@ -456,6 +457,7 @@ async function studioTell( | ||
| 456 | 457 | record: getAppByRepo(db, repo.id), |
| 457 | 458 | history: servingHistory(), |
| 458 | 459 | viewer: ctx.auth.user, |
| 460 | running: () => runningCommit(ctx.app, repo, wordCtx.history), | |
| 459 | 461 | }; |
| 460 | 462 | // Closing is the author's or a writer's (`setIssueState`); nobody else is |
| 461 | 463 | // shown a button the server would only refuse. |
src/web/studio/words.ts +26 −4
| @@ -105,6 +105,12 @@ export interface WordCtx { | ||
| 105 | 105 | readonly history: ServingHistory; |
| 106 | 106 | /** Who is reading: a private app's production is theirs only if they may enter it. */ |
| 107 | 107 | readonly viewer: User | undefined; |
| 108 | /** | |
| 109 | * Asks for the commit of the running forge process, for the forge's own repository only | |
| 110 | * (`running.ts`): "" while none is recorded live, undefined for every other app, whose | |
| 111 | * production says it. A function, so a page with no merged pull to word reads nothing. | |
| 112 | */ | |
| 113 | readonly running?: (() => string | undefined) | undefined; | |
| 108 | 114 | /** Where ancestries are kept; the process's own unless a test brings its own. */ |
| 109 | 115 | readonly ancestries?: AncestryCache; |
| 110 | 116 | } |
| @@ -115,6 +121,8 @@ interface Ahead { | ||
| 115 | 121 | readonly reviewers: Map<string, string | undefined>; |
| 116 | 122 | readonly runPulls: Map<string, Pull | undefined>; |
| 117 | 123 | readonly parked: Map<string, boolean>; |
| 124 | /** `ctx.running` answered once. */ | |
| 125 | running?: { commit: string | undefined }; | |
| 118 | 126 | /** Production as a merged pull sees it; `null` when the viewer may not see it. */ |
| 119 | 127 | production?: { env: EnvStatus | undefined } | null; |
| 120 | 128 | } |
| @@ -249,6 +257,13 @@ function pullFromRun(db: Database, run: Run): Pull | undefined { | ||
| 249 | 257 | return pullForBranch(db, run.repoId, run.branch); |
| 250 | 258 | } |
| 251 | 259 | |
| 260 | /** The running forge's commit, asked of `ctx.running` once per page. */ | |
| 261 | function runningOf(ctx: WordCtx): string | undefined { | |
| 262 | if (ctx.running === undefined) return undefined; | |
| 263 | const a = aheadOf(ctx); | |
| 264 | return (a.running ??= { commit: ctx.running() }).commit; | |
| 265 | } | |
| 266 | ||
| 252 | 267 | /** Whether production is serving this commit, or something later than it: |
| 253 | 268 | * ancestry, never equality, asked of git once per page and repository. */ |
| 254 | 269 | async function caughtUp( |
| @@ -257,11 +272,13 @@ async function caughtUp( | ||
| 257 | 272 | commitOid: string, |
| 258 | 273 | ): Promise<boolean> { |
| 259 | 274 | if (production === undefined || production.commitOid === "") return false; |
| 260 | if (production.commitOid === commitOid) return true; | |
| 261 | const key = `${ctx.dir}\0${production.commitOid}`; | |
| 275 | const serving = runningOf(ctx) ?? production.commitOid; | |
| 276 | if (serving === "") return false; | |
| 277 | if (serving === commitOid) return true; | |
| 278 | const key = `${ctx.dir}\0${serving}`; | |
| 262 | 279 | let ancestry = ctx.history.get(key); |
| 263 | 280 | if (ancestry === undefined) { |
| 264 | ancestry = (ctx.ancestries ?? ancestries).of(ctx.dir, production.commitOid); | |
| 281 | ancestry = (ctx.ancestries ?? ancestries).of(ctx.dir, serving); | |
| 265 | 282 | ctx.history.set(key, ancestry); |
| 266 | 283 | } |
| 267 | 284 | return (await ancestry)?.has(commitOid) ?? false; |
| @@ -271,7 +288,12 @@ async function caughtUp( | ||
| 271 | 288 | function mergedPullWord( |
| 272 | 289 | production: EnvStatus | undefined, |
| 273 | 290 | commitOid: string, |
| 291 | ownForge: boolean, | |
| 274 | 292 | ): { word: Word; note: string } { |
| 293 | // The forge's own deployment moves before its process is replaced: it says nothing of the | |
| 294 | // release. | |
| 295 | if (ownForge) | |
| 296 | return { word: "waiting", note: "merged; waiting for the forge to restart on it" }; | |
| 275 | 297 | if (production?.commitOid === commitOid) { |
| 276 | 298 | if (production.state === "failed") |
| 277 | 299 | return { |
| @@ -383,7 +405,7 @@ export async function pullWord( | ||
| 383 | 405 | } |
| 384 | 406 | if (await caughtUp(ctx, production, commitOid)) |
| 385 | 407 | return { word: "shipped", note: "production is serving it" }; |
| 386 | return mergedPullWord(production, commitOid); | |
| 408 | return mergedPullWord(production, commitOid, runningOf(ctx) !== undefined); | |
| 387 | 409 | } |
| 388 | 410 | if (pull.state === "closed") |
| 389 | 411 | return { |
test/pulls-words.test.ts +50
| @@ -10,9 +10,13 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 10 | 10 | import { createRepo } from "../src/actions/repos.ts"; |
| 11 | 11 | import { createIssue } from "../src/core/issues.ts"; |
| 12 | 12 | import { listPulls, type Pull } from "../src/core/pulls.ts"; |
| 13 | import type { AppsRuntime } from "../src/apps/runtime.ts"; | |
| 14 | import type { AppRecord } from "../src/core/apps.ts"; | |
| 13 | 15 | import type { Repo } from "../src/core/repos.ts"; |
| 14 | 16 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; |
| 15 | 17 | import { getUserByName } from "../src/core/users.ts"; |
| 18 | import { setForgeSource } from "../src/settings/forge_source.ts"; | |
| 19 | import { runningCommit } from "../src/web/studio/running.ts"; | |
| 16 | 20 | import { repoDir } from "../src/git/repos.ts"; |
| 17 | 21 | import { pullWord, pullWords, servingHistory, type WordCtx } from "../src/web/studio/words.ts"; |
| 18 | 22 | import { quietLogs } from "./helpers/globals.ts"; |
| @@ -122,6 +126,52 @@ describe("a page of pulls, worded in one batch", () => { | ||
| 122 | 126 | expect(batched[1]).toEqual({ word: "waiting", note: "merged; waiting for production to redeploy" }); |
| 123 | 127 | }); |
| 124 | 128 | |
| 129 | test("for the forge's own repository a deployment ahead of the running release reads as waiting (#17602)", async () => { | |
| 130 | const [first] = page().filter((p) => p.mergedAt !== null) as [Pull]; | |
| 131 | const runtime = { | |
| 132 | status: () => [{ env: "production", state: "running", commitOid: first.mergedOid, error: undefined }], | |
| 133 | } as unknown as AppsRuntime; | |
| 134 | const record = { id: "app1", repoId: repo.id, access: "public" } as unknown as AppRecord; | |
| 135 | const own = (running: string | undefined): WordCtx => ({ | |
| 136 | ...ctx(), | |
| 137 | runtime, | |
| 138 | record, | |
| 139 | ...(running === undefined ? {} : { running: () => running }), | |
| 140 | }); | |
| 141 | // Another app keeps its deployment's word. | |
| 142 | expect((await pullWord(own(undefined), first)).word).toBe("shipped"); | |
| 143 | // The deployment has it, the running process is an older release, or none is recorded. | |
| 144 | expect((await pullWord(own("1".repeat(40)), first)).word).toBe("waiting"); | |
| 145 | expect((await pullWord(own(""), first)).word).toBe("waiting"); | |
| 146 | // The running process is the commit itself. | |
| 147 | expect(await pullWord(own(first.mergedOid ?? ""), first)).toEqual({ word: "shipped", note: "production is serving it" }); | |
| 148 | }); | |
| 149 | ||
| 150 | test("runningCommit names the newest live release for the forge's own repository only", () => { | |
| 151 | const alice = getUserByName(app.db, "alice")!; | |
| 152 | const row = (v: string, sha: string, stage: string, live: string | null) => | |
| 153 | app.db.run( | |
| 154 | "INSERT INTO keeper_release (version, sha, known_good_version, known_good_image, stage, cut_at, live_at) VALUES (?1, ?2, '', '', ?3, '2026-12-02T18:00:00Z', ?4)", | |
| 155 | [v, sha, stage, live], | |
| 156 | ); | |
| 157 | try { | |
| 158 | expect(runningCommit(app, repo, {})).toBeUndefined(); | |
| 159 | setForgeSource(app.db, `${repo.ownerName}/${repo.name}`, alice.id); | |
| 160 | // No keeper has recorded anything: the deployment's word stands. | |
| 161 | expect(runningCommit(app, repo, {})).toBeUndefined(); | |
| 162 | // Releases exist and none is live: nothing is known to be serving. | |
| 163 | row("1.0.0", "d".repeat(40), "rolled_back", "2026-12-02T17:00:00Z"); | |
| 164 | expect(runningCommit(app, repo, {})).toBe(""); | |
| 165 | row("1.0.1", "a".repeat(40), "verified", "2026-12-02T18:41:24Z"); | |
| 166 | row("1.0.2", "b".repeat(40), "rolled_back", "2026-12-02T19:00:00Z"); | |
| 167 | row("1.0.3", "c".repeat(40), "rolling", null); | |
| 168 | expect(runningCommit(app, repo, {})).toBe("a".repeat(40)); | |
| 169 | } finally { | |
| 170 | setForgeSource(app.db, null, alice.id); | |
| 171 | app.db.run("DELETE FROM keeper_release"); | |
| 172 | } | |
| 173 | }); | |
| 174 | ||
| 125 | 175 | test("the words phase for 50 pulls costs a bounded number of statements", async () => { |
| 126 | 176 | const pulls = page(); |
| 127 | 177 | await pullWords(ctx(), pulls); // warm statement caches |
new above
offline
When no release is recorded at all this returns "", and
caughtUpthen answers false for every merged pull. A forge without a keeper, or one whose newest 10 releases are all rolled back, shows 'waiting for the forge to restart' for ever. Return undefined when the keeper has recorded nothing, so the deployment's word stands. Keep "" only when releases exist and none is live.