fix: harden mobile local store recovery flow

This commit is contained in:
Youzini-afk
2026-04-15 12:43:13 +08:00
parent 4846f1587b
commit 05d3fe3fbd
3 changed files with 515 additions and 12 deletions

View File

@@ -1216,10 +1216,37 @@ export async function onDeleteCurrentIdbController(runtime) {
: null;
runtime.clearCachedIndexedDbSnapshot?.(chatId);
runtime.clearCachedIndexedDbSnapshot?.(restoreSafetyChatId);
runtime.clearCurrentChatCommitMarker?.({
reason: "manual-delete-current-local-storage",
immediate: true,
resetAcceptedRevision: true,
if (typeof runtime.clearCurrentChatRecoveryAnchors === "function") {
runtime.clearCurrentChatRecoveryAnchors({
chatId,
reason: "manual-delete-current-local-storage",
immediate: true,
clearMetadataFull: true,
clearCommitMarker: true,
clearPendingPersist: true,
});
if (restoreSafetyChatId && restoreSafetyChatId !== chatId) {
runtime.clearCurrentChatRecoveryAnchors({
chatId: restoreSafetyChatId,
reason: "manual-delete-current-local-storage:restore-safety",
immediate: true,
clearMetadataFull: false,
clearCommitMarker: false,
clearPendingPersist: false,
});
}
} else {
runtime.clearCurrentChatCommitMarker?.({
reason: "manual-delete-current-local-storage",
immediate: true,
resetAcceptedRevision: true,
});
}
await runtime.refreshCurrentChatLocalStoreBinding?.({
chatId,
forceCapabilityRefresh: true,
reopenCurrentDb: true,
source: "manual-delete-current-local-storage",
});
runtime.syncGraphLoadFromLiveContext?.({
source: "manual-delete-current-local-storage",
@@ -1279,10 +1306,27 @@ export async function onDeleteAllIdbController(runtime) {
runtime.clearAllCachedIndexedDbSnapshots?.();
const activeChatId = runtime.getCurrentChatId?.();
if (activeChatId) {
runtime.clearCurrentChatCommitMarker?.({
reason: "manual-delete-all-local-storage",
immediate: true,
resetAcceptedRevision: true,
if (typeof runtime.clearCurrentChatRecoveryAnchors === "function") {
runtime.clearCurrentChatRecoveryAnchors({
chatId: activeChatId,
reason: "manual-delete-all-local-storage",
immediate: true,
clearMetadataFull: true,
clearCommitMarker: true,
clearPendingPersist: true,
});
} else {
runtime.clearCurrentChatCommitMarker?.({
reason: "manual-delete-all-local-storage",
immediate: true,
resetAcceptedRevision: true,
});
}
await runtime.refreshCurrentChatLocalStoreBinding?.({
chatId: activeChatId,
forceCapabilityRefresh: true,
reopenCurrentDb: true,
source: "manual-delete-all-local-storage",
});
runtime.syncGraphLoadFromLiveContext?.({
source: "manual-delete-all-local-storage",