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

+18 -2
View File
@@ -6,6 +6,7 @@ import {
import { persistedCanonicalRunState } from "./canonical-run-snapshot";
import { copyThreadCheckpoint, createThreadCheckpoint, type ThreadCheckpoint } from "./thread-checkpoint";
import { hasPendingAgentActivity } from "./activity-timeline";
import { reconcileModelRequest } from "./model-request";
import type { ThreadProjectionEvent, UIMessage, WebuiThreadPersistedPayload } from "./types";
type Ranges = Array<[number, number]>;
@@ -159,6 +160,7 @@ export class ThreadTranscript {
}
get messages(): UIMessage[] { return this.projection.messages; }
get modelRequests() { return this.projection.modelRequests; }
private installUnit(unit: Unit): void {
this.order = Math.max(this.order, unit.order + 1);
@@ -246,6 +248,11 @@ export class ThreadTranscript {
project(event: ThreadProjectionEvent, options: {
createId: () => string; now: number; persisted?: boolean; sideChannel?: boolean; startSeq?: number;
}): UIMessage[] {
// Telemetry never contributes body sources, memberships, or admission barriers.
if (event.event === "model_request") {
this.projection = projectThreadEvent(this.projection, event, options);
return this.messages;
}
if (!options.persisted && this.represented(event)) return this.messages;
if (!event.projection_id && (!event.turn_id || event.turn_seq === undefined)) {
event = { ...event, projection_id: options.createId() };
@@ -478,15 +485,19 @@ export class ThreadTranscript {
}
if (keepSuffix) nextMessages.push(...this.messages.slice(previous)
.filter((row) => !replaced.has(this.byRow.get(row.id)!)));
const modelRequests = new Map(this.modelRequests);
for (const [turn, snapshot] of candidate.modelRequests) {
modelRequests.set(turn, reconcileModelRequest(modelRequests.get(turn), snapshot));
}
this.projection = fullyAdopt && read.kind !== "older"
? { ...candidate.projection, messages: nextMessages,
? { ...candidate.projection, messages: nextMessages, modelRequests,
activitySegmentId: candidate.projection.activitySegmentId
? segments.get(candidate.projection.activitySegmentId) ?? null : null,
fileEditSegmentId: candidate.projection.fileEditSegmentId
? segments.get(candidate.projection.fileEditSegmentId) ?? null : null,
closedTurnIds: new Set([...this.projection.closedTurnIds, ...candidate.projection.closedTurnIds]),
closedAnswerStreamIds: new Set([...this.projection.closedAnswerStreamIds, ...candidate.projection.closedAnswerStreamIds]) }
: { ...this.projection, messages: nextMessages };
: { ...this.projection, messages: nextMessages, modelRequests };
if (fullyAdopt && read.kind !== "older") {
const retained = new Set(prefix.map((row) => row.id));
for (const unit of this.units) if (!Array.from(unit.rows).some((id) => retained.has(id))) replaced.add(unit);
@@ -559,6 +570,11 @@ export class ThreadTranscript {
.filter((key) => retainedStreams.has(key)));
const retainedTurns = new Set(Array.from(this.units).flatMap((unit) => Array.from(unit.members.keys())));
for (const row of nextMessages) if (row.turnId) retainedTurns.add(row.turnId);
for (const [turn, snapshot] of modelRequests) {
if (reset && snapshot.ended && !retainedTurns.has(turn) && !candidate.modelRequests.has(turn)) {
modelRequests.delete(turn);
} else retainedTurns.add(turn);
}
const retainedRows = new Set(nextMessages.map((row) => row.id));
const retainedBoundaries = new Set(Array.from(this.units).flatMap((unit) => unit.text
.map((text) => JSON.stringify([text.turn, text.phase, text.stream]))));