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

Move the accessors out of snapshot/service.ts (snapshotsOf) so it leaves the boot's static closure #17302

opened this

Merged 39h 40m ago, live in production

mason/forge:mason/17183-move-the-accessors-out-of-snapshot-servi → main 0 commits fork

  • Merged. mason/17183-move-the-accessors-out-of-snapshot-servi was merged into main as bc00add.

Review

Sign in to review this change.
17 files changed +43 −23
src/actions/backup_retry.ts +1 −1
@@ -8,7 +8,7 @@
88 import type { App } from "../app.ts";
99 import type { User } from "../core/users.ts";
1010 import { isOffBox } from "../snapshot/off_box.ts";
11 import { snapshotsOf } from "../snapshot/service.ts";
11 import { snapshotsOf } from "../snapshot/registry.ts";
1212 import { snapshotNow } from "./backups_now.ts";
1313
1414 export interface BackupRetry {
src/actions/backups_now.ts +1 −1
@@ -13,7 +13,7 @@ import { err, ok, type Result } from "../kernel/result.ts";
1313 import type { DrillStep } from "../snapshot/drill.ts";
1414 import { costLine } from "../snapshot/drill_cost.ts";
1515 import { lastDrill } from "../snapshot/drills.ts";
16 import { snapshotsOf } from "../snapshot/service.ts";
16 import { snapshotsOf } from "../snapshot/registry.ts";
1717 import { fileSize } from "../web/ui.ts";
1818
1919 const isAdmin = (actor: User | undefined): boolean => actor?.isAdmin === true;
src/actions/destination.ts +1 −1
@@ -18,7 +18,7 @@ import {
1818 } from "../snapshot/destination.ts";
1919 import { kitIdentity, kitText, makeKit, recordDownload } from "../snapshot/kit.ts";
2020 import { s3FromEnv, type S3Target } from "../blob/store.ts";
21 import { snapshotsOf } from "../snapshot/service.ts";
21 import { snapshotsOf } from "../snapshot/registry.ts";
2222 import type { User } from "../core/users.ts";
2323 import { err, ok, type Result } from "../kernel/result.ts";
2424 import { NOT_SEALED } from "../kernel/seal_words.ts";
src/actions/health.ts +1 −1
@@ -35,7 +35,7 @@ import {
3535 type Vitals,
3636 type VitalsInput,
3737 } from "../kernel/vitals.ts";
38 import { snapshotsOf } from "../snapshot/service.ts";
38 import { snapshotsOf } from "../snapshot/registry.ts";
3939 import { optionals, type Optional } from "../system/footprint.ts";
4040 import { forgesMemory, memoryOverLine } from "../spawn/memory_fit.ts";
4141 import { releaseOf } from "../kernel/version.ts";
src/actions/mirror.ts +1 −1
@@ -14,7 +14,7 @@ import {
1414 MIRROR_SEALED,
1515 recordMirror,
1616 } from "../snapshot/mirror.ts";
17 import { snapshotsOf } from "../snapshot/service.ts";
17 import { snapshotsOf } from "../snapshot/registry.ts";
1818 import type { User } from "../core/users.ts";
1919 import { err, ok, type Result } from "../kernel/result.ts";
2020 import { NOT_SEALED } from "../kernel/seal_words.ts";
src/actions/resilience.ts +1 −1
@@ -11,7 +11,7 @@ import type { User } from "../core/users.ts";
1111 import { drillCommand } from "../kernel/domain_drill.ts";
1212 import { DOMAINS } from "../kernel/domains.ts";
1313 import { err, ok, type Result } from "../kernel/result.ts";
14 import { snapshotsOf } from "../snapshot/service.ts";
14 import { snapshotsOf } from "../snapshot/registry.ts";
1515 import { forgeNeeds } from "./health.ts";
1616
1717 export interface ResilienceRow {
src/http/mcp/tools/backups.ts +1 −1
@@ -1,4 +1,4 @@
1 import { snapshotsOf } from "../../../snapshot/service.ts";
1 import { snapshotsOf } from "../../../snapshot/registry.ts";
22 import { resolveSnapshots, scrubReason, sealedTarget } from "../../../snapshot/destination.ts";
33 import { bodiesOf } from "../../../blob/store.ts";
44 import { mirrorNeed } from "../../../snapshot/mirror.ts";
src/http/mcp/tools/mirror_set.ts +1 −1
@@ -1,5 +1,5 @@
11 import { forgetMirror, saveMirror } from "../../../actions/mirror.ts";
2 import { snapshotsOf } from "../../../snapshot/service.ts";
2 import { snapshotsOf } from "../../../snapshot/registry.ts";
33 import { good, bad, type Tool } from "../shared.ts";
44
55 export const tool: Tool = {
src/http/mcp/tools/restore_drill.ts +2 −1
@@ -1,7 +1,8 @@
11 import { scopeAllows } from "../../../core/tokens.ts";
22 import { costLine } from "../../../snapshot/drill_cost.ts";
33 import { lastDrill } from "../../../snapshot/drills.ts";
4 import { snapshotsOf, type SnapshotsHandle } from "../../../snapshot/service.ts";
4 import { snapshotsOf } from "../../../snapshot/registry.ts";
5 import type { SnapshotsHandle } from "../../../snapshot/service.ts";
56 import { good, bad, type Tool, mayBoards } from "../shared.ts";
67
78 const phaseWords = (st: ReturnType<SnapshotsHandle["startDrill"]>["state"]): Record<string, string | number> =>
src/keeper/wire.ts +1 −1
@@ -34,7 +34,7 @@ import { readTags, recordFor } from "../release/shipped.ts";
3434 import { checkoutRelease, preflightRelease } from "../release/checkout.ts";
3535 import { handover } from "../release/swap.ts";
3636 import { runningChildren } from "../boards/sampler.ts";
37 import { snapshotsOf } from "../snapshot/service.ts";
37 import { snapshotsOf } from "../snapshot/registry.ts";
3838 import { kubeDeployer } from "./deploy.ts";
3939 import { inFlight, keepInterrupted, keepRollback, keepTimings } from "./record.ts";
4040 import { runningAgentRuns } from "../crew/running.ts";
src/snapshot/backups_line.ts +1 −1
@@ -6,7 +6,7 @@
66 */
77
88 import type { App } from "../app.ts";
9 import { snapshotsOf } from "./service.ts";
9 import { snapshotsOf } from "./registry.ts";
1010
1111 export const BACKUPS_OFF = "Backups are off here: this forge was given no bucket to keep snapshots in.";
1212
src/snapshot/registry.ts added +21
@@ -0,0 +1,21 @@
1 /**
2 * Where the running snapshot service is found. The service fills this when it starts
3 * (`service.ts`); pages, actions and tools ask here, so none of them loads the service itself and
4 * the boot's static imports leave it out (#17183).
5 */
6 import type { App } from "../app.ts";
7 import type { SnapshotsHandle } from "./service.ts";
8
9 const handles = new WeakMap<App, SnapshotsHandle>();
10
11 export const snapshotsOf = (app: App): SnapshotsHandle | undefined => handles.get(app);
12
13 /**
14 * Record the service started for `app`; the returned function forgets it when it is still the one.
15 */
16 export function registerSnapshots(app: App, handle: SnapshotsHandle): () => void {
17 handles.set(app, handle);
18 return () => {
19 if (handles.get(app) === handle) handles.delete(app);
20 };
21 }
src/snapshot/service.ts +3 −6
@@ -43,6 +43,7 @@ import { remakeOf, s3FromEnv, type Store } from "../blob/store.ts";
4343 import { verifySnapshot } from "./verify.ts";
4444 import { during } from "../perf/jobs.ts";
4545 import { limitValue } from "../settings/limits.ts";
46 import { registerSnapshots } from "./registry.ts";
4647
4748 const log = createLog("snapshots");
4849
@@ -126,10 +127,6 @@ export interface SnapshotsHandle {
126127 readonly stop: () => Promise<void>;
127128 }
128129
129 const handles = new WeakMap<App, SnapshotsHandle>();
130 export const snapshotsOf = (app: App): SnapshotsHandle | undefined =>
131 handles.get(app);
132
133130 /** The weekly restore drill: Sunday, an hour after the nightly snapshot. */
134131 const DRILL_DAY_UTC = 0;
135132 const DRILL_HOUR_UTC = 9;
@@ -795,10 +792,10 @@ export function startSnapshots(
795792 bucket.stop();
796793 if (mirroring !== undefined) await mirroring.catch(() => {});
797794 if (inFlight !== undefined) await inFlight.catch(() => {});
798 if (handles.get(app) === handle) handles.delete(app);
795 forget();
799796 },
800797 };
801 handles.set(app, handle);
798 const forget = registerSnapshots(app, handle);
802799 log.info("snapshots on", {
803800 where: current()?.where ?? "nowhere",
804801 keep: KEEP,
src/tui/screens/resilience.ts +1 −1
@@ -46,7 +46,7 @@ import { lastDrill } from "../../snapshot/drills.ts";
4646 import { hostedDrillWords } from "../../snapshot/drill_hosted_words.ts";
4747 import { resolveSnapshots } from "../../snapshot/destination.ts";
4848 import { bodiesOf } from "../../blob/store.ts";
49 import { snapshotsOf } from "../../snapshot/service.ts";
49 import { snapshotsOf } from "../../snapshot/registry.ts";
5050 import type { Ctx, Screen } from "../app/app.ts";
5151 import { binding } from "../app/keys.ts";
5252 import type { Session } from "../session.ts";
src/web/pages/backups.ts +2 −1
@@ -36,7 +36,8 @@ import { backupVerdict } from "../../snapshot/bucket.ts";
3636 import { bodiesOf, type Store } from "../../blob/store.ts";
3737 import { hostedWords } from "../../snapshot/hosted.ts";
3838 import { hostedDrillWords } from "../../snapshot/drill_hosted_words.ts";
39 import { snapshotsOf, type SnapshotsHandle } from "../../snapshot/service.ts";
39 import { snapshotsOf } from "../../snapshot/registry.ts";
40 import type { SnapshotsHandle } from "../../snapshot/service.ts";
4041 import { drillStatus, mirrorNow, snapshotNow, startDrillNow } from "../../actions/backups_now.ts";
4142 import { lastSnapshotOutcome } from "../../snapshot/outcome.ts";
4243 import type { Ctx } from "../../http/context.ts";
test/backup-truth.test.ts +2 −1
@@ -16,7 +16,8 @@ import { vitals } from "../src/kernel/vitals.ts";
1616 import { backupVerdict, CHECK_LOG, CHECK_LOG_KEEP, CHECK_STALE_MS, recordRun, judge, keepReads, LATE_MS, readLane, watchBucket, type LaneRead } from "../src/snapshot/bucket.ts";
1717 import type { DrillResult } from "../src/snapshot/drill.ts";
1818 import { lastNightly, snapshotDue } from "../src/snapshot/due.ts";
19 import { snapshotsOf, startSnapshots } from "../src/snapshot/service.ts";
19 import { snapshotsOf } from "../src/snapshot/registry.ts";
20 import { startSnapshots } from "../src/snapshot/service.ts";
2021 import { listSnapshots } from "../src/snapshot/snapshot.ts";
2122 import { dirStore } from "../src/blob/store.ts";
2223 import { verdictLines } from "../src/tui/screens/resilience.ts";
test/boot-lazy.test.ts +2 −3
@@ -24,11 +24,10 @@ test("the terminal's server is imported dynamically by the boot", () => {
2424 // #17021: the services only the boot starts are not in its static closure; that each still starts
2525 // is proved on a real boot (boot-production.test.ts, "background service started service=<name>").
2626 // The heavier ones are still reached by pages and actions, each its own follow-up: #17179,
27 // #17180, #17181, #17182, #17183 (apps/runtime, checks/service, crew/dispatch, looks/service,
28 // snapshot/service).
27 // #17180, #17181, #17182 (apps/runtime, checks/service, crew/dispatch, looks/service).
2928 test("the boot's static imports do not reach the services only it starts", () => {
3029 const closure = [...staticClosure(resolve("src/main.ts"))];
31 const only = ["maintain/runner.ts", "nightly/service.ts", "keeper/keeper.ts", "keeper/wire.ts", "crew/routines.ts"];
30 const only = ["maintain/runner.ts", "nightly/service.ts", "keeper/keeper.ts", "keeper/wire.ts", "crew/routines.ts", "snapshot/service.ts"];
3231 for (const file of only) expect(closure.some((f) => f.endsWith(`/src/${file}`)), file).toBe(false);
3332 });
3433

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

Keyboard shortcuts

Docs