commit c78931324b69954c71129bd594872bdfad265f6c
parent e215f4fb6ab082702fa94e394afae9cc3ff43744
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 9 Nov 2026 18:51:46 -0500
umtool: per-edit undo points for the app's own process only -- a spawned step keeps the throttle (L3 review 2)
instrumentation.ts set UMTOOL_UNDO_EVERY_MS=0 in process.env, and lib/jobs.ts
passes process.env to every step it spawns: a queued `umtool window --align`
over 150 clips took 150 auto-before-trim points and pruning at 200 ate the
operator's own. The throttle is a process global now (manifest.mjs
setUndoEveryMs, Symbol.for("umtool.undoEveryMs")), set by instrumentation for
the server alone; a child reads the terminal's two minutes. Unit test spawns a
child with the app's env and reads 120000.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
4 files changed, 37 insertions(+), 17 deletions(-)
diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md
@@ -628,7 +628,7 @@ expected the cut). A take is a **saved version** — FROZEN:
was rendered from (as `takes pick` copies it). Opening the draft's own parent with no edits writes nothing — its
Open in draft page goes straight on (308) to the draft's bench.
- **One undo stack.** In the app every edit is its own undo point (`revisions/<stamp>-auto-before-<op>`, the server
- runs with `UMTOOL_UNDO_EVERY_MS=0`) — a clip's edges included (`auto-before-trim`) — so two trims a minute apart
+ process sets it for itself at boot — a step it spawns keeps the terminal's throttle) — a clip's edges included (`auto-before-trim`) — so two trims a minute apart
are two **Undo last edit**s; from a terminal the old throttle stands (one per op every two minutes, so an agent's
burst is one step back). Two undo points in one second are two files (the stamp gains its milliseconds,
`20261109-143012.457-auto-before-trim`), and only the newest 200 `auto-before-*` are kept. A verdict alone is not an
diff --git a/umtool/instrumentation.ts b/umtool/instrumentation.ts
@@ -1,5 +1,5 @@
// Next.js instrumentation hook: register() runs once when the server starts.
-// It says every app edit is its own undo point (UMTOOL_UNDO_EVERY_MS=0), and
+// It says every app edit is its own undo point (manifest.mjs setUndoEveryMs), and
// umtool arms ONE thing here, the durable queue's runner (lib/queue/runner.ts),
// so the steps an agent queued (`umtool queue add`) run in the app -- the live
// unit -- and survive the session that queued them. A step that was running
@@ -14,8 +14,14 @@ import { isIdleBoot } from "yt-dlp-transcript-common/lib/idleBoot";
export async function register() {
if (process.env.NEXT_RUNTIME !== "nodejs") return;
// ONE UNDO STACK (umtool redesign L3): every edit made in the app is its own undo point (lib/report/manifest.mjs
- // autoSnapshot; a terminal keeps the two-minute throttle). Set before anything else, idle boot included.
- process.env.UMTOOL_UNDO_EVERY_MS ??= "0";
+ // autoSnapshot; a terminal keeps the two-minute throttle). A process global, not the environment: the steps
+ // the app spawns (lib/jobs.ts) must keep the terminal's throttle. Set before anything else, idle boot included.
+ try {
+ const { setUndoEveryMs } = await import("./lib/report/manifest.mjs");
+ setUndoEveryMs(0);
+ } catch (e) {
+ console.error(`umtool: per-edit undo points not set: ${e instanceof Error ? e.message : String(e)}`);
+ }
if (isIdleBoot()) return;
try {
const { queueRunnerEnabled, startQueueRunner } = await import("./lib/queue/runner");
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -2087,7 +2087,8 @@ const ARTICLE_SEGMENT_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
// restores the newest of those.
//
// ONE UNDO STACK (umtool redesign L3, S5): in the APP every op takes its own
-// undo point (`every: 0` -- instrumentation.ts sets UMTOOL_UNDO_EVERY_MS=0),
+// undo point (`every: 0` -- instrumentation.ts calls setUndoEveryMs(0) for the
+// app's own process; a step it spawns keeps the terminal's throttle),
// so two trims a minute apart are two Undos; from a terminal the old throttle
// stands (at most one per op every two minutes: an agent's burst is one step
// back). Two in one second are two files (snapshots.mjs stamps the
@@ -2105,14 +2106,23 @@ const ARTICLE_SEGMENT_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
// ---------------------------------------------------------------------------
export const AUTO_SNAPSHOT_PREFIX = "auto-before-";
-/** The terminal's throttle; the app runs with UMTOOL_UNDO_EVERY_MS=0 (every op its own undo point). */
+/** The terminal's throttle; the app sets it to 0 for its own process (every op its own undo point). */
const AUTO_SNAPSHOT_EVERY_MS = 2 * 60 * 1000;
+/**
+ * The undo-point throttle of THIS process (instrumentation.ts sets 0 in the app). A process global, never an
+ * environment variable: a step the app spawns (lib/jobs.ts, a queued `umtool window --align` over 150 clips)
+ * must keep the terminal's throttle, or its burst would take 150 undo points and prune the operator's own.
+ */
+export const UNDO_EVERY_KEY = Symbol.for("umtool.undoEveryMs");
+/** @param {number | null} ms */
+export function setUndoEveryMs(ms) {
+ /** @type {any} */ (globalThis)[UNDO_EVERY_KEY] = ms;
+}
/** The undo points kept: the newest this many `auto-before-*` snapshots (older ones are pruned). */
export const AUTO_SNAPSHOT_KEEP = 200;
-const undoEveryMs = () => {
- const raw = process.env.UMTOOL_UNDO_EVERY_MS;
- const n = raw === undefined || raw === "" ? NaN : Number(raw);
- return Number.isFinite(n) && n >= 0 ? n : AUTO_SNAPSHOT_EVERY_MS;
+export const undoEveryMs = () => {
+ const n = /** @type {any} */ (globalThis)[UNDO_EVERY_KEY];
+ return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : AUTO_SNAPSHOT_EVERY_MS;
};
const ENTRY_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
diff --git a/umtool/lib/report/versions.test.mjs b/umtool/lib/report/versions.test.mjs
@@ -9,6 +9,7 @@ import { mkdir, mkdtemp, readdir, readFile, rm, stat, writeFile } from "node:fs/
import { tmpdir } from "node:os";
import path from "node:path";
import test from "node:test";
+import { spawnSync } from "node:child_process";
import { freezeTakes, nextVersionId, openVersion, readDraft, saveVersion } from "./versions.mjs";
import { composeTake, checkSpec, makeTake, pickTake } from "./takeMaker.mjs";
@@ -259,13 +260,13 @@ test("umtool takes save | open | freeze, with --json", async () => {
}
});
-test("one undo stack: in the app (UMTOOL_UNDO_EVERY_MS=0) two trims a moment apart are two undo points, undone one by one; the terminal keeps the throttle", async () => {
+test("one undo stack: in the app (setUndoEveryMs(0)) two trims a moment apart are two undo points, undone one by one; the terminal -- and a step the app spawns -- keeps the throttle", async () => {
const { root, dir } = await project();
- const was = process.env.UMTOOL_UNDO_EVERY_MS;
+ const { setUndoEveryMs } = await import("./manifest.mjs");
try {
const t0 = await text(dir);
- // The terminal (no env): the second trim of a burst takes no undo point of its own.
- delete process.env.UMTOOL_UNDO_EVERY_MS;
+ // The terminal: the second trim of a burst takes no undo point of its own.
+ setUndoEveryMs(null);
const a = await updateClip(dir, "a", { end: 9 });
const b = await updateClip(dir, "a", { end: 8 });
assert.equal(a.snapshot?.skipped, false);
@@ -273,7 +274,11 @@ test("one undo stack: in the app (UMTOOL_UNDO_EVERY_MS=0) two trims a moment apa
await writeFile(path.join(dir, "video.manifest.json"), t0);
await rm(path.join(dir, "revisions"), { recursive: true, force: true });
// The app: each its own.
- process.env.UMTOOL_UNDO_EVERY_MS = "0";
+ setUndoEveryMs(0);
+ // ...and a child process the app spawns (lib/jobs.ts passes process.env) does NOT inherit it.
+ assert.equal(process.env.UMTOOL_UNDO_EVERY_MS, undefined);
+ const child = spawnSync(process.execPath, ["--input-type=module", "-e", `import("${new URL("./manifest.mjs", import.meta.url).href}").then((m) => console.log(m.undoEveryMs()))`], { env: process.env, encoding: "utf8" });
+ assert.equal(child.stdout.trim(), "120000", child.stderr);
await updateClip(dir, "a", { end: 9 });
const t1 = await text(dir);
await updateClip(dir, "a", { end: 8 });
@@ -287,8 +292,7 @@ test("one undo stack: in the app (UMTOOL_UNDO_EVERY_MS=0) two trims a moment apa
await undoStructural(dir);
assert.equal(JSON.parse(await text(dir)).timeline[0].end, 10);
} finally {
- if (was === undefined) delete process.env.UMTOOL_UNDO_EVERY_MS;
- else process.env.UMTOOL_UNDO_EVERY_MS = was;
+ setUndoEveryMs(null);
await rm(root, { recursive: true, force: true });
}
});