Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit af497cd0dddc2c736f9375af4a3447fc882a7b21
parent 88ce9bbd74c0be13feb2b8e5d673a178b661f8ea
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon,  9 Nov 2026 22:50:37 -0500

storage: the saved-video store refuses a write onto a drive that is not answering; the probe memo is one per process

- assertSavedVideosStoreWritable (the persist guard at the write) now asks
  the health record first: a corpus store whose link points onto a stalled
  location, or a channel's own store on one, is refused with
  SavedVideosStoreNotAnsweringError before moveFileCrossDevice holds a file
  thread on it. Every persist caller already catches a refusal there and
  leaves the container in the video dir for a later pass. Memory only; the
  store's link is read off the corpus disk.
- The 10 s location probe memo (storageVolumes.ts) moves onto globalThis,
  the house pattern: a reset from one module copy (the e2e invalidate-cache
  route, the drive-health test route, a re-point) left another copy's map
  answering "available" for a root that had just gone.
- e2e/drive-health.spec.ts: the channels link carries &sort=size; 1366x768
  screenshots of the four states.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mcommon/lib/savedVideoStore.test.ts | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/lib/savedVideoStore.ts | 32++++++++++++++++++++++++++++++--
Mcommon/lib/storageVolumes.ts | 21+++++++++++++++++----
Meditor/e2e/drive-health.spec.ts | 10+++++++++-
4 files changed, 106 insertions(+), 7 deletions(-)

