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): retain retries for failed voiceprint logout cleanup

DavidShen8f18ddca0776
diff --git a/apps/mobile/src/__tests__/mobileSpeakerFilter.test.ts b/apps/mobile/src/__tests__/mobileSpeakerFilter.test.ts
index 4ca21aeeb5..08ef0d1659 100644
--- a/apps/mobile/src/__tests__/mobileSpeakerFilter.test.ts
+++ b/apps/mobile/src/__tests__/mobileSpeakerFilter.test.ts
@@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { buildSpeakerEnrollment, SPEAKER_MODEL_ASSETS, SpeakerGate, speakerModelAsset, speakerModelLocalName } from '@cindy/voice-input-core';
import AsyncStorage from '@react-native-async-storage/async-storage';
import * as FileSystem from 'expo-file-system/legacy';
-import { getSecureItem, setSecureItem } from '@/auth/secureStorage';
+import { deleteSecureItem, getSecureItem, setSecureItem } from '@/auth/secureStorage';
import { loadSpeakerModels, nativeSpeakerOnnxRunner } from '../../modules/cindy-speaker-onnx/src';
vi.mock('@cindy/voice-input-core', async (importOriginal) => {
@@ -416,6 +416,25 @@ describe('mobile speaker filter', () => {
expect(service.createMobileSpeakerGate()).toBeUndefined();
});
+ it('does not restore a logged-out voiceprint on sign-in until cleanup succeeds', async () => {
+ installModels();
+ const key = await signIn('user-a');
+ storeProfile(key);
+ await service.setMobileSpeakerFilterEnabled(true);
+ setMobileAuthOwner(null);
+ const { clearMobileSpeakerFilterForAccount } = await import('@/session/mobileSpeakerFilterStorage');
+ vi.mocked(deleteSecureItem)
+ .mockRejectedValueOnce(new Error('keychain unavailable'))
+ .mockRejectedValueOnce(new Error('keychain still unavailable'));
+ await expect(clearMobileSpeakerFilterForAccount(key)).rejects.toThrow('cleanup pending');
+ await signIn('user-a');
+ expect(secureStore.has(service.__testing.profileKey(key))).toBe(true);
+ expect(service.getMobileSpeakerFilterSnapshot()).toMatchObject({ hydrated: false, enabled: false, enrolled: false });
+ await service.hydrateMobileSpeakerFilter();
+ expect(secureStore.has(service.__testing.profileKey(key))).toBe(false);
+ expect(service.getMobileSpeakerFilterSnapshot()).toMatchObject({ hydrated: true, enabled: false, enrolled: false });
+ });
+
it('deletes the voiceprint', async () => {
installModels();
const a = await signIn('user-a');
diff --git a/apps/mobile/src/__tests__/mobileSpeakerFilterStorage.test.ts b/apps/mobile/src/__tests__/mobileSpeakerFilterStorage.test.ts
new file mode 100644
index 0000000000..a01329c852
--- /dev/null
+++ b/apps/mobile/src/__tests__/mobileSpeakerFilterStorage.test.ts
@@ -0,0 +1,146 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+const store = vi.hoisted(() => ({
+ prefs: new Map<string, string>(),
+ secure: new Map<string, string>(),
+ getItem: vi.fn(),
+ setItem: vi.fn(),
+ removeItem: vi.fn(),
+ getAllKeys: vi.fn(),
+ deleteSecureItem: vi.fn(),
+}));
+vi.mock('@react-native-async-storage/async-storage', () => ({ default: store }));
+vi.mock('@/auth/secureStorage', () => ({ deleteSecureItem: store.deleteSecureItem }));
+
+let storage: typeof import('@/session/mobileSpeakerFilterStorage');
+const account = 'global:fixture-a';
+const marker = `cindy.mobile.voice-speaker-filter.cleanup.v1.${account}`;
+
+beforeEach(async () => {
+ vi.resetModules();
+ store.prefs.clear();
+ store.secure.clear();
+ store.getItem.mockReset().mockImplementation(async key => store.prefs.get(key) ?? null);
+ store.setItem.mockReset().mockImplementation(async (key, value) => { store.prefs.set(key, value); });
+ store.removeItem.mockReset().mockImplementation(async key => { store.prefs.delete(key); });
+ store.getAllKeys.mockReset().mockImplementation(async () => [...store.prefs.keys()]);
+ store.deleteSecureItem.mockReset().mockImplementation(async key => { store.secure.delete(key); });
+ storage = await import('@/session/mobileSpeakerFilterStorage');
+});
+
+function seed(key = account): void {
+ store.prefs.set(storage.speakerFilterPrefsKey(key), 'fixture preferences');
+ store.secure.set(storage.speakerProfileKey(key), 'fixture voiceprint');
+}
+
+describe('speaker filter logout cleanup', () => {
+ it.each(['secure', 'prefs', 'both'] as const)('retries a failed %s deletion after a process restart without an auth owner', async failure => {
+ seed();
+ seed('cn:fixture-b');
+ if (failure !== 'prefs') store.deleteSecureItem.mockRejectedValueOnce(new Error('keychain unavailable'));
+ if (failure !== 'secure') store.removeItem.mockRejectedValueOnce(new Error('disk unavailable'));
+
+ await expect(storage.clearMobileSpeakerFilterForAccount(account)).rejects.toThrow('cleanup pending');
+ expect(store.deleteSecureItem).toHaveBeenCalledWith(storage.speakerProfileKey(account));
+ expect(store.removeItem).toHaveBeenCalledWith(storage.speakerFilterPrefsKey(account));
+ expect(store.prefs.get(marker)).toBe('1');
+
+ vi.resetModules();
+ storage = await import('@/session/mobileSpeakerFilterStorage');
+ await storage.retryPendingMobileSpeakerFilterCleanup();
+ expect(store.secure.has(storage.speakerProfileKey(account))).toBe(false);
+ expect(store.prefs.has(storage.speakerFilterPrefsKey(account))).toBe(false);
+ expect(store.prefs.has(marker)).toBe(false);
+ expect(store.secure.get(storage.speakerProfileKey('cn:fixture-b'))).toBe('fixture voiceprint');
+ expect(store.prefs.get(storage.speakerFilterPrefsKey('cn:fixture-b'))).toBe('fixture preferences');
+ });
+
+ it('does not read or overwrite a voiceprint while logout cleanup is still failing', async () => {
+ seed();
+ store.deleteSecureItem.mockRejectedValue(new Error('keychain unavailable'));
+ await expect(storage.clearMobileSpeakerFilterForAccount(account)).rejects.toThrow();
+ const access = vi.fn(async () => 'old profile');
+ await expect(storage.serializeSpeakerFilterStorage(account, access)).rejects.toThrow();
+ expect(access).not.toHaveBeenCalled();
+
+ store.deleteSecureItem.mockImplementation(async key => { store.secure.delete(key); });
+ await storage.serializeSpeakerFilterStorage(account, async () => {
+ expect(store.secure.has(storage.speakerProfileKey(account))).toBe(false);
+ store.secure.set(storage.speakerProfileKey(account), 'new profile');
+ });
+ await storage.retryPendingMobileSpeakerFilterCleanup();
+ expect(store.secure.get(storage.speakerProfileKey(account))).toBe('new profile');
+ });
+
+ it('retains an in-memory retry if persisting the marker and enumerating storage fail', async () => {
+ seed();
+ store.setItem.mockRejectedValueOnce(new Error('disk full'));
+ store.deleteSecureItem.mockRejectedValueOnce(new Error('keychain unavailable'));
+ await expect(storage.clearMobileSpeakerFilterForAccount(account)).rejects.toThrow();
+ expect(store.prefs.has(marker)).toBe(false);
+ store.getAllKeys.mockRejectedValueOnce(new Error('storage unavailable'));
+ await expect(storage.retryPendingMobileSpeakerFilterCleanup()).rejects.toThrow();
+ expect(store.secure.has(storage.speakerProfileKey(account))).toBe(false);
+ await storage.retryPendingMobileSpeakerFilterCleanup();
+ });
+
+ it('still removes both account stores if writing the retry marker fails', async () => {
+ seed();
+ store.setItem.mockRejectedValueOnce(new Error('disk full'));
+ await storage.clearMobileSpeakerFilterForAccount(account);
+ expect(store.secure.size).toBe(0);
+ expect(store.prefs.size).toBe(0);
+ });
+
+ it('retries removing the marker before allowing a new profile to be saved', async () => {
+ seed();
+ store.removeItem.mockImplementationOnce(async key => { store.prefs.delete(key); })
+ .mockRejectedValueOnce(new Error('marker removal failed'));
+ await expect(storage.clearMobileSpeakerFilterForAccount(account)).rejects.toThrow('marker removal failed');
+ expect(store.secure.size).toBe(0);
+ expect(store.prefs.has(marker)).toBe(true);
+ await storage.serializeSpeakerFilterStorage(account, async () => {
+ expect(store.prefs.has(marker)).toBe(false);
+ store.secure.set(storage.speakerProfileKey(account), 'new profile');
+ });
+ await storage.retryPendingMobileSpeakerFilterCleanup();
+ expect(store.secure.get(storage.speakerProfileKey(account))).toBe('new profile');
+ });
+
+ it('rechecks stale retry enumeration before deleting a newly enrolled voiceprint', async () => {
+ seed();
+ store.deleteSecureItem.mockRejectedValueOnce(new Error('keychain unavailable'));
+ await expect(storage.clearMobileSpeakerFilterForAccount(account)).rejects.toThrow();
+ let release!: (keys: string[]) => void;
+ store.getAllKeys.mockImplementationOnce(() => new Promise(resolve => { release = resolve; }));
+ const retry = storage.retryPendingMobileSpeakerFilterCleanup();
+ await storage.serializeSpeakerFilterStorage(account, async () => {
+ store.secure.set(storage.speakerProfileKey(account), 'new profile');
+ });
+ release([marker]);
+ await retry;
+ expect(store.secure.get(storage.speakerProfileKey(account))).toBe('new profile');
+ });
+
+ it('attempts all pending accounts even when one remains unavailable', async () => {
+ seed();
+ seed('cn:fixture-b');
+ store.prefs.set(marker, '1');
+ store.prefs.set('cindy.mobile.voice-speaker-filter.cleanup.v1.cn:fixture-b', '1');
+ store.deleteSecureItem.mockImplementation(async key => {
+ if (key === storage.speakerProfileKey(account)) throw new Error('keychain unavailable');
+ store.secure.delete(key);
+ });
+ await expect(storage.retryPendingMobileSpeakerFilterCleanup()).rejects.toThrow();
+ expect(store.secure.has(storage.speakerProfileKey('cn:fixture-b'))).toBe(false);
+ expect(store.prefs.has('cindy.mobile.voice-speaker-filter.cleanup.v1.cn:fixture-b')).toBe(false);
+ expect(store.prefs.has(marker)).toBe(true);
+ });
+
+ it('does not interpret an unreadable marker as permission to read an old profile', async () => {
+ const access = vi.fn();
+ store.getItem.mockRejectedValueOnce(new Error('storage unavailable'));
+ await expect(storage.serializeSpeakerFilterStorage(account, access)).rejects.toThrow('storage unavailable');
+ expect(access).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/mobile/src/auth/AuthContext.tsx b/apps/mobile/src/auth/AuthContext.tsx
index 717aeefb47..2f1bd3ebf4 100644
--- a/apps/mobile/src/auth/AuthContext.tsx
+++ b/apps/mobile/src/auth/AuthContext.tsx
@@ -127,7 +127,7 @@ import { updateCredentialAccessToken } from '@/remote-desktop/credentialIdentity
import { clearCachedSessionMessages } from '@/session/mobileSessionMessageCache';
import { clearHistoryDisk } from '@/session/remoteHistoryDiskCache';
import { clearAllMobileVoiceCredentials } from '@/session/mobileVoiceCredentialStore';
-import { clearMobileSpeakerFilterForAccount } from '@/session/mobileSpeakerFilterStorage';
+import { clearMobileSpeakerFilterForAccount, retryPendingMobileSpeakerFilterCleanup } from '@/session/mobileSpeakerFilterStorage';
import {
clearAllMobileVoiceDictionaryCaches,
setMobileVoiceDictionaryAccountScope,
@@ -1445,6 +1445,19 @@ export function AuthProvider({ children }: { children: ReactNode }) {
],
);
+ useEffect(() => {
+ const retry = () => {
+ void retryPendingMobileSpeakerFilterCleanup().catch(() => {
+ console.warn('[auth] speaker filter cleanup pending; will retry');
+ });
+ };
+ retry();
+ const subscription = AppState.addEventListener('change', state => {
+ if (state === 'active') retry();
+ });
+ return () => subscription.remove();
+ }, []);
+
useEffect(() => {
let cancelled = false;
const epoch = loginFlowEpochRef.current;
@@ -2942,7 +2955,11 @@ export function AuthProvider({ children }: { children: ReactNode }) {
// deviceId,不清就会让下一个账号读到上一个账号的词条并发给润色模型。
await clearAllMobileVoiceDictionaryCaches().catch(() => undefined);
// 声纹是这个账号的生物特征数据,随账号的其他本机数据一起清;模型文件不含账号数据,保留。
- await clearMobileSpeakerFilterForAccount(invitationHistoryAccountKey);
+ await clearMobileSpeakerFilterForAccount(invitationHistoryAccountKey).catch(() => {
+ // The storage helper retains the account's retry marker. Still complete
+ // credential removal; neither an account id nor a voiceprint is logged.
+ console.warn('[auth] speaker filter cleanup pending; will retry');
+ });
await clearCachedSessionMessages().catch(() => undefined);
await clearHistoryDisk();
// 首页设备+会话快照与消息缓存一样属于账号数据,登出必须清掉。
diff --git a/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx b/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx
index 62e0ea30de..b917eb5fa5 100644
--- a/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx
+++ b/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx
@@ -13,6 +13,9 @@ const native = vi.hoisted(() => ({
writeSecure: vi.fn(),
logoutCleanup: vi.fn(),
unregisterPush: vi.fn(),
+ clearSpeaker: vi.fn(),
+ retrySpeaker: vi.fn(),
+ appStates: new Set<(state: string) => void>(),
links: new Set<(event: { url: string }) => void>(),
open: vi.fn(),
exchange: vi.fn(),
@@ -33,7 +36,12 @@ vi.mock('../../../app/(auth)/login', () => ({
}));
vi.mock('react-native', () => ({
Platform: { get OS() { return native.platform; } },
- AppState: { addEventListener: () => ({ remove() {} }) },
+ AppState: {
+ addEventListener: (_: string, listener: (state: string) => void) => {
+ native.appStates.add(listener);
+ return { remove: () => native.appStates.delete(listener) };
+ },
+ },
Linking: {
getInitialURL: native.initialUrl,
addEventListener: (_: string, listener: (event: { url: string }) => void) => {
@@ -107,6 +115,10 @@ vi.mock('@/remote-desktop/credentialIdentity', () => ({ updateCredentialAccessTo
vi.mock('@/session/mobileSessionMessageCache', () => ({ clearCachedSessionMessages: async () => {} }));
vi.mock('@/session/remoteHistoryDiskCache', () => ({ clearHistoryDisk: async () => {} }));
vi.mock('@/session/mobileVoiceCredentialStore', () => ({ clearAllMobileVoiceCredentials: async () => {} }));
+vi.mock('@/session/mobileSpeakerFilterStorage', () => ({
+ clearMobileSpeakerFilterForAccount: native.clearSpeaker,
+ retryPendingMobileSpeakerFilterCleanup: native.retrySpeaker,
+}));
vi.mock('@/session/mobileVoiceDictionaryCache', () => ({ setMobileVoiceDictionaryAccountScope() {}, clearAllMobileVoiceDictionaryCaches: async () => {} }));
vi.mock('@/session/mobileVoiceHistoryStore', () => ({ clearAllMobileVoiceInputHistories: async () => {} }));
vi.mock('@/debug/visualMock', () => ({}));
@@ -190,6 +202,8 @@ describe('browser auth session lifecycle (real AuthProvider, mocked native/netwo
native.writeSecure.mockReset().mockImplementation(async (key: string, value: string) => { native.storage.set(key, value); });
native.logoutCleanup.mockReset();
native.unregisterPush.mockReset();
+ native.clearSpeaker.mockReset().mockResolvedValue(undefined);
+ native.retrySpeaker.mockReset().mockResolvedValue(undefined);
native.deleteSecure.mockReset().mockImplementation(async (key: string) => { native.storage.delete(key); });
native.readSecure.mockReset().mockImplementation(async (key: string) => native.storage.get(key) ?? null);
native.state = 0;
@@ -207,9 +221,49 @@ describe('browser auth session lifecycle (real AuthProvider, mocked native/netwo
afterEach(async () => {
await act(async () => root.unmount());
expect(native.links.size).toBe(0);
+ expect(native.appStates.size).toBe(0);
vi.restoreAllMocks();
});
+ it('retries voiceprint cleanup on startup and foreground while signed out', async () => {
+ expect(auth.isAuthenticated).toBe(false);
+ expect(native.retrySpeaker).toHaveBeenCalledTimes(1);
+ await act(async () => { for (const listener of native.appStates) listener('background'); });
+ expect(native.retrySpeaker).toHaveBeenCalledTimes(1);
+ await act(async () => { for (const listener of native.appStates) listener('active'); });
+ expect(native.retrySpeaker).toHaveBeenCalledTimes(2);
+ });
+
+ it('keeps the foreground retry registered after cleanup fails at startup', async () => {
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ native.retrySpeaker.mockRejectedValueOnce(new Error('keychain unavailable'));
+ await restartProvider();
+ expect(auth.initialized).toBe(true);
+ expect(warn).toHaveBeenCalledWith('[auth] speaker filter cleanup pending; will retry');
+ native.retrySpeaker.mockClear();
+ await act(async () => { for (const listener of native.appStates) listener('active'); });
+ expect(native.retrySpeaker).toHaveBeenCalledTimes(1);
+ });
+
+ it.each(['logout', 'terminateSession'] as const)('finishes %s credential cleanup when voiceprint deletion fails', async action => {
+ const { setMobileAuthOwner, getMobileAuthOwner } = await import('../authOwnerGeneration');
+ setMobileAuthOwner('speaker-fixture', 'cn');
+ const owner = getMobileAuthOwner();
+ native.storage.set('cindy.mobile.auth.session.v1', 'fixture session');
+ native.storage.set('cindy.mobile.auth.userProfile', 'fixture user');
+ native.logoutCleanup.mockImplementationOnce(async () => {
+ native.storage.delete('cindy.mobile.auth.session.v1');
+ });
+ native.clearSpeaker.mockRejectedValueOnce(new Error('keychain unavailable'));
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ await act(async () => { await auth[action](); });
+ expect(native.clearSpeaker).toHaveBeenCalledWith(owner.accountKey);
+ expect(native.storage.has('cindy.mobile.auth.session.v1')).toBe(false);
+ expect(native.storage.has('cindy.mobile.auth.userProfile')).toBe(false);
+ expect(getMobileAuthOwner().accountKey).toBe('');
+ expect(warn).toHaveBeenCalledWith('[auth] speaker filter cleanup pending; will retry');
+ });
+
it.each(['sso', 'social'] as const)('retains %s login on Android dismiss and accepts a delayed deep link', async (kind) => {
await start(kind);
expect(auth.loginState?.step).toBe('browser-redirect');
diff --git a/apps/mobile/src/session/mobileSpeakerFilterStorage.ts b/apps/mobile/src/session/mobileSpeakerFilterStorage.ts
index 18560e291e..84484ae22e 100644
--- a/apps/mobile/src/session/mobileSpeakerFilterStorage.ts
+++ b/apps/mobile/src/session/mobileSpeakerFilterStorage.ts
@@ -12,10 +12,12 @@ import { deleteSecureItem } from '@/auth/secureStorage';
const PREFS_PREFIX = 'cindy.mobile.voice-speaker-filter.v1.';
// SecureStore keys only allow [A-Za-z0-9._-]; the account key is hashed.
const PROFILE_PREFIX = 'xdt.voiceSpeakerProfile.v1.';
+const CLEANUP_PREFIX = 'cindy.mobile.voice-speaker-filter.cleanup.v1.';
const pending = new Map<string, Promise<unknown>>();
+// Also retain failures in memory if AsyncStorage cannot write the retry marker.
+const pendingCleanup = new Set<string>();
-/** Keep deletion (including sign-out) after writes already in flight. */
-export function serializeSpeakerFilterStorage<T>(accountKey: string, operation: () => Promise<T>): Promise<T> {
+function enqueue<T>(accountKey: string, operation: () => Promise<T>): Promise<T> {
const run = (pending.get(accountKey) ?? Promise.resolve()).catch(() => undefined).then(operation);
pending.set(accountKey, run);
const clear = () => {
@@ -25,6 +27,14 @@ export function serializeSpeakerFilterStorage<T>(accountKey: string, operation:
return run;
}
+/** Finish a previous sign-out's cleanup before this account can read or write again. */
+export function serializeSpeakerFilterStorage<T>(accountKey: string, operation: () => Promise<T>): Promise<T> {
+ return enqueue(accountKey, async () => {
+ await retryAccountCleanup(accountKey);
+ return operation();
+ });
+}
+
export function speakerFilterPrefsKey(accountKey: string): string {
return PREFS_PREFIX + accountKey;
}
@@ -40,10 +50,53 @@ export function speakerProfileKey(accountKey: string): string {
*/
export async function clearMobileSpeakerFilterForAccount(accountKey: string): Promise<void> {
if (!accountKey) return;
- await serializeSpeakerFilterStorage(accountKey, async () => {
- await Promise.all([
- deleteSecureItem(speakerProfileKey(accountKey)).catch(() => undefined),
- AsyncStorage.removeItem(speakerFilterPrefsKey(accountKey)).catch(() => undefined),
- ]);
- });
+ pendingCleanup.add(accountKey);
+ await enqueue(accountKey, () => clearStoredAccount(accountKey));
+}
+
+/** Called at startup and on foreground, even while signed out. */
+export async function retryPendingMobileSpeakerFilterCleanup(): Promise<void> {
+ const accounts = new Set(pendingCleanup);
+ const errors: unknown[] = [];
+ try {
+ for (const key of await AsyncStorage.getAllKeys()) {
+ if (key.startsWith(CLEANUP_PREFIX) && key.length > CLEANUP_PREFIX.length) {
+ accounts.add(key.slice(CLEANUP_PREFIX.length));
+ }
+ }
+ } catch (error) {
+ errors.push(error);
+ }
+ const results = await Promise.allSettled([...accounts].map(accountKey =>
+ // Recheck inside the queue: an earlier retry may already have cleared the
+ // marker and allowed a newly enrolled profile to be saved.
+ enqueue(accountKey, () => retryAccountCleanup(accountKey)),
+ ));
+ for (const result of results) {
+ if (result.status === 'rejected') errors.push(result.reason);
+ }
+ if (errors.length) throw new AggregateError(errors, 'Speaker filter cleanup pending');
+}
+
+async function retryAccountCleanup(accountKey: string): Promise<void> {
+ if (pendingCleanup.has(accountKey) || await AsyncStorage.getItem(CLEANUP_PREFIX + accountKey) !== null) {
+ await clearStoredAccount(accountKey);
+ }
+}
+
+// Only called under the account queue, shared with enrollment and preferences.
+async function clearStoredAccount(accountKey: string): Promise<void> {
+ pendingCleanup.add(accountKey);
+ const marker = CLEANUP_PREFIX + accountKey;
+ // The marker contains no voiceprint. Keep trying both deletions even if the
+ // disk cannot persist it; the in-memory entry still enables a later retry.
+ await AsyncStorage.setItem(marker, '1').catch(() => undefined);
+ const results = await Promise.allSettled([
+ deleteSecureItem(speakerProfileKey(accountKey)),
+ AsyncStorage.removeItem(speakerFilterPrefsKey(accountKey)),
+ ]);
+ const errors = results.flatMap(result => result.status === 'rejected' ? [result.reason] : []);
+ if (errors.length) throw new AggregateError(errors, 'Speaker filter cleanup pending');
+ await AsyncStorage.removeItem(marker);
+ pendingCleanup.delete(accountKey);
}
diff --git a/docs/dev-rules/credentials-and-local-storage.md b/docs/dev-rules/credentials-and-local-storage.md
index bfbddde1ea..f624512f64 100644
--- a/docs/dev-rules/credentials-and-local-storage.md
+++ b/docs/dev-rules/credentials-and-local-storage.md
@@ -211,7 +211,7 @@ Desktop 的运行时 refresh 遇到瞬时失败后,主动调用与定时重试
| 供应商分享:跨区域标记 | `userData/remote-agent/provider-share-regions.json`,账号摘要 → 对方区域;**不含凭证**。跨区连接凭证只在内存里,用新身份名片重新换取;没有标记的账号从不联系对方区域 |
| 语音输入声纹(生物特征) | `userData/owners/<账号>/voice-speaker-profile.json`,「识别我的声音」录入的声纹向量与录入时间,经 `safeStorage` 加密后整体落盘(钥匙串不可用时拒绝写入,不降级明文);记录生成它的模型哈希,换模型后视为未录入。只在本机,不同步、不上传、不进日志(日志只记分数与次数);用户删除即删文件。录入用的朗读音频只在内存中处理,不落盘 |
| 语音输入声纹识别模型 | `userData/voice-models/<哈希前缀>-<文件名>.onnx`,按内容哈希从区域 CDN 下载并在可见前校验 SHA-256;不含个人数据,本机所有账号共用。新版本模型下载完成后删除旧版本文件 |
-| Mobile 语音输入声纹(生物特征) | SecureStore(iOS 钥匙串 / Android Keystore)键 `xdt.voiceSpeakerProfile.v1.<账号 key 的 SHA-256 前 32 位>`,内容同 Desktop:声纹向量、录入时间与模型哈希;开关与灵敏度 override 在 AsyncStorage `cindy.mobile.voice-speaker-filter.v1.<账号 key>`。只在本机,不同步、不上传、不进日志;退出登录时随该账号的其他本机数据一起删除(模型文件保留);朗读音频只在内存中处理 |
+| Mobile 语音输入声纹(生物特征) | SecureStore(iOS 钥匙串 / Android Keystore)键 `xdt.voiceSpeakerProfile.v1.<账号 key 的 SHA-256 前 32 位>`,内容同 Desktop:声纹向量、录入时间与模型哈希;开关与灵敏度 override 在 AsyncStorage `cindy.mobile.voice-speaker-filter.v1.<账号 key>`。只在本机,不同步、不上传、不进日志;退出登录时随该账号的其他本机数据一起删除(模型文件保留)。删除前写 AsyncStorage `cindy.mobile.voice-speaker-filter.cleanup.v1.<账号 key>` 重试标记,不含声纹;失败时保留标记,启动、回到前台及该账号下次读写前重试,全部删除成功后才移除。标记落盘也失败时保留进程内重试,无法保证进程终止后的恢复;不因声纹删除失败阻止退出凭证清除。朗读音频只在内存中处理 |
| Mobile 语音输入声纹识别模型 | `cacheDirectory/voice-models/`,与 Desktop 同一组按内容哈希下载、校验 SHA-256 后才可见的文件;放缓存目录以免进入 iCloud / Android 备份。系统清理缓存后,下次语音输入发现缺失会在后台重新下载,本次不过滤 |
| 供应商分享:受邀者对分享的本机偏好 | `userData/owners/<账号>/provider-share-guest-prefs.json`,分享 id → 分享所属区域与「信任 {分享者}」(凭证操作不再确认);只存显式打开的项,在同路径 `.lock` 跨进程安全锁内重读、修改和原子替换,拿不到锁不保存。持有权切换使排队和在途写入失效;已进入文件系统的替换在新持有者保存前完成,不能覆盖其撤销。不含昵称、对话或凭证。退出分享或分享从已确认区域的权威名单里消失时清掉 |
| 用户明确导出的文件 | 用户选择或任务明确指定的目标路径 |