mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-06-13 18:31:16 +08:00
fix: IndexedDB probe 失败后不再永久卡在 loading,重试耗尽后回退到 blocked
- index.js: 新增 reconcileIndexedDbProbeFailureState,后台 probe 失败时先有限重试,耗尽后切到 blocked - index.js: scheduleIndexedDbGraphProbe 的 .then/.catch 均接入 reconcile 逻辑 - index.js: createGraphLoadUiStatus blocked 文案更新 - ui/panel.js: _getGraphLoadLabel blocked 文案更新,不再误导为元数据未就绪 - tests/graph-persistence.mjs: 新增 manager-unavailable / read-failed 回归 - tests/graph-persistence.mjs: harness 支持 __indexedDbExportSnapshotShouldThrow / __indexedDbGetCurrentDbShouldThrow
This commit is contained in:
89
index.js
89
index.js
@@ -1029,7 +1029,7 @@ function createGraphLoadUiStatus() {
|
||||
case GRAPH_LOAD_STATES.BLOCKED:
|
||||
return createUiStatus(
|
||||
"图谱加载受阻",
|
||||
"当前图谱尚未完成 IndexedDB 初始加载",
|
||||
"当前图谱未能完成 IndexedDB 确认,请稍后重试",
|
||||
"warning",
|
||||
);
|
||||
case GRAPH_LOAD_STATES.LOADED:
|
||||
@@ -6182,6 +6182,7 @@ async function loadGraphFromIndexedDb(
|
||||
|
||||
function scheduleIndexedDbGraphProbe(chatId, options = {}) {
|
||||
const normalizedChatId = normalizeChatIdCandidate(chatId);
|
||||
const attemptIndex = Math.max(0, Math.floor(Number(options?.attemptIndex) || 0));
|
||||
if (
|
||||
!normalizedChatId ||
|
||||
bmeIndexedDbLoadInFlightByChatId.has(normalizedChatId)
|
||||
@@ -6191,8 +6192,27 @@ function scheduleIndexedDbGraphProbe(chatId, options = {}) {
|
||||
|
||||
scheduleBmeIndexedDbTask(() => {
|
||||
const loadPromise = loadGraphFromIndexedDb(normalizedChatId, options)
|
||||
.then((result) =>
|
||||
reconcileIndexedDbProbeFailureState(normalizedChatId, result, {
|
||||
attemptIndex,
|
||||
}),
|
||||
)
|
||||
.catch((error) => {
|
||||
console.warn("[ST-BME] IndexedDB 后台加载失败:", error);
|
||||
return reconcileIndexedDbProbeFailureState(
|
||||
normalizedChatId,
|
||||
{
|
||||
success: false,
|
||||
loaded: false,
|
||||
reason: "indexeddb-read-failed",
|
||||
chatId: normalizedChatId,
|
||||
attemptIndex,
|
||||
error,
|
||||
},
|
||||
{
|
||||
attemptIndex,
|
||||
},
|
||||
);
|
||||
})
|
||||
.finally(() => {
|
||||
if (
|
||||
@@ -7852,6 +7872,73 @@ function scheduleGraphLoadRetry(
|
||||
return true;
|
||||
}
|
||||
|
||||
function reconcileIndexedDbProbeFailureState(
|
||||
chatId,
|
||||
result = {},
|
||||
{ attemptIndex = 0 } = {},
|
||||
) {
|
||||
if (result?.loaded || result?.emptyConfirmed) {
|
||||
clearPendingGraphLoadRetry();
|
||||
return result;
|
||||
}
|
||||
|
||||
const normalizedChatId = normalizeChatIdCandidate(chatId || result?.chatId);
|
||||
const normalizedReason = String(result?.reason || "").trim();
|
||||
if (!normalizedChatId || !normalizedReason) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (
|
||||
!normalizedReason.startsWith("indexeddb-") ||
|
||||
normalizedReason === "indexeddb-stale" ||
|
||||
normalizedReason === "indexeddb-chat-switched"
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (graphPersistenceState.loadState !== GRAPH_LOAD_STATES.LOADING) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const stateChatId = normalizeChatIdCandidate(graphPersistenceState.chatId);
|
||||
if (stateChatId && stateChatId !== normalizedChatId) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const currentChatId = getCurrentChatId();
|
||||
if (currentChatId && currentChatId !== normalizedChatId) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (
|
||||
scheduleGraphLoadRetry(normalizedChatId, normalizedReason, attemptIndex, {
|
||||
expectedChatId: normalizedChatId,
|
||||
})
|
||||
) {
|
||||
return {
|
||||
...result,
|
||||
retryScheduled: true,
|
||||
};
|
||||
}
|
||||
|
||||
applyGraphLoadState(GRAPH_LOAD_STATES.BLOCKED, {
|
||||
chatId: normalizedChatId,
|
||||
reason: normalizedReason,
|
||||
attemptIndex,
|
||||
dbReady: false,
|
||||
writesBlocked: true,
|
||||
});
|
||||
runtimeStatus = createGraphLoadUiStatus();
|
||||
refreshPanelLiveState();
|
||||
|
||||
return {
|
||||
...result,
|
||||
loadState: GRAPH_LOAD_STATES.BLOCKED,
|
||||
blocked: true,
|
||||
reason: normalizedReason,
|
||||
};
|
||||
}
|
||||
|
||||
function shouldSyncGraphLoadFromLiveContext(
|
||||
context = getContext(),
|
||||
{ force = false } = {},
|
||||
|
||||
Reference in New Issue
Block a user