From 4b19e978c7a19cf60c4e44a9919908c14dbcd1cc Mon Sep 17 00:00:00 2001 From: Youzini-afk <13153778771cx@gmail.com> Date: Tue, 14 Apr 2026 22:02:31 +0800 Subject: [PATCH] fix: guard luker panel graph load retries --- index.js | 4 ++++ tests/graph-persistence.mjs | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/index.js b/index.js index 657558c..d022b78 100644 --- a/index.js +++ b/index.js @@ -8989,6 +8989,10 @@ function shouldSyncGraphLoadFromLiveContext( function syncGraphLoadFromLiveContext(options = {}) { const { source = "live-context-sync", force = false } = options; + const attemptIndex = Math.max( + 0, + Math.floor(Number(options?.attemptIndex) || 0), + ); const context = getContext(); syncCommitMarkerToPersistenceState(context); if (!shouldSyncGraphLoadFromLiveContext(context, { force })) { diff --git a/tests/graph-persistence.mjs b/tests/graph-persistence.mjs index ce29ca5..285512f 100644 --- a/tests/graph-persistence.mjs +++ b/tests/graph-persistence.mjs @@ -1848,6 +1848,47 @@ result = { 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( createMeaningfulGraph("chat-stale-metadata", "metadata-older"),