fix: guard luker panel graph load retries

This commit is contained in:
Youzini-afk
2026-04-14 22:02:31 +08:00
parent 19ca6f5d9d
commit 4b19e978c7
2 changed files with 45 additions and 0 deletions

View File

@@ -8989,6 +8989,10 @@ function shouldSyncGraphLoadFromLiveContext(
function syncGraphLoadFromLiveContext(options = {}) { function syncGraphLoadFromLiveContext(options = {}) {
const { source = "live-context-sync", force = false } = options; const { source = "live-context-sync", force = false } = options;
const attemptIndex = Math.max(
0,
Math.floor(Number(options?.attemptIndex) || 0),
);
const context = getContext(); const context = getContext();
syncCommitMarkerToPersistenceState(context); syncCommitMarkerToPersistenceState(context);
if (!shouldSyncGraphLoadFromLiveContext(context, { force })) { if (!shouldSyncGraphLoadFromLiveContext(context, { force })) {

View File

@@ -1848,6 +1848,47 @@ result = {
assert.equal(result.reason, "no-sync-needed"); assert.equal(result.reason, "no-sync-needed");
} }
{
const harness = await createGraphPersistenceHarness({
chatId: "chat-luker-panel-open",
globalChatId: "chat-luker-panel-open",
characterId: "char-luker-panel-open",
chatMetadata: {
integrity: "chat-luker-panel-open-integrity",
},
});
harness.runtimeContext.Luker = {
getContext() {
return harness.runtimeContext.__chatContext;
},
};
harness.api.setGraphPersistenceState({
loadState: "idle",
chatId: "chat-luker-panel-open",
reason: "cold-start",
revision: 0,
lastPersistedRevision: 0,
dbReady: false,
writesBlocked: false,
});
const result = harness.api.syncGraphLoadFromLiveContext({
source: "panel-open-sync",
});
assert.equal(
result.reason,
"luker-chat-state-probe-pending",
"Luker 面板打开时应进入 chat-state probe而不是抛出未定义变量异常",
);
assert.equal(result.attemptIndex, 0);
assert.equal(harness.api.getGraphPersistenceState().loadState, "loading");
assert.equal(
harness.api.getGraphPersistenceState().primaryStorageTier,
"luker-chat-state",
);
}
{ {
const metadataGraph = stampPersistedGraph( const metadataGraph = stampPersistedGraph(
createMeaningfulGraph("chat-stale-metadata", "metadata-older"), createMeaningfulGraph("chat-stale-metadata", "metadata-older"),