commit 9a37d40a19cf205fd296f810909f2bfd858229c7
parent 75ed2641481dae9b665474ea2189fa82aaa1823e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 1 Nov 2026 23:44:19 -0500
umtool deck: an edit made while a save re-reads the deck is kept -- the claims and markers editors count their edits, and the saved value replaces the rows (and a save's end clears "unsaved") only when no edit came after the save was sent. deck-claims.spec.ts:27 timed out at 2.6 min in a loaded full run: the PUT wrote the file, the spec's next Remove landed before the re-read (GET /api/report/chrome, then the recompose), the re-read put the old claims back and cleared dirty, and Save stayed disabled until the test's timeout. A real race, not starvation alone; the spec now holds the re-read until the next edit is made, and asserts the edit stands
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 64 insertions(+), 10 deletions(-)
diff --git a/umtool/components/projects/DeckClaimsEditor.tsx b/umtool/components/projects/DeckClaimsEditor.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useEffect, useMemo, useState } from "react";
+import { useEffect, useMemo, useRef, useState } from "react";
import { buttonVariants } from "@/components/ui/button";
import { DECK_CLAIM_LIMITS, DECK_CLAIM_OPS, DECK_CLAIM_PERS, deckClaimShapeErrors } from "umtool-report-to-video/claims";
@@ -111,17 +111,35 @@ export default function DeckClaimsEditor({
const savedKey = JSON.stringify(claims);
const [rows, setRows] = useState<Row[]>(() => claims.map(rowOf));
const [dirty, setDirty] = useState(false);
+ // Every edit is counted; `saved` is the count the last save was sent at (-1: none is in
+ // hand -- a save refused, or edits never saved). A save re-reads the deck after it writes
+ // (and recomposes the preview: seconds, on a busy machine), and an edit made meanwhile is
+ // the operator's: the saved value arriving after it must not put the old claims back,
+ // nor the save's end mark it saved.
+ const edits = useRef(0);
+ const saved = useRef(0);
useEffect(() => {
+ // The saved value, by its text: a re-read with the same claims keeps the edits; another
+ // value replaces the rows only when it accounts for every edit made (none since the save).
+ if (edits.current !== saved.current) return;
setRows(claims.map(rowOf));
setDirty(false);
- // The saved value, by its text: a re-read with the same claims keeps the edits.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [savedKey]);
const change = (next: Row[]) => {
+ edits.current += 1;
setRows(next);
setDirty(true);
};
+ const onSave = () => {
+ const at = edits.current;
+ saved.current = at;
+ void save(list.length ? list : null).then((ok) => {
+ if (!ok) saved.current = -1;
+ else if (edits.current === at) setDirty(false);
+ });
+ };
const put = (i: number, patch: Partial<CountRow> | Partial<GoalRow>) => change(rows.map((r, j) => (j === i ? ({ ...r, ...patch } as Row) : r)));
const putStep = (i: number, k: number, patch: Partial<Step>) =>
change(rows.map((r, j) => (j === i && r.kind === "goalpost" ? { ...r, steps: r.steps.map((s, m) => (m === k ? { ...s, ...patch } : s)) } : r)));
@@ -197,7 +215,7 @@ export default function DeckClaimsEditor({
type="button"
data-testid="claims-save"
disabled={busy || !dirty || problems.length > 0}
- onClick={() => void save(list.length ? list : null).then((ok) => ok && setDirty(false))}
+ onClick={onSave}
className={`${buttonVariants({ variant: "outline", size: "sm" })} ml-auto`}
>
save claims
diff --git a/umtool/components/projects/MarkersEditor.tsx b/umtool/components/projects/MarkersEditor.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useEffect, useState } from "react";
+import { useEffect, useRef, useState } from "react";
import { MARKER_LIMITS } from "umtool-report-to-video/marker-limits";
import { buttonVariants } from "@/components/ui/button";
@@ -72,17 +72,34 @@ export default function MarkersEditor({
const [rows, setRows] = useState<Row[]>(() => markers.map(rowOf));
const [layout, setLayout] = useState(markerLayout ?? "");
const [dirty, setDirty] = useState(false);
+ // An edit made while a save re-reads the deck is kept (DeckClaimsEditor.tsx, the same rule):
+ // edits are counted, and the saved value replaces the rows only when it accounts for all of them.
+ const edits = useRef(0);
+ const saved = useRef(0);
useEffect(() => {
+ // The saved value, by its text: a re-read with the same markers keeps the edits.
+ if (edits.current !== saved.current) return;
setRows(markers.map(rowOf));
setLayout(markerLayout ?? "");
setDirty(false);
- // The saved value, by its text: a re-read with the same markers keeps the edits.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [savedKey]);
+ const edited = () => {
+ edits.current += 1;
+ setDirty(true);
+ };
const change = (next: Row[]) => {
setRows(next);
- setDirty(true);
+ edited();
+ };
+ const onSave = () => {
+ const at = edits.current;
+ saved.current = at;
+ void save({ markers: rows.map(markerOf), markerLayout: layout || null }).then((ok) => {
+ if (!ok) saved.current = -1;
+ else if (edits.current === at) setDirty(false);
+ });
};
const put = (i: number, patch: Partial<Row>) => change(rows.map((r, j) => (j === i ? { ...r, ...patch } : r)));
const move = (i: number, d: number) => {
@@ -119,7 +136,7 @@ export default function MarkersEditor({
value={layout}
onChange={(e) => {
setLayout(e.target.value);
- setDirty(true);
+ edited();
}}
className={input}
>
@@ -138,7 +155,7 @@ export default function MarkersEditor({
type="button"
data-testid="markers-save"
disabled={busy || !dirty || labelLong || leadSub >= 0 || rows.some((r) => !r.label.trim() || !r.after)}
- onClick={() => void save({ markers: rows.map(markerOf), markerLayout: layout || null }).then((ok) => ok && setDirty(false))}
+ onClick={onSave}
className={`${buttonVariants({ variant: "outline", size: "sm" })} ml-auto`}
>
save markers
diff --git a/umtool/e2e/deck-claims.spec.ts b/umtool/e2e/deck-claims.spec.ts
@@ -110,12 +110,31 @@ test("the claims editor: a count and a goalpost -- validated as typed, the playh
await page.getByTestId("claim-per-0").selectOption("P1W");
await page.getByTestId("claim-remove-0").click();
await page.getByTestId("claim-step-remove-0-0").click();
+ // The save's re-read of the deck (GET /api/report/chrome) held until the next edit is made:
+ // the file is written at once, and an edit made while the editor reads it back is the
+ // operator's -- the saved value arriving after it must not put the old claims back, nor
+ // the save's end mark it saved. (Under a loaded machine the re-read and the recompose
+ // after it are seconds; an edit there used to be lost and Save stay disabled.)
+ let release!: () => void;
+ const reread = new Promise<void>((r) => (release = r));
+ await page.route(
+ (u) => u.pathname === "/api/report/chrome",
+ async (route) => {
+ if (route.request().method() === "GET") await reread;
+ await route.continue();
+ },
+ );
await page.getByTestId("claims-save").click();
await expect.poll(() => claims()).toEqual([
{ kind: "goalpost", label: "Pill test results", steps: [{ at: "c02", t: 10, said: "“6–8 weeks”", from: "2026-10-15", due: ["P6W", "P8W"] }] },
]);
- // Removing the last claim removes the key.
+ // Removing the last claim removes the key -- removed while the save is still reading back.
await page.getByTestId("claim-remove-0").click();
- await page.getByTestId("claims-save").click();
+ release();
+ await expect(page.getByTestId("onscreen-note")).toHaveText("saved 1 claim check", { timeout: 30_000 });
+ // The edit stands: no claim left, unsaved.
+ await expect(ed).toContainText(/(^|\D)0 of \d/);
+ await expect(ed).toContainText("unsaved");
+ await page.getByTestId("claims-save").click({ timeout: 15_000 });
await expect.poll(() => readManifest().render.chrome?.deck && "claims" in readManifest().render.chrome!.deck!).toBe(false);
});