fix(webui): keep working timer consistent across first output

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-07 17:54:17 +08:00
1 parent 26027e6d37
commit dd3d2970a7
2 files changed
+75 -39

No files matched your search

@@ -188,9 +188,8 @@ export function ThreadMessages({
hasBodyBelow={false}
retryStatus={retryStatus}
startedAtMs={
runStartedAt != null
? runStartedAt * 1000
: pendingActivity.startedAtMs
// Match the activity timeline's prompt-based clock across the first output.
pendingActivity.startedAtMs ?? (runStartedAt != null ? runStartedAt * 1000 : undefined)
}
/>
</div>
+73 -36
View File
@@ -16,52 +16,89 @@ afterEach(() => {
});
describe("ThreadMessages", () => {
it("shows optimistic turn progress in the thread before the first agent output", () => {
it.each([0, -13_000, -14_000, -15_000, 15_000])(
"keeps the optimistic timer through acknowledgement and output with %i ms server clock skew",
(clockSkewMs) => {
vi.useFakeTimers();
const now = new Date("2026-08-13T10:00:05.000Z").getTime();
vi.setSystemTime(now);
const prompt: UIMessage = {
id: "u-optimistic",
role: "user",
content: "check this",
turnId: "turn-optimistic",
turnPhase: "user",
deliveryStatus: "sending",
createdAt: now,
};
const { rerender } = render(
<ThreadMessages
messages={[prompt]}
isStreaming
activeTurnId="turn-optimistic"
/>,
);
expect(screen.getByRole("status", { name: "Working for 0s" })).toBeInTheDocument();
rerender(
<ThreadMessages
messages={[{ ...prompt, deliveryStatus: "accepted" }]}
isStreaming
activeTurnId="turn-optimistic"
runStartedAt={(now + clockSkewMs) / 1000}
/>,
);
expect(screen.getByRole("status", { name: "Working for 0s" })).toBeInTheDocument();
act(() => { vi.advanceTimersByTime(1000); });
rerender(
<ThreadMessages
messages={[
{ ...prompt, deliveryStatus: "accepted" },
{
id: "t-optimistic",
role: "tool",
kind: "trace",
content: "web_search()",
traces: ["web_search()"],
turnId: "turn-optimistic",
turnPhase: "activity",
createdAt: now,
},
]}
isStreaming
activeTurnId="turn-optimistic"
runStartedAt={(now + clockSkewMs) / 1000}
/>,
);
expect(screen.getByRole("button", { name: "Working for 1s" })).toBeInTheDocument();
},
);
it("restores pending progress from the original prompt when guidance arrives", () => {
vi.useFakeTimers();
const now = new Date("2026-08-13T10:00:05.000Z").getTime();
const now = 1_800_000_000_000;
vi.setSystemTime(now);
const prompt: UIMessage = {
id: "u-optimistic",
role: "user",
content: "check this",
turnId: "turn-optimistic",
turnPhase: "user",
deliveryStatus: "sending",
createdAt: now - 5_000,
};
const { rerender } = render(
<ThreadMessages
messages={[prompt]}
isStreaming
activeTurnId="turn-optimistic"
runStartedAt={(now - 5_000) / 1000}
/>,
);
expect(screen.getByRole("status", { name: "Working for 5s" })).toBeInTheDocument();
rerender(
render(
<ThreadMessages
messages={[
{ ...prompt, deliveryStatus: "accepted" },
{
id: "t-optimistic",
role: "tool",
kind: "trace",
content: "web_search()",
traces: ["web_search()"],
turnId: "turn-optimistic",
turnPhase: "activity",
createdAt: now,
id: "original", role: "user", content: "research this",
turnId: "original-turn", createdAt: now - 30_000,
},
{
id: "guidance", role: "user", content: "also check this",
turnId: "guidance-turn", createdAt: now,
},
]}
isStreaming
activeTurnId="turn-optimistic"
runStartedAt={(now - 5_000) / 1000}
activeTurnId="original-turn"
runStartedAt={(now - 43_000) / 1000}
/>,
);
expect(screen.getByRole("button", { name: "Working for 5s" })).toBeInTheDocument();
expect(screen.getByRole("status", { name: "Working for 30s" })).toBeInTheDocument();
});
it("does not move a mounted tail answer into offscreen rendering on the next turn", () => {