fix(webui): reconcile running turns on reconnect (#6715)
* fix(webui): reconcile running turns on reconnect * test(webui): verify only the current turn-sync policy
This commit is contained in:
1 parent
b453de9cf6
commit
094bac0dc3
25 files changed
+455
-226
No files matched your search
@@ -9,6 +9,7 @@ interface TurnRecord {
|
||||
// Only openOrder marks unsettled ownership; a timestamp alone does not.
|
||||
openOrder: number | null;
|
||||
startedAt: number | null;
|
||||
needsLiveCheck: boolean;
|
||||
}
|
||||
|
||||
interface ChatRecord {
|
||||
@@ -59,6 +60,7 @@ type Command =
|
||||
| { kind: "transport-lost" }
|
||||
| { kind: "local-stop" | "forget"; chatId: string }
|
||||
| { kind: "fence" | "settle-completed-lifecycle"; chatId: string; completedTurnIds: readonly string[] }
|
||||
| { kind: "reattach"; chatId: string; liveTurnIds: readonly string[] }
|
||||
| { kind: "restore-pending"; chatId: string; generation: number; turnId: string | null };
|
||||
|
||||
export type RunEffect =
|
||||
@@ -176,6 +178,7 @@ export class ClientRunLedger {
|
||||
case "transport-lost":
|
||||
for (const chat of this.chats.values()) {
|
||||
for (const turn of chat.turns.values()) {
|
||||
turn.needsLiveCheck = turn.openOrder !== null && (!turn.delivery || turn.delivery.phase === "accepted");
|
||||
if (turn.delivery?.phase === "sent") {
|
||||
turn.delivery = { phase: "unknown", role: turn.delivery.role };
|
||||
}
|
||||
@@ -207,6 +210,20 @@ export class ClientRunLedger {
|
||||
chat.anonymousActive = command.turnId === null;
|
||||
break;
|
||||
}
|
||||
case "reattach": {
|
||||
const chat = this.chats.get(command.chatId);
|
||||
if (!chat) break;
|
||||
const live = new Set(command.liveTurnIds);
|
||||
const retired: string[] = [];
|
||||
for (const [turnId, turn] of chat.turns) {
|
||||
if (turn.needsLiveCheck && !live.has(turnId)) retired.push(turnId);
|
||||
turn.needsLiveCheck = false;
|
||||
}
|
||||
// Absence only retires previously observed owners, not new/uncertain sends.
|
||||
// It does not report an outcome or claim that the transcript is complete.
|
||||
if (retired.length > 0) this.completeTurns(command.chatId, retired, "lifecycle", effects);
|
||||
break;
|
||||
}
|
||||
case "fence":
|
||||
case "settle-completed-lifecycle":
|
||||
this.completeTurns(command.chatId, command.completedTurnIds,
|
||||
@@ -391,7 +408,7 @@ export class ClientRunLedger {
|
||||
private ensureTurn(chat: ChatRecord, turnId: string): TurnRecord {
|
||||
let turn = chat.turns.get(turnId);
|
||||
if (!turn) {
|
||||
turn = { delivery: null, openOrder: null, startedAt: null };
|
||||
turn = { delivery: null, openOrder: null, startedAt: null, needsLiveCheck: false };
|
||||
chat.turns.set(turnId, turn);
|
||||
}
|
||||
return turn;
|
||||
|
||||
@@ -1069,6 +1069,10 @@ export class NanobotClient {
|
||||
} else {
|
||||
this.knownChats.add(parsed.chat_id);
|
||||
}
|
||||
const live = parsed.live_turn_ids;
|
||||
if (Array.isArray(live) && live.every((id) => typeof id === "string" && id.length > 0)) {
|
||||
this.applyRunEffects(this.runs.transition({ kind: "reattach", chatId: parsed.chat_id, liveTurnIds: live }));
|
||||
}
|
||||
this.dispatch(parsed.chat_id, parsed);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1565,6 +1565,7 @@ export type InboundEvent =
|
||||
chat_id: string;
|
||||
request_id?: string;
|
||||
temporary?: boolean;
|
||||
live_turn_ids?: string[];
|
||||
recovery_state?: RecoveryState;
|
||||
usage?: TurnUsage;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user