fix: close PI core chat review gaps

This commit is contained in:
2026-08-24 01:28:06 +08:00
parent 612135f911
commit bec93d0918
15 changed files with 1094 additions and 122 deletions

View File

@@ -338,6 +338,7 @@ export function createCodingConversationStore(
const deps = { ...defaultDependencies(), ...dependencies };
const snapshotLoads = new Map<string, Promise<ConversationSnapshot>>();
const recoveryBatches = new Map<string, CodingConversationPatchBatchEvent[]>();
const recoveryRefreshKeys = new Map<string, string>();
let eventSource: EventSource | null = null;
let connectFlight: Promise<void> | null = null;
let connectionGeneration = 0;
@@ -375,11 +376,20 @@ export function createCodingConversationStore(
const items = [...itemsBySeq.values()].sort((left, right) => left.seq - right.seq);
if (items.length === 0) {
recoveryBatches.delete(conversationId);
recoveryRefreshKeys.delete(conversationId);
return;
}
const continuous = items[0].seq === snapshot.cursor.seq + 1
&& items.every((item, index) => index === 0 || item.seq === items[index - 1].seq + 1);
if (!continuous) {
const lastSeq = items.at(-1)?.seq ?? items[0].seq;
const refreshKey = [
snapshot.cursor.workerGeneration,
snapshot.cursor.seq,
items[0].seq,
lastSeq,
].join(':');
const willRefresh = recoveryRefreshKeys.get(conversationId) !== refreshKey;
store.setState((state) => {
const current = state.entriesByConversationId[conversationId] ?? emptyEntry();
return {
@@ -387,15 +397,24 @@ export function createCodingConversationStore(
...state.entriesByConversationId,
[conversationId]: {
...current,
loadState: 'recovering',
loadState: willRefresh ? 'recovering' : 'error',
error: 'Conversation patch batch is not continuous',
},
},
};
});
if (willRefresh) {
recoveryRefreshKeys.set(conversationId, refreshKey);
queueMicrotask(() => {
if (!snapshotLoads.has(conversationId)) {
void store.getState().loadSnapshot(conversationId, true).catch(() => undefined);
}
});
}
return;
}
recoveryBatches.delete(conversationId);
recoveryRefreshKeys.delete(conversationId);
store.getState().applyPatchBatchEvent({
type: 'patch-batch',
conversationId,
@@ -521,6 +540,7 @@ export function createCodingConversationStore(
},
async recoverConversation(conversationId) {
recoveryRefreshKeys.delete(conversationId);
set((state) => {
const entry = state.entriesByConversationId[conversationId] ?? emptyEntry();
return {