fix(webui): settle completed turns across reconnect paths

Separate named completion facts from history adoption, preserve newer and anonymous activity, and keep one mounted whole-snapshot adopter. Unify explicit-ID lifecycle/content closure without discarding uncovered content.

Cover the real client/hooks reconnect and selection races, await asynchronous browser fixture startup, and retain current-policy bounded TLC models and missing-evidence limits. Archive historical/candidate verification separately.
This commit is contained in:
chengyongru authored and chengyongru committed 2026-11-17 17:59:01 +08:00
1 parent 9e499ad539
commit 53a556585e
34 files changed
+1891 -46

No files matched your search

+14 -26
View File
@@ -58,7 +58,7 @@ type Command =
| ({ kind: "written" | "reject" } & TurnRef)
| { kind: "transport-lost" }
| { kind: "local-stop" | "forget"; chatId: string }
| { kind: "fence" | "settle-fragment-lifecycle"; chatId: string; completedTurnIds: readonly string[] }
| { kind: "fence" | "settle-completed-lifecycle"; chatId: string; completedTurnIds: readonly string[] }
| { kind: "restore-pending"; chatId: string; generation: number; turnId: string | null };
export type RunEffect =
@@ -208,10 +208,9 @@ export class ClientRunLedger {
break;
}
case "fence":
this.fence(command.chatId, command.completedTurnIds, effects);
break;
case "settle-fragment-lifecycle":
this.settleFragmentLifecycle(command.chatId, command.completedTurnIds, effects);
case "settle-completed-lifecycle":
this.completeTurns(command.chatId, command.completedTurnIds,
command.kind === "fence" ? "content" : "lifecycle", effects);
break;
default: {
const unhandled: never = command;
@@ -348,7 +347,7 @@ export class ClientRunLedger {
private applyCanonicalSnapshot(request: CanonicalRequest): { accepted: boolean; effects: readonly RunEffect[] } {
const { chatId, snapshot } = request;
const effects: RunEffect[] = [];
this.fence(chatId, request.completedTurnIds, effects);
this.completeTurns(chatId, request.completedTurnIds, "content", effects);
if (!this.canApplyCanonical({ ...request, completedTurnIds: [] })) return { accepted: false, effects };
const chat = this.chats.get(chatId);
@@ -466,34 +465,23 @@ export class ClientRunLedger {
this.trimTerminalSet(chat.closed, chat.latestTurnId);
}
private settleFragmentLifecycle(chatId: string, turnIds: readonly string[], effects: RunEffect[]): void {
for (const turnId of turnIds) {
if (!turnId) continue;
const chat = this.ensureChat(chatId);
this.rememberClosed(chat, turnId);
this.settle(chatId, turnId, effects);
if (chat.latestTurnId === turnId) {
chat.anonymousActive = false;
chat.effectiveStartedAt = null;
}
}
effects.push({ kind: "prune-lifecycle-inbound", chatId, turnIds });
}
private fence(chatId: string, turnIds: readonly string[], effects: RunEffect[]): void {
private completeTurns(
chatId: string, turnIds: readonly string[], coverage: "lifecycle" | "content", effects: RunEffect[],
): void {
let chat = this.chats.get(chatId);
for (const turnId of turnIds) {
if (!turnId) continue;
chat ??= this.ensureChat(chatId);
chat.fenced.add(turnId);
// Explicit completion settles ownership even when the full page cannot be adopted.
this.rememberClosed(chat, turnId);
this.settle(chatId, turnId, effects);
// Anonymous recovery activity is independent of this named turn.
// Named completion never clears a different owner or anonymous recovery.
if (chat.latestTurnId === turnId) chat.effectiveStartedAt = null;
if (coverage === "content") chat.fenced.add(turnId);
}
if (chat) this.trimTerminalSet(chat.fenced);
effects.push({ kind: "prune-inbound", chatId, turnIds: Array.from(chat?.fenced ?? []) });
if (coverage === "content") {
if (chat) this.trimTerminalSet(chat.fenced);
effects.push({ kind: "prune-inbound", chatId, turnIds: Array.from(chat?.fenced ?? []) });
} else effects.push({ kind: "prune-lifecycle-inbound", chatId, turnIds });
}
private trimTerminalSet(turnIds: Set<string>, retainedTurnId?: string | null): void {
+3 -3
View File
@@ -439,9 +439,9 @@ export class NanobotClient {
this.applyRunEffects(this.runs.transition({ kind: "fence", chatId, completedTurnIds }));
}
/** Settle explicit fragment completions without claiming coverage of live content. */
settleFragmentRunLifecycle(chatId: string, completedTurnIds: readonly string[]): void {
this.applyRunEffects(this.runs.transition({ kind: "settle-fragment-lifecycle", chatId, completedTurnIds }));
/** Settle explicit completions without claiming coverage of live content. */
settleCompletedRunLifecycle(chatId: string, completedTurnIds: readonly string[]): void {
this.applyRunEffects(this.runs.transition({ kind: "settle-completed-lifecycle", chatId, completedTurnIds }));
}
/** Whether a mounted transcript owns delivery for this chat. */