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

opened this in answer to

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

  • Merged. mason/17602-a-merged-pull-of-the-forge-says-producti was merged into main as db29859.

Review

Sign in to review this change.
9 files changed +121 −4
src/web/studio/app.ts +2
@@ -73,6 +73,7 @@ import { schedulesCard } from "./schedules.ts";
7373 import { appPanels, warmProductionLog } from "./previews.ts";
7474 import { contributeSteps } from "./contribute_steps.ts";
7575 import { noCrewLine, pausedWords, servingHistory, type WordCtx } from "./words.ts";
76 import { runningCommit } from "./running.ts";
7677 import { crewKeyCard, includedCredit } from "./crew_key.ts";
7778 import { landOnApp } from "./land_as_is.ts";
7879 import { usdWords } from "../../spawn/credit.ts";
@@ -294,6 +295,7 @@ export async function studioApp(
294295 record,
295296 history: servingHistory(),
296297 viewer: ctx.auth.user,
298 running: () => runningCommit(ctx.app, repo, wordCtx.history),
297299 };
298300 const crew = timePhase(req, "crew", () => listCrewRoles(db, repo.id));
299301 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";
109109 import { paneView, type PaneDoors } from "./pane.ts";
110110 import { changeHref } from "./nouns.ts";
111111 import { pullWord, servingHistory, wordDot, type WordCtx } from "./words.ts";
112 import { runningCommit } from "./running.ts";
112113 import { getHold } from "../../core/holds.ts";
113114 import { backToWave } from "../../story/waves.ts";
114115 import { offerPullCard } from "../pages/offer-upstream.ts";
@@ -416,6 +417,7 @@ async function pullPanels(ctx: Ctx, repo: Repo, pull: Pull, spent: Spent = newSp
416417 record,
417418 history: servingHistory(),
418419 viewer: ctx.auth.user,
420 running: () => runningCommit(ctx.app, repo, wordCtx.history),
419421 };
420422 const { word, note: checkNote } = await lap(spent, "checks", () =>
421423 pullWord(wordCtx, pull),
src/web/studio/lists.ts +3
@@ -76,6 +76,7 @@ import {
7676 servingHistory,
7777 type WordCtx,
7878 } from "./words.ts";
79 import { runningCommit } from "./running.ts";
7980
8081 /** The five words a studio list filters by. `waiting` and `planned` are
8182 * 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) {
403404 record,
404405 history: servingHistory(),
405406 viewer: ctx.auth.user,
407 running: () => runningCommit(ctx.app, repo, wordCtx.history),
406408 };
407409 return { options, record, wordCtx };
408410 }
@@ -859,6 +861,7 @@ export async function runsListPage(ctx: Ctx, repo: Repo): Promise<Response> {
859861 record,
860862 history: servingHistory(),
861863 viewer: ctx.auth.user,
864 running: () => runningCommit(ctx.app, repo, wordCtx.history),
862865 };
863866 const actors = actorsFor(ctx, fetched);
864867 const issues = issuesFor(ctx, fetched);
src/web/studio/run.ts +2
@@ -48,6 +48,7 @@ import { changeHref, tellHref } from "./nouns.ts";
4848 import { crewFace } from "../pixel.ts";
4949 import { unnamedRun, voiceFor, type Actor } from "./voice.ts";
5050 import { runWord, servingHistory, wordBadge, type WordCtx } from "./words.ts";
51 import { runningCommit } from "./running.ts";
5152
5253 /** A step's badge: red only where it failed; waiting and skipped stay quiet. */
5354 const STEP_TONES: Record<string, Tone> = { ok: "success", failed: "danger", running: "attn" };
@@ -154,6 +155,7 @@ export async function runView(
154155 record: getAppByRepo(db, repo.id),
155156 history: servingHistory(),
156157 viewer: ctx.auth.user,
158 running: () => runningCommit(ctx.app, repo, wordCtx.history),
157159 };
158160 const { word } = await runWord(wordCtx, run);
159161 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);
outdated

When no release is recorded at all this returns "", and caughtUp then 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.

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;

Non-blocking: listKeeperReleases(app.db, 10) means that if the newest ten are all rolled back or not live, a forge that is in fact serving an older live release reads waiting. That is conservative and the test pins it. Consider asking for the newest live row directly instead of a window of ten.

