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

+4 -2
View File
@@ -544,7 +544,7 @@ export function useNanobotStream(
}, [chatId, client]);
const settleFragment = useCallback((owner: ThreadTranscript) => {
if (!chatId || !owner.fragmentCompletedTurnIds.length) return;
client.settleFragmentRunLifecycle(chatId, owner.fragmentCompletedTurnIds);
client.settleCompletedRunLifecycle(chatId, owner.fragmentCompletedTurnIds);
if (!client.getRunState(chatId)?.active) setRetryStatus(null);
}, [chatId, client]);
@@ -575,7 +575,9 @@ export function useNanobotStream(
if (chatId && canonical && (ownRead || !seed)) {
if (body?.page?.record_range) {
if (accepted) settleFragment(owner);
} else if (ownRead && !owner.hasPendingFragmentGap) {
} else if (!owner.hasPendingFragmentGap) {
// A published reconnect page supersedes this owner's shared read.
// The owner must reconcile its completion facts after that handoff too.
reconcileCanonical(generation, canonical, accepted);
}
}
+15 -9
View File
@@ -29,26 +29,32 @@ export function useReconnectRuns(client: NanobotClient, getToken: () => string):
const body = await fetchLatestWebuiThread(client, getToken(), key, signal);
if (!body || signal.aborted) return;
const { completedTurnIds, snapshot } = persistedCanonicalRunState(body);
const mounted = client.hasTranscript(chatId);
if (body.page?.record_range) {
if (!Array.isArray(body.completed_turn_ids)) return;
const mounted = client.hasTranscript(chatId);
if (client.canReconcileCanonicalCompletion(chatId, generation, completedTurnIds, snapshot)) {
webuiThreadCache.set(key, body);
}
// A mounted owner must accept (or stage) the fragment before settling.
// Explicit completion is otherwise independent of a newer run, but the
// fragment is not proof that its WS content is covered.
if (!mounted) client.settleFragmentRunLifecycle(chatId, completedTurnIds);
if (!mounted) client.settleCompletedRunLifecycle(chatId, completedTurnIds);
return;
}
const explicitlyCompleted = turnId !== null && completedTurnIds.includes(turnId);
if (!explicitlyCompleted && (snapshot.hasPendingToolCalls || snapshot.activeTurnId)) return;
if (turnId && !explicitlyCompleted && !snapshot.observedTurnIds.includes(turnId)) return;
if (!client.canReconcileCanonicalCompletion(chatId, generation, completedTurnIds, snapshot)) return;
// Preserve the result before completion fences prune queued fragments.
// Returning to an inactive chat can hydrate from this canonical page.
webuiThreadCache.set(key, body);
client.reconcileCanonicalCompletion(chatId, generation, completedTurnIds, snapshot);
const canCache = (explicitlyCompleted || (!snapshot.hasPendingToolCalls && !snapshot.activeTurnId))
&& (!turnId || explicitlyCompleted || snapshot.observedTurnIds.includes(turnId))
&& client.canReconcileCanonicalCompletion(chatId, generation, completedTurnIds, snapshot);
// Preserve adoptable history before notifying completion subscribers.
if (canCache) webuiThreadCache.set(key, body);
// Full-page completion facts belong to the ledger regardless of whether
// a transcript can adopt this page. Retain content for its later owner.
client.settleCompletedRunLifecycle(chatId, completedTurnIds);
// Mounted owners alone adopt whole snapshots. Only an idle snapshot can
// settle activity without a named identity.
if (!mounted && canCache && !snapshot.hasPendingToolCalls && !snapshot.activeTurnId) {
client.reconcileCanonicalCompletion(chatId, generation, completedTurnIds, snapshot);
}
};
let nextJob = 0;
const worker = async () => {