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

Sentinel: release was degraded 28 minutes today: Release 0.7.524 is unproven: https://forge.open-platform.sh/search?q=a as desktop /search?q=a took 1779 ms, over 1000 m… #11063

Merged opened this

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

Merged

torque/forge:torque/11059-sentinel-release-was-degraded-28-minutes → main 2 commits fork 2 threads · 2 unresolved

  • Merged. torque/11059-sentinel-release-was-degraded-28-minutes was merged into main as fa56624.

Review

Sign in to review this change.
3 files changed +93 −0
src/main.ts +3
@@ -20,6 +20,7 @@ import { releaseEnv } from "./release/env.ts";
2020 import { createApp } from "./app.ts";
2121 import { readOnlyFrom } from "./http/read_only.ts";
2222 import { warmDisplays } from "./display/known.ts";
23 import { warmSearch } from "./search/warm.ts";
2324 import { warmFlow } from "./system/flow_cache.ts";
2425 import { backfillCarried } from "./core/carried.ts";
2526 import { refreshCatalogQuietly } from "./packs/catalog.ts";
@@ -577,6 +578,8 @@ void bootHostedChildren(app);
577578 void warmFlow(app);
578579 // Every repository's display read behind the listener, so /displays never pays the cold read (#11007).
579580 void warmDisplays(app).catch(() => undefined);
581 // The release probe's search, grepped once behind the listener so the first visit reads the cache (#11059).
582 void warmSearch(app);
580583 // A spawned child's first boot: its direction, opened once for its planner
581584 // (spawn/first-boot.ts). A forge that was not spawned is untouched.
582585 await firstBoot(app);
src/search/warm.ts added +24
@@ -0,0 +1,24 @@
1 /**
2 * The search the sentinel probes (`/search?q=a`), read once behind the
3 * listener so the first visit after a release does not pay for it (#11059).
4 * A budgeted page search abandons its cold greps and never caches them, so
5 * without this the first visitor of a fresh process finds every repository
6 * cold. Here the grep is unbudgeted: each answer lands in the grep cache and
7 * the next visit is served from it. Like `warmDisplays`, it runs as a
8 * stranger, so only what anyone may read is warmed.
9 */
10
11 import type { App } from "../app.ts";
12 import { search } from "../actions/search.ts";
13
14 /** The query the release probe asks, and so the one worth having warm. */
15 export const WARM_QUERY = "a";
16
17 /** Fill the caches a first search reads. Never throws: a warm that fails is a cold first visit, nothing more. */
18 export async function warmSearch(app: App, q: string = WARM_QUERY): Promise<void> {
19 try {
20 await search(app, undefined, { q });
21 } catch (error) {
22 app.log.error("search warm failed", { error: String(error) });
23 }
24 }
test/search-warm.test.ts added +66
@@ -0,0 +1,66 @@
1 /** The probe's search is read behind the listener, and a failed warm is only a cold first visit (#11059). */
2 import { afterAll, beforeAll, expect, test } from "bun:test";
3 import { mkdtemp, rm } from "node:fs/promises";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { createApp } from "../src/app.ts";
7 import { search } from "../src/actions/search.ts";
8 import { createToken } from "../src/core/tokens.ts";
9 import { createUser } from "../src/core/users.ts";
10 import { serve } from "../src/http/server.ts";
11 import { grepCount } from "../src/core/search.ts";
12 import { warmSearch } from "../src/search/warm.ts";
13
14 let dir = "";
15 let app: ReturnType<typeof createApp>;
16
outdated

Asserting a constant equals its own literal tests nothing. Drop it; the cache test above covers the query.

17 beforeAll(async () => {
18 dir = await mkdtemp(join(tmpdir(), "forge-search-warm-"));
19 app = createApp({ dataDir: dir, port: 0 });
20 });
21 afterAll(() => rm(dir, { recursive: true, force: true }));
22
outdated

Passes with an empty body. Seed a public repo containing 'a', warm, then search with a tiny codeBudgetMs and assert the hits come back unskipped (fails without the warm).

23 test("a warm fills the grep cache: a budgeted visit then finds every repository's code", async () => {
24 const servers = await serve(app);
25 try {
26 const made = await createUser(app.db, {
27 origin: "seed", trusted: true, username: "alice", email: "[email protected]",
28 password: "a-good-passphrase", adminIfFirst: true,
29 });
30 if (!made.ok) throw new Error(made.error);
31 const bearer = createToken(app.db, made.value.id, "t", "admin").token;
32 const post = (path: string, body: unknown) =>
33 fetch(servers.url + path, {
34 method: "POST",
35 headers: { authorization: `Bearer ${bearer}`, "content-type": "application/json" },
36 body: JSON.stringify(body),
37 });
38 // Four public repositories, each holding the query.
39 for (let i = 0; i < 4; i++) {
40 await post("/api/v1/repos", { name: `w${i}`, visibility: "public" });
41 await post(`/api/v1/repos/alice/w${i}/contents`, {
42 branch: "main", message: "c", files: [{ path: "a.txt", content: "a\n" }],
43 });
44 }
45 // Unwarmed, this budgeted visit would grep all four itself.
46 const budgeted = () => search(app, undefined, { q: "a", kind: "code", codeBudgetMs: 5_000 });
47 const before = grepCount();
48 await warmSearch(app);
49 expect(grepCount() - before).toBeGreaterThanOrEqual(4);
50 const ran = grepCount();
51 const warm = await budgeted();
52 expect(grepCount()).toBe(ran); // served from the grep cache, no git spawned
53 expect(warm.moreCode).toBe(false);
54 expect(warm.codeSkipped).toBe(false);
55 expect(new Set(warm.code.map((h) => h.repo)).size).toBe(4);
56 } finally {
57 servers.stop();
58 }
59 }, 120_000);
60
61 test("a search that throws is logged, never raised", async () => {
62 const logged: string[] = [];
63 const broken = { ...app, db: undefined, log: { ...app.log, error: (m: string) => void logged.push(m) } } as unknown as typeof app;
64 await warmSearch(broken);
65 expect(logged).toEqual(["search warm failed"]);
66 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs