fix(webui): update usage and tool progress during active turns (#6553)

* fix(webui): stream model status and usage during active turns

* fix(webui): keep live rounds and active-run status consistent

* fix(webui): reuse existing run indicators without extra status text

* fix(webui): preserve live activity and batch durable delivery

Cancel and drain sibling tools when progress notifications fail, retain balanced checkpoints, and keep model telemetry separate from answer provenance.

Group-commit already queued activity at the channel delivery boundary while preserving FIFO, generation ownership, per-envelope admission, and commit-before-fanout semantics. Isolate invalid members without dropping valid neighboring events.

Retain tool detail lazy grouping and cover scheduling, cancellation, persistence, encoding failures, and projection regressions.

* test(webui): separate standard-library imports in batch regression

* test: tighten live execution checks and clarify contracts

* refactor: remove redundant live execution comments

* refactor: settle tool results through one output path
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-04 16:27:24 +08:00
1 parent 006a535537
commit 8ff04aad2b
52 files changed
+2065 -211

No files matched your search

+28
View File
@@ -5,6 +5,7 @@ import { describe, expect, it, vi } from "vitest";
import { useNanobotStream } from "@/hooks/useNanobotStream";
import { ThreadVisibilityContext } from "@/hooks/useThreadVisibility";
import { normalizeActivityTimeline } from "@/lib/activity-timeline";
import { composerUsageSnapshots } from "@/lib/model-request";
import { ThreadMessageCache } from "@/lib/thread-message-cache";
import type { NanobotClient, StreamError } from "@/lib/nanobot-client";
import type {
@@ -3837,3 +3838,30 @@ describe("live canonical event projection", () => {
]);
});
});
it("projects active model usage without ending the turn and ignores late usage after stop", () => {
const fake = fakeClient();
const { result } = renderHook(() => useNanobotStream("chat-model", EMPTY_MESSAGES), {
wrapper: wrap(fake.client),
});
const envelope = { chat_id: "chat-model", turn_id: "turn-model" };
act(() => {
fake.emit("chat-model", { ...envelope, event: "goal_status", status: "running", started_at: 1700 });
fake.emit("chat-model", { ...envelope, event: "user_message", text: "hello", starts_turn: true, turn_seq: 0 });
fake.emit("chat-model", { ...envelope, event: "model_request", request_id: "first", run_id: "run",
sequence: 1, turn_seq: 1, phase: "completed", usage: { prompt_tokens: 105000, completion_tokens: 100,
context_tokens: 105000, request_count: 1 }, round_usages: [{ prompt_tokens: 105000, completion_tokens: 100 }] });
fake.emit("chat-model", { ...envelope, event: "model_request", request_id: "second", run_id: "run",
sequence: 2, turn_seq: 2, phase: "started" });
});
expect(result.current.isStreaming).toBe(true);
expect(composerUsageSnapshots(result.current.messages, result.current.modelRequests).at(-1)?.usage?.context_tokens).toBe(105000);
act(() => result.current.stop());
expect(result.current.isStreaming).toBe(false);
act(() => fake.emit("chat-model", { ...envelope, event: "model_request", request_id: "late", run_id: "run",
sequence: 3, turn_seq: 3, phase: "completed", usage: { prompt_tokens: 999, completion_tokens: 1,
context_tokens: 999, request_count: 2 } }));
expect(result.current.isStreaming).toBe(false);
expect(composerUsageSnapshots(result.current.messages, result.current.modelRequests).at(-1)?.usage?.context_tokens).toBe(105000);
});