fix(anchor): serialize frame actions and self-heal stale L1 boundary

This commit is contained in:
2026-02-16 22:05:49 +08:00
parent 7a79d8f9b9
commit be70e595ce

View File

@@ -367,6 +367,18 @@ async function handleAnchorGenerate() {
postToFrame({ type: "ANCHOR_GEN_PROGRESS", current, total, message }); postToFrame({ type: "ANCHOR_GEN_PROGRESS", current, total, message });
}); });
// Self-heal: if chunks are empty but boundary looks "already built",
// reset boundary so incremental L1 rebuild can start from floor 0.
const [meta, storageStats] = await Promise.all([
getMeta(chatId),
getStorageStats(chatId),
]);
const lastFloor = (chat?.length || 0) - 1;
if (storageStats.chunks === 0 && lastFloor >= 0 && (meta.lastChunkFloor ?? -1) >= lastFloor) {
await updateMeta(chatId, { lastChunkFloor: -1 });
xbLog.warn(MODULE_ID, "Detected empty L1 chunks with full boundary, reset lastChunkFloor=-1");
}
postToFrame({ type: "ANCHOR_GEN_PROGRESS", current: 0, total: 1, message: "向量化 L1..." }); postToFrame({ type: "ANCHOR_GEN_PROGRESS", current: 0, total: 1, message: "向量化 L1..." });
const chunkResult = await buildIncrementalChunks({ vectorConfig: vectorCfg }); const chunkResult = await buildIncrementalChunks({ vectorConfig: vectorCfg });
@@ -1157,7 +1169,7 @@ function updateFrameStatsAfterSummary(endMesId, merged) {
// iframe 消息处理 // iframe 消息处理
// ═══════════════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════════════
function handleFrameMessage(event) { async function handleFrameMessage(event) {
const iframe = document.getElementById("xiaobaix-story-summary-iframe"); const iframe = document.getElementById("xiaobaix-story-summary-iframe");
if (!isTrustedMessage(event, iframe, "LittleWhiteBox-StoryFrame")) return; if (!isTrustedMessage(event, iframe, "LittleWhiteBox-StoryFrame")) return;
@@ -1212,7 +1224,7 @@ function handleFrameMessage(event) {
break; break;
case "VECTOR_CLEAR": case "VECTOR_CLEAR":
handleClearVectors(); await handleClearVectors();
break; break;
case "VECTOR_CANCEL_GENERATE": case "VECTOR_CANCEL_GENERATE":
@@ -1223,11 +1235,11 @@ function handleFrameMessage(event) {
break; break;
case "ANCHOR_GENERATE": case "ANCHOR_GENERATE":
handleAnchorGenerate(); await handleAnchorGenerate();
break; break;
case "ANCHOR_CLEAR": case "ANCHOR_CLEAR":
handleAnchorClear(); await handleAnchorClear();
break; break;
case "ANCHOR_CANCEL": case "ANCHOR_CANCEL":