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
+45 -9

No files matched your search

@@ -188,9 +188,8 @@ export function ThreadMessages({
hasBodyBelow={false} hasBodyBelow={false}
retryStatus={retryStatus} retryStatus={retryStatus}
startedAtMs={ startedAtMs={
runStartedAt != null // Match the activity timeline's prompt-based clock across the first output.
? runStartedAt * 1000 pendingActivity.startedAtMs ?? (runStartedAt != null ? runStartedAt * 1000 : undefined)
: pendingActivity.startedAtMs
} }
/> />
</div> </div>
+43 -6
View File
@@ -16,7 +16,9 @@ afterEach(() => {
}); });
describe("ThreadMessages", () => { 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(); vi.useFakeTimers();
const now = new Date("2026-08-13T10:00:05.000Z").getTime(); const now = new Date("2026-08-13T10:00:05.000Z").getTime();
vi.setSystemTime(now); vi.setSystemTime(now);
@@ -27,18 +29,28 @@ describe("ThreadMessages", () => {
turnId: "turn-optimistic", turnId: "turn-optimistic",
turnPhase: "user", turnPhase: "user",
deliveryStatus: "sending", deliveryStatus: "sending",
createdAt: now - 5_000, createdAt: now,
}; };
const { rerender } = render( const { rerender } = render(
<ThreadMessages <ThreadMessages
messages={[prompt]} messages={[prompt]}
isStreaming isStreaming
activeTurnId="turn-optimistic" activeTurnId="turn-optimistic"
runStartedAt={(now - 5_000) / 1000}
/>, />,
); );
expect(screen.getByRole("status", { name: "Working for 5s" })).toBeInTheDocument(); 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( rerender(
<ThreadMessages <ThreadMessages
@@ -57,11 +69,36 @@ describe("ThreadMessages", () => {
]} ]}
isStreaming isStreaming
activeTurnId="turn-optimistic" activeTurnId="turn-optimistic"
runStartedAt={(now - 5_000) / 1000} runStartedAt={(now + clockSkewMs) / 1000}
/>, />,
); );
expect(screen.getByRole("button", { name: "Working for 5s" })).toBeInTheDocument(); expect(screen.getByRole("button", { name: "Working for 1s" })).toBeInTheDocument();
},
);
it("restores pending progress from the original prompt when guidance arrives", () => {
vi.useFakeTimers();
const now = 1_800_000_000_000;
vi.setSystemTime(now);
render(
<ThreadMessages
messages={[
{
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="original-turn"
runStartedAt={(now - 43_000) / 1000}
/>,
);
expect(screen.getByRole("status", { name: "Working for 30s" })).toBeInTheDocument();
}); });
it("does not move a mounted tail answer into offscreen rendering on the next turn", () => { it("does not move a mounted tail answer into offscreen rendering on the next turn", () => {