diff --git a/common/lib/savedVideoStore.test.ts b/common/lib/savedVideoStore.test.ts @@ -166,3 +166,53 @@ async function exists(p: string): Promise<boolean> { return (err as NodeJS.ErrnoException).code === "EISDIR"; } } + +// A STORE ON A DRIVE THAT IS NOT ANSWERING IS NOT WRITTEN (lane drive-stall): +// the corpus store through its link, a channel's own store as given; the +// container stays in the video dir, and nothing touches the stalled drive. +test("a store whose drive is not answering refuses the write, and the container stays put", async () => { + const { symlink } = await import("node:fs/promises"); + const { recordLocationHealth, resetStorageHealth } = await import("./storageHealth"); + const { SavedVideosStoreNotAnsweringError } = await import("./savedVideoStore"); + await withTmp(async (paths, videoDir) => { + const platter = path.join(path.dirname(paths.transcriptsDir), "platter"); + const target = path.join(platter, "saved-videos"); + await mkdir(target, { recursive: true }); + await rm(paths.savedVideosDir, { recursive: true, force: true }); + await symlink(target, paths.savedVideosDir); + const loc = { id: "platter", label: "Platter", root: platter }; + try { + // Answering: the guard passes. + recordLocationHealth(loc, "ok"); + await assertSavedVideosStoreWritable(paths, path.join(paths.savedVideosDir, "chan")); + // Not answering: refused, for the corpus store and for a channel store on it. + recordLocationHealth(loc, "stalled", { cause: "test" }); + await assert.rejects( + assertSavedVideosStoreWritable(paths, path.join(paths.savedVideosDir, "chan")), + (err: unknown) => + err instanceof SavedVideosStoreNotAnsweringError && + /^The saved-video store's drive "Platter" is not answering \(since \d\d:\d\d\)/.test(err.message), + ); + await assert.rejects( + assertSavedVideosStoreWritable(paths, path.join(platter, "own-store")), + SavedVideosStoreNotAnsweringError, + ); + // A store elsewhere is not held by this drive. + await assertSavedVideosStoreWritable(paths, path.join(paths.transcriptsDir, "elsewhere")); + await writeFile(path.join(videoDir, "source-media.mp4"), "container"); + await assert.rejects( + persistSourceVideo({ + videoDir, + sourceFilename: "source-media.mp4", + storeDir: path.join(paths.savedVideosDir, "chan"), + keepReason: "pin", + paths, + }), + SavedVideosStoreNotAnsweringError, + ); + assert.equal(await readFile(path.join(videoDir, "source-media.mp4"), "utf8"), "container"); + } finally { + resetStorageHealth(); + } + }); +}); diff --git a/common/lib/savedVideoStore.ts b/common/lib/savedVideoStore.ts @@ -1,7 +1,8 @@ import path from "node:path"; -import { readFile } from "node:fs/promises"; +import { readFile, readlink } from "node:fs/promises"; import type { Paths } from "./paths"; import type { RelocationMarker } from "./channelMedia"; +import { sinceText, stalledLocationForPath, type LocationHealth } from "./storageHealth"; // IS THE SAVED-VIDEO STORE SAFE TO WRITE INTO RIGHT NOW? // @@ -109,7 +110,34 @@ export async function assertSavedVideosStoreWritable( paths: Pick<Paths, "transcriptsDir" | "savedVideosDir">, storeDir: string, ): Promise<void> { - if (!isInCorpusSavedVideoStore(paths, storeDir)) return; + const corpus = isInCorpusSavedVideoStore(paths, storeDir); + // A STORE ON A DRIVE THAT IS NOT ANSWERING IS NOT WRITTEN (lane drive-stall). + // The move into it is in-process (`moveFileCrossDevice`), and on a stalled + // drive every call of it holds one of Node's file threads until the kernel + // gives up. Memory only: the health record, matched against the store's + // path — a channel's own store as given, the corpus store through its link + // (`readlink` reads the corpus disk, never the target). + const where = corpus + ? await readlink(paths.savedVideosDir).catch(() => paths.savedVideosDir) + : storeDir; + const stall = stalledLocationForPath(where); + if (stall) throw new SavedVideosStoreNotAnsweringError(stall); + if (!corpus) return; const marker = await readSavedVideosMarker(paths); if (marker) throw new SavedVideosStoreInTransitionError(marker); } + +// Thrown by assertSavedVideosStoreWritable when the store's drive is not +// answering. Every persist caller already catches a refusal here and leaves +// the container where it is, to be persisted on a later pass. +export class SavedVideosStoreNotAnsweringError extends Error { + readonly health: LocationHealth; + constructor(health: LocationHealth) { + super( + `The saved-video store's drive "${health.label}" is not answering ` + + `(${sinceText(health.since)}) — nothing is written into it until it answers.`, + ); + this.name = "SavedVideosStoreNotAnsweringError"; + this.health = health; + } +} diff --git a/common/lib/storageVolumes.ts b/common/lib/storageVolumes.ts @@ -768,11 +768,24 @@ export type MemoizedProbe = StorageLocationProbe & { export const PROBE_MEMO_MS = 10_000; type MemoEntry = { root: string; probedAt: number; probe: StorageLocationProbe }; -const probeMemo = new Map<string, MemoEntry>(); + +declare global { + // eslint-disable-next-line no-var + var __yttStorageProbeMemo__: Map<string, MemoEntry> | undefined; +} + +// ON globalThis, the house pattern (lane drive-stall): a page, a poll and the +// e2e `invalidate-cache` route can each be a different copy of this module, +// and a reset in one copy that leaves another's map standing answers the next +// page with a root that is no longer there — for up to ten seconds. +function probeMemo(): Map<string, MemoEntry> { + globalThis.__yttStorageProbeMemo__ ??= new Map(); + return globalThis.__yttStorageProbeMemo__; +} // Test seam, and the escape hatch for a process that has just written a root. export function resetStorageProbeMemo(): void { - probeMemo.clear(); + probeMemo().clear(); } // Probe a location, at most once per PROBE_MEMO_MS. @@ -801,7 +814,7 @@ export async function probeLocationMemo( if (stalledLocation(loc)) { return { status: "stalled", identity: { known: false }, probedAt: now }; } - const hit = probeMemo.get(loc.id); + const hit = probeMemo().get(loc.id); if ( !opts.refresh && hit && @@ -811,6 +824,6 @@ export async function probeLocationMemo( return { ...hit.probe, probedAt: hit.probedAt }; } const probe = await probeLocation(loc, bins, opts); - probeMemo.set(loc.id, { root: loc.root, probedAt: now, probe }); + probeMemo().set(loc.id, { root: loc.root, probedAt: now, probe }); return { ...probe, probedAt: now }; } diff --git a/editor/e2e/drive-health.spec.ts b/editor/e2e/drive-health.spec.ts @@ -84,6 +84,8 @@ test("a stalled drive reads 'not answering' on /storage and the dashboard; an un await expect(cold.getByLabel("location status")).toHaveText("Not answering"); await expect(cold.getByLabel("location drive")).toHaveText(/^not answering since \d\d:\d\d — /); await expect(cold.getByLabel("location slow")).toHaveCount(0); + await page.setViewportSize({ width: 1366, height: 768 }); + await cold.screenshot({ path: testInfo.outputPath("storage-not-answering.png") }); await mark("cold", "stalled"); await page.goto("/"); @@ -95,8 +97,10 @@ test("a stalled drive reads 'not answering' on /storage and the dashboard; an un await expect(page.getByLabel("drive cold health")).toHaveText(/^not answering since \d\d:\d\d/); await expect(card.getByRole("link", { name: "1 channel(s) on it" })).toHaveAttribute( "href", - "/channels?location=cold", + /^\/channels\?location=cold(&|$)/, ); + await page.setViewportSize({ width: 1366, height: 768 }); + await page.screenshot({ path: testInfo.outputPath("dashboard-not-answering.png") }); // --- the drive answers again: no banner ----------------------------------- await fetch(`${baseUrl}/api/test/invalidate-cache`); @@ -132,6 +136,8 @@ test("a slow drive stays Available with a slow chip, and its dashboard card is a await expect(cold.getByLabel("location drive")).toHaveText( /^slow at \d\d:\d\d — a read in the editor took 2.4 s$/, ); + await page.setViewportSize({ width: 1366, height: 768 }); + await cold.screenshot({ path: testInfo.outputPath("storage-slow.png") }); await mark("cold", "slow"); await page.goto("/"); @@ -139,6 +145,8 @@ test("a slow drive stays Available with a slow chip, and its dashboard card is a await expect(card).toHaveAttribute("data-state", "slow"); await expect(card).toHaveAttribute("role", "status"); await expect(card).toContainText("The media drive Cold is answering slowly"); + await page.setViewportSize({ width: 1366, height: 768 }); + await page.screenshot({ path: testInfo.outputPath("dashboard-slow.png") }); // `pnpm ops get storage` reports the same view per location. await mark("cold", "slow");