Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): 旧账号落盘补偿不删新账号的同 host 快照

Dash3dc5043287e4
diff --git a/apps/mobile/src/__tests__/mobileVoiceDictionaryCache.test.ts b/apps/mobile/src/__tests__/mobileVoiceDictionaryCache.test.ts
index de6fc226f3..55134f5c4b 100644
--- a/apps/mobile/src/__tests__/mobileVoiceDictionaryCache.test.ts
+++ b/apps/mobile/src/__tests__/mobileVoiceDictionaryCache.test.ts
@@ -357,6 +357,31 @@ describe('账号切走之后落地的旧请求', () => {
await hydrateMobileVoiceDictionary(HOST);
expect(readCachedMobileVoiceDictionary(HOST)[0].text).toBe('账号B的词');
});
+
+ it('旧账号落盘补偿不删新账号已接收的同 host 快照', async () => {
+ persistGate.delaySnapshotWrites = true;
+ setMobileVoiceDictionaryAccountScope('user-a');
+ const older = applyMobileVoiceDictionarySnapshot(HOST, {
+ ok: true,
+ entries: [{ text: '账号A的词' }],
+ emittedAt: 1_000,
+ });
+ await Promise.resolve();
+ setMobileVoiceDictionaryAccountScope('user-b');
+ persistGate.delaySnapshotWrites = false;
+ const newer = applyMobileVoiceDictionarySnapshot(HOST, {
+ ok: true,
+ entries: [{ text: '账号B的词' }],
+ emittedAt: 2_000,
+ });
+ releaseSnapshotWrites();
+ await Promise.all([older, newer]);
+ expect(readCachedMobileVoiceDictionary(HOST)[0].text).toBe('账号B的词');
+ __resetMobileVoiceDictionaryCacheForTests();
+ setMobileVoiceDictionaryAccountScope('user-b');
+ await hydrateMobileVoiceDictionary(HOST);
+ expect(readCachedMobileVoiceDictionary(HOST)[0].text).toBe('账号B的词');
+ });
});
describe('在途请求的去重范围', () => {
diff --git a/apps/mobile/src/session/mobileVoiceDictionaryCache.ts b/apps/mobile/src/session/mobileVoiceDictionaryCache.ts
index a03e9006e9..771b588c25 100644
--- a/apps/mobile/src/session/mobileVoiceDictionaryCache.ts
+++ b/apps/mobile/src/session/mobileVoiceDictionaryCache.ts
@@ -356,7 +356,9 @@ function persistAcceptedSnapshot(
() => undefined,
);
if (epoch !== cacheEpoch) {
- memoryCache.delete(host);
+ // 只回收自己刚写的那份。内存按 host 不按账号分区,无条件 delete
+ // 会把新账号已经写入的同 host 快照一并抹掉,后续落盘也因身份检查失败而跳过。
+ if (memoryCache.get(host) === next) memoryCache.delete(host);
await AsyncStorage.removeItem(storageKeyForHost(host, scope)).catch(() => undefined);
}
});