fix: allow extraction with recoverable pending persist

This commit is contained in:
Youzini-afk
2026-04-23 02:33:44 +08:00
parent 35d5cfd6be
commit 13ccc33f0d
4 changed files with 244 additions and 3 deletions

View File

@@ -454,6 +454,28 @@ function isPersistenceRevisionAccepted(runtime, persistence = null) {
return Number.isFinite(lastAcceptedRevision) && lastAcceptedRevision >= persistenceRevision;
}
function hasRecoverablePendingPersistence(runtime) {
const persistenceState = runtime?.getGraphPersistenceState?.() || {};
if (persistenceState.pendingPersist !== true) {
return false;
}
const recoverableTier = String(
persistenceState.lastRecoverableStorageTier || "none",
).trim();
if (recoverableTier === "metadata-full") {
return true;
}
if (recoverableTier !== "shadow") {
return false;
}
const queuedRevision = Number(persistenceState.queuedPersistRevision || 0);
const shadowRevision = Number(persistenceState.shadowSnapshotRevision || 0);
if (!Number.isFinite(queuedRevision) || queuedRevision <= 0) {
return true;
}
return Number.isFinite(shadowRevision) && shadowRevision >= queuedRevision;
}
function getPendingPersistenceGateInfo(runtime) {
const graph = runtime?.getCurrentGraph?.();
const batchStatus = graph?.historyState?.lastBatchStatus || null;
@@ -479,10 +501,14 @@ function getPendingPersistenceGateInfo(runtime) {
async function maybeRetryPendingPersistence(runtime, reason = "pending-persist-retry") {
const gate = getPendingPersistenceGateInfo(runtime);
if (!gate || typeof runtime?.retryPendingGraphPersist !== "function") {
if (!gate) {
return gate;
}
if (typeof runtime?.retryPendingGraphPersist !== "function") {
return hasRecoverablePendingPersistence(runtime) ? null : gate;
}
try {
const retryResult = await runtime.retryPendingGraphPersist({ reason });
if (retryResult?.accepted === true) {
@@ -492,7 +518,11 @@ async function maybeRetryPendingPersistence(runtime, reason = "pending-persist-r
runtime?.console?.warn?.("[ST-BME] pending persistence retry failed", error);
}
return getPendingPersistenceGateInfo(runtime);
const nextGate = getPendingPersistenceGateInfo(runtime);
if (nextGate && hasRecoverablePendingPersistence(runtime)) {
return null;
}
return nextGate;
}
function formatPendingPersistenceGateMessage(runtime, operationLabel = "当前提取") {