mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
fix: allow extraction with recoverable pending persist
This commit is contained in:
@@ -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 = "当前提取") {
|
||||
|
||||
Reference in New Issue
Block a user