fix(ui): hide startup steps too short to name and hold labels long enough to read (#23299)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The task view names each startup stage of a run until the agent
works, for example "Preparing workspace" or "Starting agent".
> - Core and environment plugins report every startup step as it starts,
however short, and the task view decides which labels to show.
> - The view held each label for 500 ms and showed every change at once.
A step of a few milliseconds that started after a longer step appeared
at once and stayed up after it ended. Also, 500 ms is less than the time
most labels take to read.
> - This pull request adds a short show delay, so that steps too short
to name never appear, and holds each shown label for its reading time.
> - The benefit is a status line that changes only for steps that last,
and stays up long enough to read.

## Linked Issues or Issue Description

No public issue exists. Follows #22956, which added the startup stage
labels.

**Subsystem affected**
Task chat UI: the startup stage line of a running turn
(`ui/src/components/task-chat`).

**Problem or motivation**
A startup step that lasts a few milliseconds can show its label for 500
ms after the step ended. For example, a short "Connecting tools" step
inside a long "Starting agent" step changes the line twice. Also, the
500 ms hold is shorter than the time needed to read most labels.

**Proposed solution**
Use the common loading-indicator pattern of a show delay plus a minimum
display time. Base the minimum time on reading time:
- A new stage's label shows only after the stage stays current for 300
ms.
- A shown label stays up for 50 ms per character (20 characters a
second, the usual adult subtitle reading speed), and at least
five-sixths of a second (the usual subtitle minimum).

**Alternatives considered**
- Only a minimum display time (the current behavior). This prevents
flicker, but short steps still show and stay up after they end.
- Hide steps in the reporter. This would put a display rule in each
reporter. Reporters report every step, and the view decides what to
show.

## What Changed

- `useHeldLabel` shows a new label only after it stays current for
`STARTUP_LABEL_SHOW_DELAY_MS` (300 ms). Labels that come and go within
that time never show.
- A shown label stays up for `startupLabelHoldMs(label)`: the greater of
833 ms and 50 ms per character. Today's labels stay up for 0.83 s to
0.95 s.
- The end of startup (no label) has no show delay. The last label is
still held so that it can be read. Agent activity replaces the line as
before.
- The first label shows at once. A task opened during startup can show a
stage that is already old, and `Thinking` in its place would be wrong.
- `DESIGN.md` describes the show delay, the reading-time hold, and the
first label.

## Verification

- `npx vitest run src/components/task-chat/run-startup-stage.test.ts` in
`ui`: 9 tests pass. They cover the first label, the hold per label, the
show delay, a short step inside a longer one, a skip to the latest
stage, a longer hold for a longer label, and the end of startup.
- `npx vitest run src/components/TaskChatThread.test.tsx -t "startup
stage"` in `ui`: the startup stage thread tests pass.
- `pnpm --filter @paperclipai/ui typecheck` passes.
- CI runs the full suite.

## Risks

- Low risk. This changes display timing only.
- Each new label shows 300 ms later than before. A shown label can stay
up for up to about 0.65 s after its step ends, if the step is just
longer than the show delay.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use
(shell, file edits, web research).

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Nicky LeachandClaude Opus 5.5 authored and GitHub committed 2026-11-30 10:03:46 -08:00
1 parent 79dadd8655
commit 79ef767578
4 files changed
+135 -41

No files matched your search

+5 -2
View File
@@ -14,7 +14,7 @@ import { TooltipProvider } from "@/components/ui/tooltip";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ConnectivityProvider, createConnectivityStore } from "@/lib/connectivity";
import { INITIAL_TRANSCRIPT_REVEAL_BUDGET_MS, TaskChatThread } from "./TaskChatThread";
import { STARTUP_LABEL_MIN_DISPLAY_MS } from "./task-chat/run-startup-stage";
import { STARTUP_LABEL_SHOW_DELAY_MS, startupLabelHoldMs } from "./task-chat/run-startup-stage";
import { IssueChatThread } from "./IssueChatThread";
import { TaskChatAgentIdentity, TaskTranscriptAgents } from "./task-chat/TaskChatBubble";
import type {
@@ -1834,8 +1834,11 @@ describe("TaskChatThread runtime transcript selection", () => {
// The stage is the activity line; the header keeps its usual Working status.
expect(container.querySelector('[data-testid="task-chat-turn-status-header"]')?.textContent).toContain("Working");
await act(async () => { await new Promise(resolve => setTimeout(resolve, STARTUP_LABEL_MIN_DISPLAY_MS + 50)); });
// A shown stage stays up long enough to read; the next one shows once it has stayed current for the show delay.
await act(async () => { await new Promise(resolve => setTimeout(resolve, startupLabelHoldMs("Connecting tools"))); });
renderThread({ ...props, activeRun: { ...run, startupStage: "starting_agent", startupSessionResumed: true } });
expect(activity()?.textContent).toBe("Connecting tools");
await act(async () => { await new Promise(resolve => setTimeout(resolve, STARTUP_LABEL_SHOW_DELAY_MS + 50)); });
expect(activity()?.textContent).toBe("Resuming session");
nativeTranscriptState.transcriptByRun.set(run.id, [
@@ -6,7 +6,9 @@ import { RUN_STARTUP_STAGES } from "@paperclipai/shared";
import {
RUN_STARTUP_STAGE_LABELS,
runStartupStageLabel,
STARTUP_LABEL_MIN_DISPLAY_MS,
STARTUP_LABEL_MIN_HOLD_MS,
STARTUP_LABEL_SHOW_DELAY_MS,
startupLabelHoldMs,
useHeldLabel,
} from "./run-startup-stage";
@@ -41,41 +43,98 @@ it("names every startup stage and the resumed session", () => {
expect(runStartupStageLabel(null)).toBeNull();
});
it("shows a changed label at once after the minimum time", () => {
vi.useFakeTimers();
const { result, rerender } = renderHeldLabel("Getting ready");
act(() => { vi.advanceTimersByTime(STARTUP_LABEL_MIN_DISPLAY_MS); });
rerender("Waking up");
expect(result.current).toBe("Waking up");
const advance = (ms: number) => act(() => { vi.advanceTimersByTime(ms); });
it("holds each label for its reading time, at least five-sixths of a second", () => {
expect(startupLabelHoldMs("Waking up")).toBe(STARTUP_LABEL_MIN_HOLD_MS);
expect(startupLabelHoldMs("Starting agent")).toBe(STARTUP_LABEL_MIN_HOLD_MS);
// 19 characters at 20 a second.
expect(startupLabelHoldMs("Preparing workspace")).toBe(950);
expect(startupLabelHoldMs(null)).toBe(0);
});
it("holds a fresh label, then skips to the latest one", () => {
it("shows the current stage at once when the line first appears", () => {
vi.useFakeTimers();
const { result, rerender } = renderHeldLabel("Getting ready");
act(() => { vi.advanceTimersByTime(100); });
rerender("Waking up");
rerender("Preparing workspace");
expect(result.current).toBe("Getting ready");
act(() => { vi.advanceTimersByTime(STARTUP_LABEL_MIN_DISPLAY_MS - 101); });
expect(result.current).toBe("Getting ready");
act(() => { vi.advanceTimersByTime(1); });
const { result } = renderHeldLabel("Preparing workspace");
expect(result.current).toBe("Preparing workspace");
});
it("holds the last stage before returning to the default", () => {
it("shows a new stage once it has stayed current for the show delay", () => {
vi.useFakeTimers();
const { result, rerender } = renderHeldLabel("Starting agent");
rerender(null);
expect(result.current).toBe("Starting agent");
act(() => { vi.advanceTimersByTime(STARTUP_LABEL_MIN_DISPLAY_MS); });
expect(result.current).toBeNull();
const { result, rerender } = renderHeldLabel("Getting ready");
advance(startupLabelHoldMs("Getting ready"));
rerender("Waking up");
expect(result.current).toBe("Getting ready");
advance(STARTUP_LABEL_SHOW_DELAY_MS - 1);
expect(result.current).toBe("Getting ready");
advance(1);
expect(result.current).toBe("Waking up");
});
it("keeps the shown label when a change is undone within the hold", () => {
it("never shows a stage that ends within the show delay", () => {
vi.useFakeTimers();
const { result, rerender } = renderHeldLabel("Starting agent");
advance(startupLabelHoldMs("Starting agent"));
// A step a few milliseconds long, inside a longer one.
rerender("Connecting tools");
advance(5);
rerender("Starting agent");
advance(STARTUP_LABEL_SHOW_DELAY_MS * 4);
expect(result.current).toBe("Starting agent");
// A short step followed by another stage: only the stage that stays current shows.
rerender("Restoring session");
advance(STARTUP_LABEL_SHOW_DELAY_MS - 1);
rerender("Preparing workspace");
advance(STARTUP_LABEL_SHOW_DELAY_MS - 1);
expect(result.current).toBe("Starting agent");
advance(1);
expect(result.current).toBe("Preparing workspace");
});
it("holds a fresh label for its reading time, then skips to the latest one", () => {
vi.useFakeTimers();
const { result, rerender } = renderHeldLabel("Getting ready");
advance(100);
rerender("Waking up");
rerender("Preparing workspace");
// The show delay has passed, but the shown label has not been up long enough to read.
advance(STARTUP_LABEL_MIN_HOLD_MS - 101);
expect(result.current).toBe("Getting ready");
advance(1);
expect(result.current).toBe("Preparing workspace");
});
it("holds a longer label for longer", () => {
vi.useFakeTimers();
const { result, rerender } = renderHeldLabel("Preparing workspace");
rerender("Starting agent");
advance(startupLabelHoldMs("Preparing workspace") - 1);
expect(result.current).toBe("Preparing workspace");
advance(1);
expect(result.current).toBe("Starting agent");
});
it("ends startup without the show delay, once the last label has been up long enough to read", () => {
vi.useFakeTimers();
const settled = renderHeldLabel("Starting agent");
advance(startupLabelHoldMs("Starting agent"));
settled.rerender(null);
expect(settled.result.current).toBeNull();
const fresh = renderHeldLabel("Starting agent");
fresh.rerender(null);
expect(fresh.result.current).toBe("Starting agent");
advance(startupLabelHoldMs("Starting agent") - 1);
expect(fresh.result.current).toBe("Starting agent");
advance(1);
expect(fresh.result.current).toBeNull();
});
it("keeps the shown label when a change is undone", () => {
vi.useFakeTimers();
const { result, rerender } = renderHeldLabel("Getting ready");
rerender("Waking up");
rerender("Getting ready");
act(() => { vi.advanceTimersByTime(STARTUP_LABEL_MIN_DISPLAY_MS * 2); });
advance(STARTUP_LABEL_MIN_HOLD_MS * 2);
expect(result.current).toBe("Getting ready");
});
@@ -21,35 +21,62 @@ export function runStartupStageLabel(
}
/**
* How long a shown label stays before the next one replaces it. Startup steps
* often take a few milliseconds, so a shorter hold would flicker.
* How long a new stage must stay current before its label replaces the shown
* one. Most startup steps take a few milliseconds; a label for one of them
* would only stay up, held for reading, after its step had ended. This is the
* delay loading indicators commonly use before they appear.
*/
export const STARTUP_LABEL_MIN_DISPLAY_MS = 500;
export const STARTUP_LABEL_SHOW_DELAY_MS = 300;
/** The shortest time a shown label stays: five-sixths of a second, the usual subtitle minimum. */
export const STARTUP_LABEL_MIN_HOLD_MS = 833;
/** Reading time per character, at 20 characters a second, the usual adult subtitle reading speed. */
export const STARTUP_LABEL_MS_PER_CHARACTER = 50;
/** How long a shown label stays before the next one replaces it, long enough to read it comfortably. */
export function startupLabelHoldMs(label: string | null): number {
return label === null ? 0 : Math.max(STARTUP_LABEL_MIN_HOLD_MS, label.length * STARTUP_LABEL_MS_PER_CHARACTER);
}
/** How long `label` must still wait before it replaces `shown`; zero or less when it can show now. */
function heldLabelWaitMs(label: string | null, since: number, shown: string | null, shownAt: number, now: number): number {
const delay = label === null ? 0 : STARTUP_LABEL_SHOW_DELAY_MS - (now - since);
return Math.max(delay, startupLabelHoldMs(shown) - (now - shownAt));
}
/**
* Shows a changed label at once when the current one has been visible for the
* minimum time. Otherwise it waits out the rest of that time and then shows
* the latest label, skipping any that came and went in between. Nothing is
* delayed by a prediction of how long a step will last.
* The label to show for a label that changes as startup moves on. A new label
* shows once it has stayed current for the show delay, so a step too short to
* name never appears, and once the shown label has been up long enough to
* read. Labels that came and went in between are skipped. The end of startup
* (null) needs no delay, because it is not a guess about a step's length, but
* the last label is still held so that it can be read.
*/
export function useHeldLabel(label: string | null, minDisplayMs = STARTUP_LABEL_MIN_DISPLAY_MS): string | null {
export function useHeldLabel(label: string | null): string | null {
// The first label shows at once: a task opened during startup may show a stage that has been current for a while,
// and the default in its place, `Thinking`, would be wrong.
const [shown, setShown] = useState(label);
const shownAtRef = useRef(Date.now());
// Once the hold has passed, show the change in this render, not a later one.
const holdPassed = label !== shown && Date.now() - shownAtRef.current >= minDisplayMs;
// When the current label value first arrived.
const currentRef = useRef({ label, since: Date.now() });
if (currentRef.current.label !== label) currentRef.current = { label, since: Date.now() };
// Once the delay and the hold have passed, show the change in this render, not a later one.
const ready = label !== shown &&
heldLabelWaitMs(label, currentRef.current.since, shown, shownAtRef.current, Date.now()) <= 0;
useEffect(() => {
if (label === shown) return;
const remainingMs = minDisplayMs - (Date.now() - shownAtRef.current);
const show = () => {
shownAtRef.current = Date.now();
setShown(label);
};
const remainingMs = heldLabelWaitMs(label, currentRef.current.since, shown, shownAtRef.current, Date.now());
if (remainingMs <= 0) {
show();
return;
}
const timer = setTimeout(show, remainingMs);
return () => clearTimeout(timer);
}, [label, shown, minDisplayMs]);
return holdPassed ? label : shown;
}, [label, shown]);
return ready ? label : shown;
}