32 }
src/web/studio/shelf.ts +2
@@ -56,6 +56,7 @@ import {
5656 type WordCtx,
5757 NOBODY_ON_CREW,
5858 } from "./words.ts";
59 import { runningCommit } from "./running.ts";
5960
6061 /** Reads the caller has already made, so the shelf does not make them again. */
6162 export interface ShelfReads {
@@ -252,6 +253,7 @@ export async function shelfRows(
252253 record,
253254 history,
254255 viewer: ctx.auth.user,
256 running: () => runningCommit(ctx.app, repo, wordCtx.history),
255257 };
256258 const agentWord =
257259 useOpenPull || latest === undefined
src/web/studio/tell.ts +2
@@ -104,6 +104,7 @@ import {
104104 servingHistory,
105105 type WordCtx,
106106 } from "./words.ts";
107 import { runningCommit } from "./running.ts";
107108
108109 /** Per word context, per repository: the pull each issue's merge closed. */
109110 const mergeClosings = new WeakMap<
@@ -456,6 +457,7 @@ async function studioTell(
456457 record: getAppByRepo(db, repo.id),
457458 history: servingHistory(),
458459 viewer: ctx.auth.user,
460 running: () => runningCommit(ctx.app, repo, wordCtx.history),
459461 };
460462 // Closing is the author's or a writer's (`setIssueState`); nobody else is
461463 // shown a button the server would only refuse.
src/web/studio/words.ts +26 −4
@@ -105,6 +105,12 @@ export interface WordCtx {
105105 readonly history: ServingHistory;
106106 /** Who is reading: a private app's production is theirs only if they may enter it. */
107107 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;
108114 /** Where ancestries are kept; the process's own unless a test brings its own. */
109115 readonly ancestries?: AncestryCache;
110116 }
@@ -115,6 +121,8 @@ interface Ahead {
115121 readonly reviewers: Map<string, string | undefined>;
116122 readonly runPulls: Map<string, Pull | undefined>;
117123 readonly parked: Map<string, boolean>;
124 /** `ctx.running` answered once. */
125 running?: { commit: string | undefined };
118126 /** Production as a merged pull sees it; `null` when the viewer may not see it. */
119127 production?: { env: EnvStatus | undefined } | null;
120128 }
@@ -249,6 +257,13 @@ function pullFromRun(db: Database, run: Run): Pull | undefined {
249257 return pullForBranch(db, run.repoId, run.branch);
250258 }
251259
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
252267 /** Whether production is serving this commit, or something later than it:
253268 * ancestry, never equality, asked of git once per page and repository. */
254269 async function caughtUp(
@@ -257,11 +272,13 @@ async function caughtUp(
257272 commitOid: string,
258273 ): Promise<boolean> {
259274 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}`;
262279 let ancestry = ctx.history.get(key);
263280 if (ancestry === undefined) {
264 ancestry = (ctx.ancestries ?? ancestries).of(ctx.dir, production.commitOid);
281 ancestry = (ctx.ancestries ?? ancestries).of(ctx.dir, serving);
265282 ctx.history.set(key, ancestry);
266283 }
267284 return (await ancestry)?.has(commitOid) ?? false;
@@ -271,7 +288,12 @@ async function caughtUp(
271288 function mergedPullWord(
272289 production: EnvStatus | undefined,
273290 commitOid: string,
291 ownForge: boolean,
274292 ): { 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" };
275297 if (production?.commitOid === commitOid) {
276298 if (production.state === "failed")
277299 return {
@@ -383,7 +405,7 @@ export async function pullWord(
383405 }
384406 if (await caughtUp(ctx, production, commitOid))
385407 return { word: "shipped", note: "production is serving it" };
386 return mergedPullWord(production, commitOid);
408 return mergedPullWord(production, commitOid, runningOf(ctx) !== undefined);
387409 }
388410 if (pull.state === "closed")
389411 return {
test/pulls-words.test.ts +50
@@ -10,9 +10,13 @@ import { createApp, type App } from "../src/app.ts";
1010 import { createRepo } from "../src/actions/repos.ts";
1111 import { createIssue } from "../src/core/issues.ts";
1212 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";
1315 import type { Repo } from "../src/core/repos.ts";
1416 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
1517 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";
1620 import { repoDir } from "../src/git/repos.ts";
1721 import { pullWord, pullWords, servingHistory, type WordCtx } from "../src/web/studio/words.ts";
1822 import { quietLogs } from "./helpers/globals.ts";
@@ -122,6 +126,52 @@ describe("a page of pulls, worded in one batch", () => {
122126 expect(batched[1]).toEqual({ word: "waiting", note: "merged; waiting for production to redeploy" });
123127 });
124128
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");
outdated

Reset the forge source in a finally (or afterEach). If an expect above throws, the forge source stays set and later tests in this file read a forge's own repository. Also run these tests against the old words.ts once and say in the pull that they fail there.

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
125175 test("the words phase for 50 pulls costs a bounded number of statements", async () => {
126176 const pulls = page();
127177 await pullWords(ctx(), pulls); // warm statement caches

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

Keyboard shortcuts

Docs