commit 7dcdc8e8ead45503b2033b4cc0729b9f87264d12
parent 1bd6c781cdeccb73d120d8936f81f23112efae27
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 17 Nov 2026 22:33:50 -0500
the shared walk's memo is timed from when the walk finished -- timed from its start, a walk slower than the memo was stale on arrival, so every stage of one slow page walked again in turn (the home data: 9 walks, now 4, one at a time); `since` still compares when a walk started
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
2 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/umtool/lib/projects/sharedWalkMemo.test.mjs b/umtool/lib/projects/sharedWalkMemo.test.mjs
@@ -0,0 +1,39 @@
+// The shared walk's memo is timed from when the walk FINISHED: a walk slower than the memo still answers the
+// caller that asks right after it lands (timed from its start, every stage of a slow page walked again in turn).
+import "../report/noLiveEditor.mjs";
+import assert from "node:assert/strict";
+import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
+import os from "node:os";
+import path from "node:path";
+import test from "node:test";
+import { forgetSharedWalks, sharedWalk, walkStats } from "./walk.mjs";
+
+test("a walk slower than the memo answers the next caller; `since` still asks for a fresh one", async () => {
+ const root = await mkdtemp(path.join(os.tmpdir(), "shared-walk-memo-"));
+ try {
+ for (let i = 0; i < 600; i += 1) {
+ const dir = path.join(root, `group-${i % 20}`, `piece-${i}`);
+ await mkdir(dir, { recursive: true });
+ await writeFile(path.join(dir, "video.manifest.json"), "{}");
+ }
+ forgetSharedWalks();
+ // A memo shorter than the walk takes: find one by measuring.
+ const t0 = Date.now();
+ await sharedWalk(root, { memoMs: 0 });
+ const took = Date.now() - t0;
+ const memoMs = Math.max(5, Math.floor(took / 2));
+ forgetSharedWalks();
+ const before = walkStats.calls;
+ const a = await sharedWalk(root, { memoMs });
+ const b = await sharedWalk(root, { memoMs });
+ assert.equal(walkStats.calls - before, 1, `one walk for two callers in turn (walk ${took} ms, memo ${memoMs} ms)`);
+ assert.equal(a, b);
+ const asked = Date.now() + 1;
+ await new Promise((r) => setTimeout(r, 2));
+ await sharedWalk(root, { memoMs: 60_000, since: asked });
+ assert.equal(walkStats.calls - before, 2, "a caller that needs a walk begun after it asked gets a fresh one");
+ } finally {
+ forgetSharedWalks();
+ await rm(root, { recursive: true, force: true });
+ }
+});
diff --git a/umtool/lib/projects/walk.mjs b/umtool/lib/projects/walk.mjs
@@ -210,7 +210,7 @@ export function collapseFolders(nodes) {
/**
* ONE WALK AT A TIME PER ROOT, shared (the regression of 17 Nov 2026: hundreds of walks of the reports root in flight
- * at once, one per request or per card). A walk younger than `memoMs` answers; else the walk running now is shared by
+ * at once, one per request or per card). A walk that finished less than `memoMs` ago answers; else the walk running now is shared by
* every caller while it runs; else a new one is started, which every later caller shares. `since`: only a walk that
* STARTED at or after it will do (a lookup that missed asks again with the time it asked: one fresh walk for any
* number of misses, never one each). The state is on globalThis: Next bundles each route on its own, and a
@@ -223,11 +223,13 @@ export function sharedWalk(root, { since = 0, memoMs = 1000 } = {}) {
const all = (globalThis.__umtoolSharedWalks ??= new Map());
const st = all.get(root) ?? { memo: null, inflight: null };
all.set(root, st);
- if (st.memo && Date.now() - st.memo.at < memoMs && st.memo.at >= since) return Promise.resolve(st.memo.refs);
+ // Fresh for `memoMs` after the walk FINISHED (a walk slower than the memo is still an answer when it lands: timed
+ // from its start, every stage of one slow page walked again in turn); `since` compares when it STARTED.
+ if (st.memo && Date.now() - st.memo.done < memoMs && st.memo.at >= since) return Promise.resolve(st.memo.refs);
if (st.inflight && st.inflight.started >= since) return st.inflight.refs;
const started = Date.now();
const refs = walkProjects(root).then((got) => {
- if (!st.memo || st.memo.at <= started) st.memo = { at: started, refs: got };
+ if (!st.memo || st.memo.at <= started) st.memo = { at: started, done: Date.now(), refs: got };
return got;
}).finally(() => {
if (st.inflight?.refs === refs) st.inflight = null;