commit 9817f784ff12c40b25cef45bbe1ef5f8e52fe298
parent 05426df1db4531d6864f5008f35c16f08d1d7579
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 18 Nov 2026 02:01:56 -0500
umtool: the home page's shell is sent at once; the Inbox streams in
The page awaited the whole Inbox read (every project's open decisions,
the piece graph, the lifecycle, the mutes, the machine's calls, each
card's play link) before its first byte. It starts the read now and the
rail, the header, Quick clip, what is running and the recent cuts are
sent at once; the count and the cards stream in behind a placeholder,
and the header's Muted / Show hidden toggles with them. One read per
request, shared by the three places that draw it.
streaming.spec: the shell arrives while the Inbox is held back (a
test-server cookie, lib/streamDelay.ts, inert without
E2E_UMTOOL_STREAM_DELAY=1); the Inbox starts where its placeholder did;
a refresh brings no placeholder back; the console stays clean.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
4 files changed, 276 insertions(+), 49 deletions(-)
diff --git a/umtool/app/page.tsx b/umtool/app/page.tsx
@@ -1,3 +1,4 @@
+import { cache, Suspense } from "react";
import Link from "next/link";
import InboxList, { type InboxCard, type InboxGroup } from "@/components/inbox/InboxList";
import { UndoBar } from "@/components/piece/Lifecycle";
@@ -19,6 +20,7 @@ import RunningList from "@/components/shell/RunningList";
import RecentCuts from "@/components/shell/RecentCuts";
import { initialRunning } from "@/lib/activity";
import { projectRefs } from "@/lib/projects";
+import { e2eStreamDelay } from "@/lib/streamDelay";
export const dynamic = "force-dynamic";
@@ -96,12 +98,15 @@ function hiddenCards(items: Decision[], keep: (d: Decision) => boolean, lifeOf:
);
}
-export default async function Inbox({
- searchParams,
-}: {
- searchParams: Promise<{ hidden?: string; muted?: string }>;
-}) {
- const { hidden: showHidden, muted: showMuted } = await searchParams;
+// EVERYTHING THE INBOX READS — every project's open decisions, the piece
+// graph, the lifecycle, the mutes, the machine's calls, each card's play link.
+// It is the slow part of this page (seconds on a few hundred projects, more on
+// a busy machine), so the page starts it and does not await it: the shell —
+// the rail, the header, Quick clip, what is running, the recent cuts — is sent
+// at once and the Inbox streams in behind a placeholder. One read per request,
+// shared by the three places that draw it.
+const loadInbox = cache(async (showHidden: boolean, showMuted: boolean) => {
+ await e2eStreamDelay();
// settings.privacy.hidePrivateSites: the private sites' cards are left out.
const inbox = await readInbox({ hide: await privateFilter() });
const lifeOf = new Map<string, LifecycleState>();
@@ -143,6 +148,113 @@ export default async function Inbox({
const refs = await projectRefs();
await Promise.all(all.flatMap((g) => g.cards.map(async (c) => (c.play = await playHrefOfPiece(c.piece, c.action.href, refs)))));
+ return { inbox, all, head, parkedN };
+});
+
+type InboxView = ReturnType<typeof loadInbox>;
+
+// The header's two toggles: how many decisions are muted, how many hidden.
+async function InboxToggles({ view, showHidden, showMuted }: { view: InboxView; showHidden: boolean; showMuted: boolean }) {
+ const { inbox, parkedN } = await view;
+ return (
+ <>
+ {inbox.muted > 0 && (
+ <Link
+ href={homeHref({ muted: !showMuted, hidden: showHidden })}
+ prefetch={false}
+ data-show-muted={showMuted ? "1" : "0"}
+ aria-pressed={showMuted}
+ className={buttonVariants({ variant: "quiet", size: "md" })}
+ >
+ {showMuted ? "Hide muted" : `Muted ${inbox.muted}`}
+ </Link>
+ )}
+ {parkedN > 0 && (
+ <Link
+ href={homeHref({ hidden: !showHidden, muted: showMuted })}
+ prefetch={false}
+ data-show-hidden={showHidden ? "1" : "0"}
+ aria-pressed={showHidden}
+ className={buttonVariants({ variant: "quiet", size: "md" })}
+ >
+ {showHidden ? "Hide hidden" : `Show hidden ${parkedN}`}
+ </Link>
+ )}
+ </>
+ );
+}
+
+async function InboxErrors({ view }: { view: InboxView }) {
+ const { inbox } = await view;
+ return (
+ <>
+ {inbox.lifecycleError && (
+ <p role="alert" className="mb-3 text-[12.5px] text-reject-text">
+ {inbox.lifecycleError} — every piece reads as active until it is fixed.
+ </p>
+ )}
+ {inbox.mutesError && (
+ <p role="alert" className="mb-3 text-[12.5px] text-reject-text">
+ {inbox.mutesError} — nothing reads as muted until it is fixed.
+ </p>
+ )}
+ </>
+ );
+}
+
+// The count and the cards.
+async function InboxBody({ view }: { view: InboxView }) {
+ const { all, head } = await view;
+ return (
+ <div data-stream-filled="inbox">
+ <div className="mb-1 mt-1 flex items-end gap-3.5" data-inbox-count={head.calls}>
+ <span className="display text-[72px] font-[850] leading-[0.8]">{head.calls}</span>
+ <span className="pb-0.5 text-[13px] text-text-2">
+ {head.calls === 1 ? "call waiting on you" : "calls waiting on you"}
+ <small className="block text-[12px] text-muted" data-inbox-note="">
+ {headlineNote(head)}
+ </small>
+ </span>
+ </div>
+
+ <InboxList groups={all} />
+ </div>
+ );
+}
+
+// What holds the Inbox's place: the count's line at its real size, and a few
+// card-shaped rows. Nothing sits below the Inbox in its column, so its height
+// is open: only where it starts and how wide it is must not move.
+function InboxPlaceholder() {
+ return (
+ <div data-stream-skeleton="inbox" aria-hidden="true">
+ {/* The count's line, at its real size, with nothing to read in it. */}
+ <div className="mb-1 mt-1 flex items-end gap-3.5">
+ <span className="display animate-pulse rounded-md bg-panel text-[72px] font-[850] leading-[0.8] text-transparent">0</span>
+ <span className="pb-0.5 text-[13px] text-transparent">
+ calls waiting on you
+ <small className="block text-[12px]"> </small>
+ </span>
+ </div>
+ <div className="mt-4 space-y-2">
+ {[0, 1, 2, 3].map((n) => (
+ <div key={n} className="h-[58px] animate-pulse rounded-md border border-seam bg-panel" />
+ ))}
+ </div>
+ </div>
+ );
+}
+
+export default async function Inbox({
+ searchParams,
+}: {
+ searchParams: Promise<{ hidden?: string; muted?: string }>;
+}) {
+ const sp = await searchParams;
+ const showHidden = !!sp.hidden;
+ const showMuted = !!sp.muted;
+ const view = loadInbox(showHidden, showMuted);
+
return (
<div className="flex h-full flex-col">
<AppShell
@@ -151,57 +263,23 @@ export default async function Inbox({
actions={
<>
<ResumeChip />
- {inbox.muted > 0 && (
- <Link
- href={homeHref({ muted: !showMuted, hidden: !!showHidden })}
- prefetch={false}
- data-show-muted={showMuted ? "1" : "0"}
- aria-pressed={!!showMuted}
- className={buttonVariants({ variant: "quiet", size: "md" })}
- >
- {showMuted ? "Hide muted" : `Muted ${inbox.muted}`}
- </Link>
- )}
- {parkedN > 0 && (
- <Link
- href={homeHref({ hidden: !showHidden, muted: !!showMuted })}
- prefetch={false}
- data-show-hidden={showHidden ? "1" : "0"}
- aria-pressed={!!showHidden}
- className={buttonVariants({ variant: "quiet", size: "md" })}
- >
- {showHidden ? "Hide hidden" : `Show hidden ${parkedN}`}
- </Link>
- )}
+ <Suspense fallback={null}>
+ <InboxToggles view={view} showHidden={showHidden} showMuted={showMuted} />
+ </Suspense>
</>
}
/>
<main className="deck-main flex-1 px-4 pb-6 pt-4">
- {inbox.lifecycleError && (
- <p role="alert" className="mb-3 text-[12.5px] text-reject-text">
- {inbox.lifecycleError} — every piece reads as active until it is fixed.
- </p>
- )}
- {inbox.mutesError && (
- <p role="alert" className="mb-3 text-[12.5px] text-reject-text">
- {inbox.mutesError} — nothing reads as muted until it is fixed.
- </p>
- )}
+ <Suspense fallback={null}>
+ <InboxErrors view={view} />
+ </Suspense>
<div className="grid gap-x-6 gap-y-5 min-[1280px]:grid-cols-[minmax(0,1fr)_300px]">
<div className="min-w-0">
- <div className="mb-1 mt-1 flex items-end gap-3.5" data-inbox-count={head.calls}>
- <span className="display text-[72px] font-[850] leading-[0.8]">{head.calls}</span>
- <span className="pb-0.5 text-[13px] text-text-2">
- {head.calls === 1 ? "call waiting on you" : "calls waiting on you"}
- <small className="block text-[12px] text-muted" data-inbox-note="">
- {headlineNote(head)}
- </small>
- </span>
- </div>
-
- <InboxList groups={all} />
+ <Suspense fallback={<InboxPlaceholder />}>
+ <InboxBody view={view} />
+ </Suspense>
</div>
<aside data-home-aside="" className="min-w-0 space-y-4 min-[1280px]:sticky min-[1280px]:top-4 min-[1280px]:self-start">
<QuickClip />
diff --git a/umtool/e2e/streaming.spec.ts b/umtool/e2e/streaming.spec.ts
@@ -0,0 +1,120 @@
+import { test, expect, type Page } from "@playwright/test";
+import * as urls from "./urls";
+import { warm, WARM_TIMEOUT } from "./warm";
+
+// ---------------------------------------------------------------------------
+// THE HOME PAGE STREAMS. Its shell — the rail, the header, Quick clip, what is
+// running, the recent cuts — is sent at once, and the Inbox (every project's
+// open decisions: the slow read) when it is done, behind a placeholder.
+//
+// Against the fixture that read is over in milliseconds, so the app server
+// honours a cookie (lib/streamDelay.ts; E2E_UMTOOL_STREAM_DELAY, set by
+// playwright.config.ts) that holds the Inbox back. With it:
+// 1. the shell is in the document before the Inbox is;
+// 2. the Inbox starts where its placeholder started, at its width (nothing
+// sits below it in its column, so its height is open);
+// 3. a refresh never brings the placeholder back.
+// WRITES the fixture's REPORTS_ROOT/.umtool/lifecycle.json (zeta parked, then
+// active again), as inbox.spec does.
+// ---------------------------------------------------------------------------
+
+// A piece with open calls in the fixture (inbox.spec parks the same one).
+const ZETA = "a:articles/zeta";
+const DELAY_MS = 1500;
+const TOLERANCE_PX = 4;
+
+async function holdInbox(page: Page, baseURL: string) {
+ await page.context().addCookies([{ name: "e2e-stream-delay", value: String(DELAY_MS), url: baseURL }]);
+}
+
+function watchConsole(page: Page): string[] {
+ const problems: string[] = [];
+ page.on("console", (m) => {
+ if (m.type() === "error") problems.push(m.text());
+ });
+ page.on("pageerror", (e) => problems.push(String(e)));
+ return problems;
+}
+
+test.beforeAll(async ({ playwright }) => {
+ test.setTimeout(WARM_TIMEOUT);
+ await warm(playwright, ["/"]);
+});
+
+test("the shell is sent before the Inbox", async ({ baseURL }) => {
+ const started = Date.now();
+ const res = await fetch(baseURL + urls.homeHref(), {
+ headers: { "Accept-Encoding": "identity", Cookie: `e2e-stream-delay=${DELAY_MS}` },
+ });
+ expect(res.status).toBe(200);
+ const reader = res.body!.getReader();
+ const decoder = new TextDecoder();
+ let html = "";
+ let shellAt = -1;
+ let shell = "";
+ for (;;) {
+ const { done, value } = await reader.read();
+ if (done) break;
+ html += decoder.decode(value, { stream: true });
+ if (shellAt < 0 && html.includes('data-stream-skeleton="inbox"')) {
+ shellAt = Date.now() - started;
+ shell = html;
+ }
+ }
+ expect(shellAt, "the placeholder never arrived").toBeGreaterThanOrEqual(0);
+ expect(shellAt, `shell at ${shellAt}ms`).toBeLessThan(DELAY_MS);
+ expect(Date.now() - started).toBeGreaterThanOrEqual(DELAY_MS);
+ // The shell: the rail and the aside are there; the count is not yet.
+ expect(shell).toContain("data-app-rail");
+ expect(shell).toContain("data-home-aside");
+ expect(shell).not.toContain("data-inbox-count");
+ expect(html).toContain("data-inbox-count");
+ expect(html).toContain('data-stream-filled="inbox"');
+});
+
+test("the Inbox starts where its placeholder did, and a refresh never brings the placeholder back", async ({ page, request, baseURL }) => {
+ const problems = watchConsole(page);
+ await holdInbox(page, baseURL!);
+ await page.goto(urls.homeHref(), { waitUntil: "commit" });
+ const placeholder = page.locator('[data-stream-skeleton="inbox"]');
+ await expect(placeholder).toBeVisible();
+ // The shell is usable while the Inbox is still being read.
+ await expect(page.locator("[data-app-rail] [data-place=inbox]")).toBeVisible();
+ await expect(page.locator("[data-home-aside]")).toBeVisible();
+ const before = (await placeholder.boundingBox())!;
+
+ const filled = page.locator('[data-stream-filled="inbox"]');
+ await expect(filled).toBeVisible({ timeout: 20_000 });
+ await expect(page.locator("[data-stream-skeleton]")).toHaveCount(0);
+ await expect(page.locator("[data-inbox-count]")).toBeVisible();
+ const after = (await filled.boundingBox())!;
+ const say = `placeholder ${JSON.stringify(before)} filled ${JSON.stringify(after)}`;
+ expect(Math.abs(after.x - before.x), say).toBeLessThanOrEqual(TOLERANCE_PX);
+ expect(Math.abs(after.y - before.y), say).toBeLessThanOrEqual(TOLERANCE_PX);
+ expect(Math.abs(after.width - before.width), say).toBeLessThanOrEqual(TOLERANCE_PX);
+ // The count's line is the placeholder's first line, to the pixel row.
+ const line = (await page.locator("[data-inbox-count]").boundingBox())!;
+ expect(Math.abs(line.y - before.y), say).toBeLessThanOrEqual(TOLERANCE_PX);
+
+ // A refresh, with the Inbox held back again: the list on screen stays until
+ // the new one is ready. A piece is parked out of band so the refresh has
+ // something to bring in — the count moving is the proof that it landed.
+ const count = page.locator("[data-inbox-count]");
+ const was = await count.getAttribute("data-inbox-count");
+ await page.evaluate(() => {
+ const w = window as unknown as { __skeletons: number };
+ w.__skeletons = 0;
+ new MutationObserver(() => {
+ w.__skeletons += document.querySelectorAll("[data-stream-skeleton]").length;
+ }).observe(document.body, { childList: true, subtree: true });
+ });
+ try {
+ expect((await request.post("/api/pieces/lifecycle", { data: { piece: ZETA, state: "parked" } })).status()).toBe(200);
+ await page.evaluate(() => (window as unknown as { next: { router: { refresh(): void } } }).next.router.refresh());
+ await expect(count).not.toHaveAttribute("data-inbox-count", was!, { timeout: 20_000 });
+ expect(await page.evaluate(() => (window as unknown as { __skeletons: number }).__skeletons)).toBe(0);
+ } finally {
+ await request.post("/api/pieces/lifecycle", { data: { piece: ZETA, state: "active" } });
+ }
+ expect(problems, problems.join("\n")).toEqual([]);
+});
diff --git a/umtool/lib/streamDelay.ts b/umtool/lib/streamDelay.ts
@@ -0,0 +1,21 @@
+import { cookies } from "next/headers";
+
+// A TEST SERVER'S WAY TO HOLD A STREAMED SECTION BACK (the Inbox, app/page.tsx).
+//
+// The home page sends its shell first and the Inbox when its read is done.
+// Against the e2e fixture that read is over in milliseconds, so a spec could
+// never see the placeholder, or prove a refresh does not bring it back. A spec
+// sets this cookie to a number of milliseconds and the Inbox waits that long
+// before it reads.
+//
+// INERT OUTSIDE THE E2E SERVER: without E2E_UMTOOL_STREAM_DELAY=1 (set by
+// playwright.config.ts on the app server only) the cookie is not even read.
+export const STREAM_DELAY_COOKIE = "e2e-stream-delay";
+const MAX_DELAY_MS = 5_000;
+
+export async function e2eStreamDelay(): Promise<void> {
+ if (process.env.E2E_UMTOOL_STREAM_DELAY !== "1") return;
+ const raw = (await cookies()).get(STREAM_DELAY_COOKIE)?.value;
+ const ms = Math.min(Number(raw) || 0, MAX_DELAY_MS);
+ if (ms > 0) await new Promise((resolve) => setTimeout(resolve, ms));
+}
diff --git a/umtool/playwright.config.ts b/umtool/playwright.config.ts
@@ -52,6 +52,11 @@ import { dataRootRefusal } from "./lib/e2eEnvGuard.mjs";
// E2E_UMTOOL_OPEN_FOLDER_LOG set below on the app server: where the clip
// export's Open folder records what it was asked to
// show, in place of a file manager (lib/report/openFolder.mjs)
+// E2E_UMTOOL_STREAM_DELAY set below on the app server: the home page's
+// streamed Inbox honours a spec's `e2e-stream-delay`
+// cookie (milliseconds to wait before it reads), so
+// streaming.spec can see the placeholder
+// (lib/streamDelay.ts); unset, the cookie is not read
// E2E_CASE_STAGES_SHOTS a directory, set by whoever runs the suite: the
// research case stages' screenshots go there
// (case-stages.spec.ts, release 38 lane C)
@@ -267,6 +272,9 @@ export default defineConfig({
// Open folder (a clip's export) records the ask instead of opening a file manager.
`E2E_UMTOOL_OPEN_FOLDER_LOG=${FIXTURE}/open-folder.jsonl ` +
`E2E_DIGEST_CONTEXT_PLAN=${FIXTURE}/digest-context-review.md ` +
+ // The home page's Inbox waits as long as a spec's `e2e-stream-delay`
+ // cookie says before it reads (lib/streamDelay.ts; streaming.spec).
+ `E2E_UMTOOL_STREAM_DELAY=1 ` +
// No background refresh check (R4, lib/inbox/refresh.ts): an Inbox read
// would otherwise enumerate every fixture article's corpus and add cards
// other specs count. refresh.spec runs the check itself, through its route.