mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
Tighten extraction persistence success gating
This commit is contained in:
6
index.js
6
index.js
@@ -6505,7 +6505,11 @@ function updateProcessedHistorySnapshot(chat, lastProcessedAssistantFloor) {
|
|||||||
|
|
||||||
function shouldAdvanceProcessedHistory(batchStatus) {
|
function shouldAdvanceProcessedHistory(batchStatus) {
|
||||||
if (!batchStatus || typeof batchStatus !== "object") return false;
|
if (!batchStatus || typeof batchStatus !== "object") return false;
|
||||||
return batchStatus?.stages?.core?.outcome === "success";
|
return (
|
||||||
|
batchStatus?.stages?.core?.outcome === "success" &&
|
||||||
|
batchStatus?.stages?.finalize?.outcome === "success" &&
|
||||||
|
batchStatus?.completed === true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function computePostProcessArtifacts(
|
function computePostProcessArtifacts(
|
||||||
|
|||||||
@@ -254,17 +254,61 @@ export async function executeExtractionBatchController(
|
|||||||
signal,
|
signal,
|
||||||
batchStatus,
|
batchStatus,
|
||||||
);
|
);
|
||||||
const finalizedBatchStatus =
|
const batchStatusRef = effects?.batchStatus || batchStatus;
|
||||||
effects?.batchStatus ||
|
const persistResult = runtime.saveGraphToChat({
|
||||||
runtime.finalizeBatchStatus(batchStatus, runtime.getExtractionCount());
|
reason: "extraction-batch-complete",
|
||||||
|
persistMetadata: true,
|
||||||
|
captureShadow: true,
|
||||||
|
immediate: true,
|
||||||
|
});
|
||||||
|
const persistAccepted = Boolean(
|
||||||
|
persistResult?.saved || persistResult?.queued,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!persistAccepted) {
|
||||||
|
runtime.setBatchStageOutcome(
|
||||||
|
batchStatusRef,
|
||||||
|
"finalize",
|
||||||
|
"failed",
|
||||||
|
`图谱持久化失败: ${persistResult?.reason || "unknown-persist-failure"}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const finalizedBatchStatus = runtime.finalizeBatchStatus(
|
||||||
|
batchStatusRef,
|
||||||
|
runtime.getExtractionCount(),
|
||||||
|
);
|
||||||
|
|
||||||
runtime.getCurrentGraph().historyState.lastBatchStatus = {
|
runtime.getCurrentGraph().historyState.lastBatchStatus = {
|
||||||
...finalizedBatchStatus,
|
...finalizedBatchStatus,
|
||||||
historyAdvanced: runtime.shouldAdvanceProcessedHistory(finalizedBatchStatus),
|
historyAdvanced: runtime.shouldAdvanceProcessedHistory(finalizedBatchStatus),
|
||||||
|
persist: persistResult
|
||||||
|
? {
|
||||||
|
saved: Boolean(persistResult.saved),
|
||||||
|
queued: Boolean(persistResult.queued),
|
||||||
|
blocked: Boolean(persistResult.blocked),
|
||||||
|
reason: String(persistResult.reason || ""),
|
||||||
|
saveMode: String(persistResult.saveMode || ""),
|
||||||
|
revision: Number.isFinite(Number(persistResult.revision))
|
||||||
|
? Number(persistResult.revision)
|
||||||
|
: 0,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (runtime.getCurrentGraph().historyState.lastBatchStatus.historyAdvanced) {
|
if (runtime.getCurrentGraph().historyState.lastBatchStatus.historyAdvanced) {
|
||||||
runtime.updateProcessedHistorySnapshot(chat, endIdx);
|
runtime.updateProcessedHistorySnapshot(chat, endIdx);
|
||||||
|
} else if (!persistAccepted) {
|
||||||
|
runtime.setLastExtractionStatus(
|
||||||
|
"提取待恢复",
|
||||||
|
`楼层 ${startIdx}-${endIdx} 已抽取但未确认写盘成功,请稍后重试或检查持久化状态`,
|
||||||
|
"warning",
|
||||||
|
{ syncRuntime: true },
|
||||||
|
);
|
||||||
|
runtime.console?.warn?.("[ST-BME] extraction persist not accepted", {
|
||||||
|
chatId: runtime.getGraphPersistenceState?.()?.chatId || "",
|
||||||
|
persist: persistResult,
|
||||||
|
processedRange: [startIdx, endIdx],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const afterSnapshot = runtime.cloneGraphSnapshot(runtime.getCurrentGraph());
|
const afterSnapshot = runtime.cloneGraphSnapshot(runtime.getCurrentGraph());
|
||||||
@@ -282,7 +326,6 @@ export async function executeExtractionBatchController(
|
|||||||
extractionCountBefore,
|
extractionCountBefore,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
runtime.saveGraphToChat({ reason: "extraction-batch-complete" });
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: finalizedBatchStatus.completed,
|
success: finalizedBatchStatus.completed,
|
||||||
|
|||||||
Reference in New Issue
Block a user