refactor(sync): extract graph load/persist/authority cluster (Phase 5d)

This commit is contained in:
youzini
2026-05-31 13:16:13 +00:00
parent 00c603356c
commit 8259dba003
3 changed files with 2029 additions and 928 deletions

1075
index.js

File diff suppressed because it is too large Load Diff

1840
sync/graph-load-persist.js Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -95,6 +95,7 @@ import {
} from "../retrieval/recall-persistence.js";
import { getNodeDisplayName } from "../graph/node-labels.js";
import {
buildVectorCollectionId,
hasGraphPersistDirtyState,
normalizeGraphRuntimeState,
pruneGraphPersistDirtyState,
@@ -121,6 +122,7 @@ import {
normalizeAuthorityCapabilityState,
probeAuthorityCapabilities,
} from "../runtime/authority-capabilities.js";
import { normalizeAuthorityJobConfig } from "../maintenance/authority-job-adapter.js";
import { normalizeAuthorityBlobConfig } from "../maintenance/authority-blob-adapter.js";
import {
createAuthorityBrowserState,
@@ -186,6 +188,16 @@ import {
getPanelRuntimeStatusImpl,
readRuntimeDebugSnapshotImpl,
} from "../sync/graph-mutation-gate.js";
import {
buildBmeSyncRuntimeOptionsImpl,
loadGraphFromChatImpl,
maybeCaptureGraphShadowSnapshotImpl,
persistExtractionBatchResultImpl,
shouldUseAuthorityGraphStoreImpl,
shouldUseAuthorityJobsImpl,
syncGraphLoadFromLiveContextImpl,
writeAuthorityCheckpointFromCurrentGraphImpl,
} from "../sync/graph-load-persist.js";
import {
consumeRerollRecallReuseMarker,
createRerollRecallReuseMarker,
@@ -715,6 +727,20 @@ async function createGraphPersistenceHarness({
return result;
}
function buildPersistenceEnvironment(
context = null,
presentation = { storagePrimary: "indexeddb", storageMode: "indexeddb" },
) {
const hostProfile = resolveBmeHostProfile(context);
const primaryStorageTier = String(presentation?.storagePrimary || "indexeddb");
const cacheStorageTier = primaryStorageTier === "authority" ? "indexeddb" : "none";
return {
hostProfile,
primaryStorageTier,
cacheStorageTier,
};
}
const runtimeContext = {
console,
Date,
@@ -746,6 +772,7 @@ async function createGraphPersistenceHarness({
createDefaultAuthorityCapabilityState,
normalizeAuthoritySettings,
normalizeAuthorityCapabilityState,
normalizeAuthorityJobConfig,
probeAuthorityCapabilities,
isAuthorityVectorConfig,
normalizeAuthorityVectorConfig,
@@ -830,6 +857,14 @@ async function createGraphPersistenceHarness({
getGraphPersistenceLiveStateImpl,
getPanelRuntimeStatusImpl,
readRuntimeDebugSnapshotImpl,
buildBmeSyncRuntimeOptionsImpl,
loadGraphFromChatImpl,
maybeCaptureGraphShadowSnapshotImpl,
persistExtractionBatchResultImpl,
shouldUseAuthorityGraphStoreImpl,
shouldUseAuthorityJobsImpl,
syncGraphLoadFromLiveContextImpl,
writeAuthorityCheckpointFromCurrentGraphImpl,
consumeRerollRecallReuseMarker,
createRerollRecallReuseMarker,
createRecallMessageUiController() {
@@ -1329,6 +1364,10 @@ async function createGraphPersistenceHarness({
getRequestHeaders() {
return {};
},
recordAuthorityBlobSnapshot() {},
recordLocalPersistEarlyFailure(reason = "") {
runtimeContext.__lastLocalPersistEarlyFailure = String(reason || "");
},
__syncNowCalls: [],
async syncNow(chatId, options = {}) {
runtimeContext.__syncNowCalls.push({
@@ -1436,7 +1475,10 @@ async function createGraphPersistenceHarness({
buildGraphFromSnapshot,
buildPersistDelta,
buildPersistDeltaFromGraphDirtyState,
buildPersistenceEnvironment,
buildSnapshotFromGraph,
buildVectorCollectionId,
cloneGraphSnapshot: cloneGraphForPersistence,
evaluateNativeHydrateGate,
evaluatePersistNativeDeltaGate,
hasGraphPersistDirtyState,