mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
Fix chat metadata integrity persistence
This commit is contained in:
21
index.js
21
index.js
@@ -1596,7 +1596,6 @@ function persistGraphToChatMetadata(
|
||||
reason = "graph-persist",
|
||||
revision = graphPersistenceState.revision,
|
||||
immediate = false,
|
||||
rotateIntegrity = false,
|
||||
} = {},
|
||||
) {
|
||||
if (!context || !currentGraph) {
|
||||
@@ -1618,9 +1617,7 @@ function persistGraphToChatMetadata(
|
||||
});
|
||||
}
|
||||
|
||||
const nextIntegrity = rotateIntegrity
|
||||
? createLocalIntegritySlug()
|
||||
: getChatMetadataIntegrity(context);
|
||||
const nextIntegrity = getChatMetadataIntegrity(context);
|
||||
stampGraphPersistenceMeta(currentGraph, {
|
||||
revision,
|
||||
reason,
|
||||
@@ -1629,7 +1626,6 @@ function persistGraphToChatMetadata(
|
||||
});
|
||||
writeChatMetadataPatch(context, {
|
||||
[GRAPH_METADATA_KEY]: currentGraph,
|
||||
...(nextIntegrity ? { integrity: nextIntegrity } : {}),
|
||||
});
|
||||
const saveMode = triggerChatMetadataSave(context, { immediate });
|
||||
|
||||
@@ -1669,7 +1665,7 @@ function persistGraphToChatMetadata(
|
||||
function queueGraphPersist(
|
||||
reason = "graph-persist-blocked",
|
||||
revision = graphPersistenceState.revision,
|
||||
{ immediate = true, rotateIntegrity = true } = {},
|
||||
{ immediate = true } = {},
|
||||
) {
|
||||
maybeCaptureGraphShadowSnapshot(reason);
|
||||
updateGraphPersistenceState({
|
||||
@@ -1678,7 +1674,7 @@ function queueGraphPersist(
|
||||
revision || 0,
|
||||
),
|
||||
queuedPersistMode: immediate ? "immediate" : "debounced",
|
||||
queuedPersistRotateIntegrity: Boolean(rotateIntegrity),
|
||||
queuedPersistRotateIntegrity: false,
|
||||
queuedPersistReason: String(reason || ""),
|
||||
pendingPersist: true,
|
||||
writesBlocked: true,
|
||||
@@ -1731,7 +1727,6 @@ function maybeFlushQueuedGraphPersist(reason = "queued-graph-persist") {
|
||||
reason,
|
||||
revision: targetRevision,
|
||||
immediate: graphPersistenceState.queuedPersistMode !== "debounced",
|
||||
rotateIntegrity: graphPersistenceState.queuedPersistRotateIntegrity,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2682,7 +2677,7 @@ function loadGraphFromChat(options = {}) {
|
||||
updateGraphPersistenceState({
|
||||
metadataIntegrity,
|
||||
queuedPersistMode: "immediate",
|
||||
queuedPersistRotateIntegrity: true,
|
||||
queuedPersistRotateIntegrity: false,
|
||||
queuedPersistReason: "shadow-snapshot-newer-than-official",
|
||||
});
|
||||
const persistResult = maybeFlushQueuedGraphPersist(
|
||||
@@ -2816,7 +2811,7 @@ function loadGraphFromChat(options = {}) {
|
||||
updateGraphPersistenceState({
|
||||
metadataIntegrity: getChatMetadataIntegrity(context),
|
||||
queuedPersistMode: "immediate",
|
||||
queuedPersistRotateIntegrity: true,
|
||||
queuedPersistRotateIntegrity: false,
|
||||
queuedPersistReason: "shadow-snapshot-promoted",
|
||||
});
|
||||
const persistResult = maybeFlushQueuedGraphPersist(
|
||||
@@ -2855,7 +2850,7 @@ function loadGraphFromChat(options = {}) {
|
||||
});
|
||||
updateGraphPersistenceState({
|
||||
queuedPersistMode: "immediate",
|
||||
queuedPersistRotateIntegrity: true,
|
||||
queuedPersistRotateIntegrity: false,
|
||||
queuedPersistReason: shouldRetry
|
||||
? "shadow-snapshot-restored"
|
||||
: "shadow-snapshot-blocked",
|
||||
@@ -3026,7 +3021,6 @@ function saveGraphToChat(options = {}) {
|
||||
markMutation = true,
|
||||
captureShadow = true,
|
||||
immediate = markMutation,
|
||||
rotateIntegrity = markMutation,
|
||||
} = options;
|
||||
|
||||
ensureCurrentGraphRuntimeState();
|
||||
@@ -3068,14 +3062,13 @@ function saveGraphToChat(options = {}) {
|
||||
console.warn(
|
||||
`[ST-BME] 图谱写回已被安全保护拦截(chat=${chatId},state=${graphPersistenceState.loadState},reason=${reason})`,
|
||||
);
|
||||
return queueGraphPersist(reason, revision, { immediate, rotateIntegrity });
|
||||
return queueGraphPersist(reason, revision, { immediate });
|
||||
}
|
||||
|
||||
return persistGraphToChatMetadata(context, {
|
||||
reason,
|
||||
revision,
|
||||
immediate,
|
||||
rotateIntegrity,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -637,6 +637,11 @@ result = {
|
||||
?.title,
|
||||
"事件-shadow-newer",
|
||||
);
|
||||
assert.equal(
|
||||
reader.runtimeContext.__chatContext.chatMetadata?.integrity,
|
||||
"integrity-official-older",
|
||||
"影子快照补写正式图谱时不能改写宿主 metadata.integrity",
|
||||
);
|
||||
assert.equal(
|
||||
reader.api.readGraphShadowSnapshot("chat-shadow-newer"),
|
||||
null,
|
||||
@@ -724,8 +729,8 @@ result = {
|
||||
assert.equal(
|
||||
harness.runtimeContext.__chatContext.chatMetadata?.integrity ===
|
||||
"integrity-before-first-save",
|
||||
false,
|
||||
"真正改图后应轮换 metadata.integrity,阻止旧页面覆盖",
|
||||
true,
|
||||
"插件保存图谱时不能改写宿主 metadata.integrity",
|
||||
);
|
||||
assert.equal(
|
||||
harness.runtimeContext.__chatContext.chatMetadata?.st_bme_graph?.__stBmePersistence
|
||||
@@ -765,6 +770,11 @@ result = {
|
||||
reader.runtimeContext.__chatContext.chatMetadata?.st_bme_graph?.nodes?.length,
|
||||
1,
|
||||
);
|
||||
assert.equal(
|
||||
reader.runtimeContext.__chatContext.chatMetadata?.integrity,
|
||||
"meta-ready-promote",
|
||||
"metadata 就绪后提升影子快照时不能改写宿主 metadata.integrity",
|
||||
);
|
||||
assert.equal(reader.runtimeContext.__contextImmediateSaveCalls, 1);
|
||||
assert.equal(reader.runtimeContext.__contextSaveCalls, 0);
|
||||
assert.equal(live.lastPersistedRevision, 9);
|
||||
|
||||
Reference in New Issue
Block a user