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(desktop): safeStorage 持续不可用时升级为可操作的凭证库故障提示 (#1744)

DavidShenXD4295889a1c21
diff --git a/apps/desktop/src/main/__tests__/authCredentialStoreHealth.test.ts b/apps/desktop/src/main/__tests__/authCredentialStoreHealth.test.ts
new file mode 100644
index 0000000000..e4831695ca
--- /dev/null
+++ b/apps/desktop/src/main/__tests__/authCredentialStoreHealth.test.ts
@@ -0,0 +1,139 @@
+import { describe, expect, it } from 'vitest';
+import { readFileSync } from 'node:fs';
+import { resolve } from 'node:path';
+
+import {
+ CREDENTIAL_STORE_UNREADABLE_ESCALATION_THRESHOLD,
+ createCredentialStoreHealth,
+} from '../authCredentialStoreHealth';
+
+/**
+ * #1687:持久凭证库故障升级状态机。
+ *
+ * 守护的契约:refresh token 文件仍在但连续读不出时,不能无限 transient(此前
+ * 该路径失败 14+ 小时零提示),也不能立即清空登录态(会重新引入「钥匙串抖动
+ * 强制登出」的历史问题)。连续 N 次失败才升级、任何一次成功读取立即复位。
+ */
+describe('authCredentialStoreHealth', () => {
+ it('阈值之前保持瞬时语义,不升级', () => {
+ const health = createCredentialStoreHealth(5);
+ for (let i = 0; i < 4; i++) {
+ expect(health.noteReadFailure()).toBe(false);
+ expect(health.unavailable).toBe(false);
+ }
+ });
+
+ it('连续跨过阈值时恰好翻转一次(只广播一次)', () => {
+ const health = createCredentialStoreHealth(3);
+ expect(health.noteReadFailure()).toBe(false);
+ expect(health.noteReadFailure()).toBe(false);
+ expect(health.noteReadFailure()).toBe(true); // 第 3 次:翻转
+ expect(health.unavailable).toBe(true);
+ // 继续失败不再返回 true,避免每 60s 重复广播
+ expect(health.noteReadFailure()).toBe(false);
+ expect(health.unavailable).toBe(true);
+ });
+
+ it('失败与成功交替时永不升级(「连续」是全部语义)', () => {
+ const health = createCredentialStoreHealth(3);
+ for (let i = 0; i < 10; i++) {
+ expect(health.noteReadFailure()).toBe(false);
+ expect(health.noteReadFailure()).toBe(false);
+ expect(health.noteRecovered()).toBe(false); // 未升级时恢复不返回翻转信号
+ expect(health.unavailable).toBe(false);
+ }
+ });
+
+ it('升级后一次成功读取立即恢复并返回翻转信号,再恢复不重复', () => {
+ const health = createCredentialStoreHealth(2);
+ health.noteReadFailure();
+ expect(health.noteReadFailure()).toBe(true);
+ expect(health.noteRecovered()).toBe(true); // 恢复:翻转,广播一次
+ expect(health.unavailable).toBe(false);
+ expect(health.noteRecovered()).toBe(false); // 已恢复,不重复广播
+ });
+
+ it('恢复后重新计数,再次连续失败可再次升级', () => {
+ const health = createCredentialStoreHealth(2);
+ health.noteReadFailure();
+ health.noteReadFailure();
+ health.noteRecovered();
+ expect(health.noteReadFailure()).toBe(false); // 计数已清零
+ expect(health.noteReadFailure()).toBe(true); // 再次连续跨过阈值
+ });
+
+ it('reset 无条件复位且不返回信号(登出整体清态用)', () => {
+ const health = createCredentialStoreHealth(1);
+ health.noteReadFailure();
+ expect(health.unavailable).toBe(true);
+ health.reset();
+ expect(health.unavailable).toBe(false);
+ // reset 后计数也清零
+ expect(health.noteReadFailure()).toBe(true); // threshold=1,单次即翻转
+ });
+
+ it('默认阈值 × 60s 重试间隔 ≈ 5 分钟持续失败才升级', () => {
+ expect(CREDENTIAL_STORE_UNREADABLE_ESCALATION_THRESHOLD).toBe(5);
+ });
+});
+
+/**
+ * authManager 接线守卫(authManager 依赖 Electron 无法直接 import,沿用
+ * authSessionExpiredDetection.test.ts 的源码守卫模式)。
+ */
+describe('authManager credential-store escalation wiring', () => {
+ const authSource = readFileSync(resolve(process.cwd(), 'src/main/authManager.ts'), 'utf8').replace(
+ /\r\n/g,
+ '\n',
+ );
+
+ it('transient-unreadable 分支喂失败计数并在翻转时广播,但仍保持瞬时语义', () => {
+ const start = authSource.indexOf('export async function refresh(): Promise<boolean> {');
+ const end = authSource.indexOf('const diskTokenChangedBeforeRefresh', start);
+ const body = authSource.slice(start, end);
+
+ // 升级钩子必须在 transient 分支内、且仍然 return false + 重排重试
+ // (升级不改变「不强踢用户」的语义,只是多了状态广播)。
+ expect(body).toContain('credentialStoreHealth.noteReadFailure()');
+ const noteIdx = body.indexOf('credentialStoreHealth.noteReadFailure()');
+ expect(noteIdx).toBeGreaterThan(body.indexOf('treating as transient'));
+ // 注意 refresh body 更早处(realm manifest 分支)也调用了同名重排函数,
+ // 必须取 noteReadFailure 之后的那一次。
+ const retryAfterNote = body.indexOf('scheduleRefreshRetryAfterTransientFailure();', noteIdx);
+ expect(retryAfterNote).toBeGreaterThan(noteIdx);
+ // 升级不改变瞬时语义:transient 分支内不得出现实际的过期 / 清态调用
+ // (匹配调用形态,避免误中提及函数名的注释)。
+ const transientBranch = body.slice(body.indexOf('treating as transient'), retryAfterNote);
+ expect(transientBranch).not.toContain('await expireRuntimeAuth(');
+ expect(transientBranch).not.toContain('clearAuth(');
+ });
+
+ it('成功读到持久会话时喂恢复并在翻转时广播', () => {
+ const start = authSource.indexOf('export async function refresh(): Promise<boolean> {');
+ const end = authSource.indexOf('const diskTokenChangedBeforeRefresh', start);
+ const body = authSource.slice(start, end);
+ expect(body).toContain(
+ 'if (persistedSession !== null && credentialStoreHealth.noteRecovered())',
+ );
+ });
+
+ it('clearAuth 整体清态时复位状态机', () => {
+ const start = authSource.indexOf('function clearAuth(');
+ const end = authSource.indexOf('commitActiveAppSession', start);
+ const body = authSource.slice(start, end);
+ expect(body).toContain('credentialStoreHealth.reset();');
+ });
+
+ it('AuthState 快照携带 credentialStoreUnavailable,登出投影恒为 false', () => {
+ const snapStart = authSource.indexOf('function snapshotAuthState(): AuthState {');
+ const snapEnd = authSource.indexOf('function snapshotLoggedOutAuthState', snapStart);
+ expect(authSource.slice(snapStart, snapEnd)).toContain(
+ 'credentialStoreUnavailable: credentialStoreHealth.unavailable',
+ );
+ const loggedOutStart = snapEnd;
+ const loggedOutEnd = authSource.indexOf('function notifyRenderer', loggedOutStart);
+ expect(authSource.slice(loggedOutStart, loggedOutEnd)).toContain(
+ 'credentialStoreUnavailable: false',
+ );
+ });
+});
diff --git a/apps/desktop/src/main/authCredentialStoreHealth.ts b/apps/desktop/src/main/authCredentialStoreHealth.ts
new file mode 100644
index 0000000000..ada1780ed4
--- /dev/null
+++ b/apps/desktop/src/main/authCredentialStoreHealth.ts
@@ -0,0 +1,70 @@
+/**
+ * authCredentialStoreHealth.ts
+ * ---------------------------------------------------------------------------
+ * 持久凭证库(safeStorage)健康状态机(#1687)。
+ *
+ * 跟踪的是一种特定的半死状态:refresh token 文件仍在磁盘上,但连续多个刷新周期
+ * 都读不出来(钥匙串拒绝 / 加密不可用 / 解密失败)。单次抖动必须保持瞬时语义
+ * (authManager 的 transient 分支,不得强踢用户);只有**连续** N 次失败才升级为
+ * `unavailable`,让 renderer 显示可操作提示。任何一次成功读取立即复位——
+ * 「连续」是这个状态机的全部语义,失败与成功交替时永不升级。
+ *
+ * 刻意不做的事:
+ * - 不落盘:进程内状态,重启后重新计数(重启本身就是用户可尝试的恢复动作);
+ * - 不主动探测 safeStorage:macOS 上 isEncryptionAvailable() 本身可能触发
+ * 钥匙串授权弹窗(见 credentials-and-local-storage.md),只被动消费
+ * authManager 刷新路径上已经发生的读取结果;
+ * - 不区分底层原因:ACL 冲突 / 用户拒绝授权 / 条目损坏对上层处置完全一致
+ * (Issue #1687 的「根因边界」——不把某一种底层触发条件写成唯一原因)。
+ *
+ * 阈值 × 运行时重试间隔(RUNTIME_REFRESH_RETRY_MS = 60s)≈ 5 分钟持续失败才
+ * 升级,与 Issue 期望的「短暂不可用可以重试,持续 T 分钟后必须升级」一致。
+ */
+
+export const CREDENTIAL_STORE_UNREADABLE_ESCALATION_THRESHOLD = 5;
+
+export interface CredentialStoreHealth {
+ /** 当前是否处于「持久凭证库不可用」升级态。 */
+ readonly unavailable: boolean;
+ /**
+ * 记一次「文件仍在但读不出」的刷新失败。
+ * 返回 true 表示本次调用刚好跨过阈值、状态翻转为 unavailable(调用方应广播);
+ * 已处于 unavailable 时继续失败不再返回 true,避免重复广播。
+ */
+ noteReadFailure(): boolean;
+ /**
+ * 记一次成功的持久凭证读取,连续失败计数清零。
+ * 返回 true 表示此前处于 unavailable、状态刚恢复(调用方应广播)。
+ */
+ noteRecovered(): boolean;
+ /** 无条件复位(登出 / 会话过期整体清态时用),不返回翻转信号。 */
+ reset(): void;
+}
+
+export function createCredentialStoreHealth(
+ threshold: number = CREDENTIAL_STORE_UNREADABLE_ESCALATION_THRESHOLD,
+): CredentialStoreHealth {
+ let consecutiveFailures = 0;
+ let unavailable = false;
+ return {
+ get unavailable(): boolean {
+ return unavailable;
+ },
+ noteReadFailure(): boolean {
+ consecutiveFailures += 1;
+ if (unavailable || consecutiveFailures < threshold) return false;
+ unavailable = true;
+ return true;
+ },
+ noteRecovered(): boolean {
+ consecutiveFailures = 0;
+ if (!unavailable) return false;
+ unavailable = false;
+ return true;
+ },
+ reset(): void {
+ consecutiveFailures = 0;
+ unavailable = false;
+ },
+ };
+}
diff --git a/apps/desktop/src/main/authManager.ts b/apps/desktop/src/main/authManager.ts
index 5c779193d0..41c6ad524a 100644
--- a/apps/desktop/src/main/authManager.ts
+++ b/apps/desktop/src/main/authManager.ts
@@ -100,9 +100,15 @@ import {
recordLegacyGhostMigrationResult,
} from './ownerNamespaceMigration.js';
import { buildSafeStorageIssueMeta } from './safeStorageIssueLog.js';
+import { createCredentialStoreHealth } from './authCredentialStoreHealth';
const log = createLogger('authManager');
+// #1687:持久凭证库(safeStorage)故障升级状态机。运行时刷新的 transient-unreadable
+// 分支喂失败,成功读到持久会话喂恢复;连续跨过阈值才置 unavailable 并随 AuthState
+// 广播,renderer 据此显示可操作提示(检查钥匙串授权 / 重新登录)。
+const credentialStoreHealth = createCredentialStoreHealth();
+
async function claimLegacyNamespaceForVerifiedUser(userId: string): Promise<void> {
try {
const result = await claimLegacyOwnerNamespace({
@@ -197,6 +203,11 @@ export interface AuthState {
hasAccountDeletionReceipt: boolean;
/** One-shot successful-login notice for a deletion that was cancelled by signing in. */
accountDeletionRestored: boolean;
+ /**
+ * 持久凭证库(safeStorage)连续多个刷新周期不可用(#1687)。true 时登录态无法
+ * 续期持久化,renderer 应显示可操作提示;成功读写一次后自动回 false。
+ */
+ credentialStoreUnavailable: boolean;
}
export interface AuthInitializeOptions {
@@ -1279,6 +1290,7 @@ function snapshotAuthState(): AuthState {
deviceId,
hasAccountDeletionReceipt: readPersistedAccountDeletionReceipt() !== null,
accountDeletionRestored: accountDeletionRestoredNoticePending,
+ credentialStoreUnavailable: credentialStoreHealth.unavailable,
};
}
@@ -1296,6 +1308,8 @@ function snapshotLoggedOutAuthState(): AuthState {
deviceId,
hasAccountDeletionReceipt: readPersistedAccountDeletionReceipt() !== null,
accountDeletionRestored: false,
+ // 登出投影不携带升级态:登录页可见时用户已有明确的重新登录入口。
+ credentialStoreUnavailable: false,
};
}
@@ -1433,6 +1447,9 @@ function clearAuth(
): void {
const notify = opts.notify ?? true;
authStateEpoch += 1; // 迟到的冷启动流程从此作废(见 authStateEpoch 注释)
+ // #1687:登出 / 会话过期整体清态时复位凭证库升级态——升级提示只对「仍以为
+ // 自己登录着」的会话有意义,登录页自身就是恢复入口。
+ credentialStoreHealth.reset();
accessToken = null;
pendingAccountToken = null;
currentUser = null;
@@ -2805,6 +2822,12 @@ export async function refresh(): Promise<boolean> {
return true;
};
const persistedSession = readPersistedAuthSession();
+ // #1687:成功读到持久会话 = 凭证库读取工作正常,连续失败计数清零;
+ // 若此前已升级为 unavailable,立即广播恢复(banner 自动消失)。
+ if (persistedSession !== null && credentialStoreHealth.noteRecovered()) {
+ log.info('credential store recovered — clearing the persistent-unavailability state');
+ notifyRenderer();
+ }
const refreshRealm = persistedSession?.realm ?? activeAuthRealm;
if (persistedSession && persistedSession.realm !== activeAuthRealm) {
try {
@@ -2831,6 +2854,15 @@ export async function refresh(): Promise<boolean> {
log.warn(
'runtime refresh: refresh token unreadable but file still present (or encryption unavailable) — treating as transient',
);
+ // #1687:单次仍按瞬时处理(绝不 expireRuntimeAuth),但连续跨过阈值后
+ // 升级为持久凭证库故障并广播——此前这条路径无论失败多少轮都完全静默,
+ // 用户面对的是假登录态 + 全部鉴权请求 401 而无任何可操作提示。
+ if (credentialStoreHealth.noteReadFailure()) {
+ log.warn(
+ 'credential store persistently unavailable — surfacing credentialStoreUnavailable to renderer',
+ );
+ notifyRenderer();
+ }
// 正常 refresh timer 已经触发过,这里不重排的话,一次密钥链/IO 抖动
// 会让有效会话在 access token 到期前没有任何后续 refresh(半死)。
scheduleRefreshRetryAfterTransientFailure();
diff --git a/apps/desktop/src/renderer/components/layout/CredentialStoreBanner.tsx b/apps/desktop/src/renderer/components/layout/CredentialStoreBanner.tsx
new file mode 100644
index 0000000000..8cc4fe6406
--- /dev/null
+++ b/apps/desktop/src/renderer/components/layout/CredentialStoreBanner.tsx
@@ -0,0 +1,117 @@
+/**
+ * CredentialStoreBanner —— 持久凭证库(safeStorage)故障全局警示条(#1687)。
+ *
+ * main 侧 authManager 在连续多个刷新周期读不出 refresh token(文件仍在但钥匙串
+ * 拒绝 / 加密不可用)后,把 AuthState.credentialStoreUnavailable 置 true 广播;
+ * 本组件挂在 MainLayout 主内容区顶部(ContentHeader 之下、路由内容之上),
+ * 显示一条 warning 色横幅 + 「查看解决方法」dialog,给用户可操作的恢复路径——
+ * 此前这种半死状态(界面看似已登录、所有鉴权请求持续 401)没有任何提示。
+ *
+ * 行为约定:
+ * - 状态由 main 驱动,凭证库恢复(成功读写一次)后 flag 回 false,横幅自动消失;
+ * - ✕ 关闭是**进程内**记忆(模块级,与 ControlledBanner 的模块级缓存同模式):
+ * 路由切换 / remount 不复活,重启后若仍故障会重新出现;flag 回 false 时清除
+ * dismiss 记忆,下次再故障必须重新提示;
+ * - 解决步骤按平台分支:macOS 给钥匙串检查指引,其它平台给通用重启/重登指引。
+ *
+ * 颜色走既有语义豁免 token(--warning-fg / --warning-bg-soft,双模式同值/自适配),
+ * 不引入新 token,无需 DESIGN.md §10 豁免表登记。
+ */
+
+import { useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { TriangleAlert, X } from 'lucide-react';
+
+import { useAuth } from '@/contexts/AuthContext';
+import { ConfirmDialog } from '@/components/ui/confirm-dialog';
+import { Tip } from '@/components/ui/tooltip';
+
+// 进程内 dismiss 记忆:MainLayout 在路由切换间会重挂本组件,用组件态存 dismiss
+// 会导致每次导航横幅复活。模块级变量的生命周期 = 渲染进程,语义正好。
+let dismissedInProcess = false;
+
+/** 测试钩子:重置模块级 dismiss 记忆(仅测试使用)。 */
+export function __resetCredentialStoreBannerDismissForTest(): void {
+ dismissedInProcess = false;
+}
+
+export function CredentialStoreBanner() {
+ const { t } = useTranslation();
+ const { credentialStoreUnavailable } = useAuth();
+ const [helpOpen, setHelpOpen] = useState(false);
+ // dismiss 后触发一次重渲染让横幅立即消失;真值存模块级变量。
+ const [, setDismissTick] = useState(0);
+
+ const isMac = window.electronAPI?.platform === 'darwin';
+
+ // 凭证库恢复后清 dismiss 记忆:下次再故障必须重新出现,不能被上次的 ✕ 吞掉。
+ useEffect(() => {
+ if (!credentialStoreUnavailable) dismissedInProcess = false;
+ }, [credentialStoreUnavailable]);
+
+ if (!credentialStoreUnavailable || dismissedInProcess) return null;
+
+ const handleDismiss = () => {
+ dismissedInProcess = true;
+ setDismissTick((n) => n + 1);
+ };
+
+ // 恢复步骤:macOS 多一条钥匙串检查;两个平台都以「重启 → 仍不行再重登」收尾,
+ // 与 main 侧「首次失败不 clearAuth」的取向一致——不引导用户上来就丢登录态。
+ const steps = [
+ ...(isMac ? [t('credentialStore.dialog.stepMacKeychain')] : []),
+ t('credentialStore.dialog.stepRestart'),
+ t('credentialStore.dialog.stepRelogin'),
+ ];
+
+ return (
+ <>
+ <div
+ role="alert"
+ className="flex shrink-0 select-none items-center gap-2 border-b border-[var(--border-default)] bg-[var(--warning-bg-soft)] px-4 py-2"
+ >
+ <TriangleAlert
+ className="h-4 w-4 shrink-0 text-[var(--warning-fg)]"
+ strokeWidth={2}
+ aria-hidden
+ />
+ <span className="min-w-0 flex-1 truncate text-xs text-[var(--text-primary)]">
+ {t('credentialStore.banner.message')}
+ </span>
+ <button
+ type="button"
+ onClick={() => setHelpOpen(true)}
+ className="shrink-0 rounded-full text-xs underline underline-offset-2 text-[var(--text-secondary)] transition-colors hover:text-[var(--text-primary)]"
+ >
+ {t('credentialStore.banner.viewHelp')}
+ </button>
+ <Tip text={t('credentialStore.banner.dismiss')}>
+ <button
+ type="button"
+ onClick={handleDismiss}
+ aria-label={t('credentialStore.banner.dismiss')}
+ className="flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-[var(--text-secondary)] transition-colors hover:text-[var(--text-primary)]"
+ >
+ <X className="h-3.5 w-3.5" strokeWidth={2} />
+ </button>
+ </Tip>
+ </div>
+ <ConfirmDialog
+ open={helpOpen}
+ onOpenChange={setHelpOpen}
+ title={t('credentialStore.dialog.title')}
+ description={t('credentialStore.dialog.intro')}
+ content={
+ <ol className="list-decimal space-y-1.5 pl-5 text-sm text-[var(--text-secondary-mid)]">
+ {steps.map((step) => (
+ <li key={step}>{step}</li>
+ ))}
+ </ol>
+ }
+ confirmText={t('credentialStore.dialog.confirm')}
+ showCancel={false}
+ onConfirm={() => setHelpOpen(false)}
+ />
+ </>
+ );
+}
diff --git a/apps/desktop/src/renderer/components/layout/MainLayout.tsx b/apps/desktop/src/renderer/components/layout/MainLayout.tsx
index c0e514262a..f95a9e5aa3 100644
--- a/apps/desktop/src/renderer/components/layout/MainLayout.tsx
+++ b/apps/desktop/src/renderer/components/layout/MainLayout.tsx
@@ -28,6 +28,7 @@ import { FeishuConflictDialogHost } from '@/components/feishuBot/FeishuConflictD
import { GlobalDropImportListener } from '@/components/layout/GlobalDropImportListener';
import { SessionShareImportWizard } from '@/components/settings/SessionShareImportWizard';
import { ControlledBanner } from '@/features/remote-device/ControlledBanner';
+import { CredentialStoreBanner } from '@/components/layout/CredentialStoreBanner';
import { useDeviceLinkRemoteProjects } from '@/features/device-link/useDeviceLinkRemoteProjects';
import { pluginScheduleNavigationState } from '@/features/scheduler/lib/pluginScheduleCreateIntent';
import { FeatureSidebarSlotProvider } from '@/features/feature-context';
@@ -1282,6 +1283,10 @@ export function MainLayout() {
重跑导致的"刷新一帧"闪烁。
ContentHeader 在 FadeSwitcher 之外 —— header chrome 不参与路由切换
动画,只有注入的中部内容随路由变化。 */}
+ {/* 持久凭证库故障全局警示条(#1687):ContentHeader 之下、路由内容之上,
+ shrink-0 在 main 的 flex 列里独占一行把内容推下(不遮盖)。放在
+ FadeSwitcher 之外 —— 它是全局状态提示,不参与路由切换动画。 */}
+ <CredentialStoreBanner />
<FadeSwitcher key={location.pathname.split('/')[1] || 'root'}>
<Outlet
context={{
diff --git a/apps/desktop/src/renderer/contexts/AuthContext.tsx b/apps/desktop/src/renderer/contexts/AuthContext.tsx
index cfe57d6106..2f722cca7f 100644
--- a/apps/desktop/src/renderer/contexts/AuthContext.tsx
+++ b/apps/desktop/src/renderer/contexts/AuthContext.tsx
@@ -70,6 +70,8 @@ export interface AuthContextValue {
exitLocalMode: () => Promise<void>;
hasAccountDeletionReceipt: boolean;
accountDeletionRestored: boolean;
+ /** 持久凭证库(safeStorage)连续多个刷新周期不可用(#1687);全局警示条据此显隐。 */
+ credentialStoreUnavailable: boolean;
getAccountDeletionAvailability: ReturnType<
typeof createAuthService
>['getAccountDeletionAvailability'];
@@ -109,6 +111,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const [deviceId, setDeviceId] = useState<string | null>(null);
const [hasAccountDeletionReceipt, setHasAccountDeletionReceipt] = useState(false);
const [accountDeletionRestored, setAccountDeletionRestored] = useState(false);
+ const [credentialStoreUnavailable, setCredentialStoreUnavailable] = useState(false);
const [loginState, setLoginState] = useState<AuthFlowState | null>(null);
const { confirm } = useConfirmDialog();
const { t } = useTranslation();
@@ -182,6 +185,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
setDeviceId(state.deviceId);
setHasAccountDeletionReceipt(state.hasAccountDeletionReceipt);
setAccountDeletionRestored(state.accountDeletionRestored);
+ setCredentialStoreUnavailable(state.credentialStoreUnavailable);
if (state.user) {
setLoginState(null);
if (ownerChanged) {
@@ -239,6 +243,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
setLoginState(null);
clearWorkersCache();
setUser(null);
+ setCredentialStoreUnavailable(false);
})
.finally(() => setIsInitializing(false));
@@ -296,6 +301,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
setIsAuthenticated(false);
setIsCanary(false);
setLoginState(null);
+ setCredentialStoreUnavailable(false);
handling = false;
});
});
@@ -412,6 +418,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
exitLocalMode,
hasAccountDeletionReceipt,
accountDeletionRestored,
+ credentialStoreUnavailable,
getAccountDeletionAvailability,
requestAccountDeletionChallenge,
confirmAccountDeletion,
@@ -437,6 +444,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
exitLocalMode,
hasAccountDeletionReceipt,
accountDeletionRestored,
+ credentialStoreUnavailable,
getAccountDeletionAvailability,
requestAccountDeletionChallenge,
confirmAccountDeletion,
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 480470cccf..a0e321332a 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -3928,6 +3928,21 @@
"dismissButton": "Got it"
}
},
+ "credentialStore": {
+ "banner": {
+ "message": "System credential storage is unavailable; your signed-in state cannot be maintained",
+ "viewHelp": "View solutions",
+ "dismiss": "Dismiss"
+ },
+ "dialog": {
+ "title": "System credential storage unavailable",
+ "intro": "Cindy cannot read its sign-in credentials from the system credential storage, so the signed-in state and related integrations will keep failing. Try the following steps to recover:",
+ "stepMacKeychain": "Quit Cindy, open Keychain Access, search for \"Cindy Safe Storage\" and check its access control; delete the entry if necessary (saved integration credentials will be invalidated and need to be reconnected)",
+ "stepRestart": "Restart Cindy",
+ "stepRelogin": "If it still does not recover, sign out and sign in again",
+ "confirm": "OK"
+ }
+ },
"localDbGate": {
"title": "Local data could not be opened",
"description": "Retry, or return to the sign-in choices and select a mode again.",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 6ce0d0a22a..698e8f6c80 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -3926,6 +3926,21 @@
"dismissButton": "確認"
}
},
+ "credentialStore": {
+ "banner": {
+ "message": "システムの資格情報ストレージが利用できないため、ログイン状態を維持できません",
+ "viewHelp": "解決方法を見る",
+ "dismiss": "閉じる"
+ },
+ "dialog": {
+ "title": "システムの資格情報ストレージが利用できません",
+ "intro": "Cindy はシステムの資格情報ストレージからログイン資格情報を読み取れないため、ログイン状態や関連する連携が失敗し続けます。以下の手順をお試しください:",
+ "stepMacKeychain": "Cindy を終了し、「キーチェーンアクセス」を開いて「Cindy Safe Storage」を検索し、アクセス制御を確認してください。必要に応じて項目を削除します(保存済みの連携資格情報は無効になり、再接続が必要です)",
+ "stepRestart": "Cindy を再起動する",
+ "stepRelogin": "回復しない場合は、ログアウトしてから再度ログインしてください",
+ "confirm": "OK"
+ }
+ },
"localDbGate": {
"title": "ローカルデータを開けませんでした",
"description": "再試行するか、ログイン方法に戻ってモードを選び直してください。",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index e55d37ff74..c9c80ea855 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -3926,6 +3926,21 @@
"dismissButton": "확인"
}
},
+ "credentialStore": {
+ "banner": {
+ "message": "시스템 자격 증명 저장소를 사용할 수 없어 로그인 상태를 유지할 수 없습니다",
+ "viewHelp": "해결 방법 보기",
+ "dismiss": "닫기"
+ },
+ "dialog": {
+ "title": "시스템 자격 증명 저장소를 사용할 수 없음",
+ "intro": "Cindy가 시스템 자격 증명 저장소에서 로그인 자격 증명을 읽을 수 없어 로그인 상태와 관련 연동이 계속 실패합니다. 다음 단계를 시도해 보세요:",
+ "stepMacKeychain": "Cindy를 종료하고 '키체인 접근'을 열어 'Cindy Safe Storage'를 검색한 뒤 접근 제어를 확인하세요. 필요하면 해당 항목을 삭제하세요(저장된 연동 자격 증명은 무효화되어 다시 연결해야 합니다)",
+ "stepRestart": "Cindy 다시 시작",
+ "stepRelogin": "여전히 복구되지 않으면 로그아웃 후 다시 로그인하세요",
+ "confirm": "확인"
+ }
+ },
"localDbGate": {
"title": "로컬 데이터를 열 수 없습니다",
"description": "다시 시도하거나 로그인 방식으로 돌아가 모드를 다시 선택하세요.",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 7d6b5cccab..513798b673 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -3926,6 +3926,21 @@
"dismissButton": "我知道了"
}
},
+ "credentialStore": {
+ "banner": {
+ "message": "系统凭证存储不可用,登录状态无法维持",
+ "viewHelp": "查看解决方法",
+ "dismiss": "关闭提示"
+ },
+ "dialog": {
+ "title": "系统凭证存储不可用",
+ "intro": "Cindy 无法通过系统凭证存储读取登录凭证,登录状态和相关集成会持续失效。可尝试以下步骤恢复:",
+ "stepMacKeychain": "退出 Cindy,打开「钥匙串访问」,搜索「Cindy Safe Storage」并检查其访问控制;必要时删除该条目(已保存的集成凭证会失效,需要重新连接)",
+ "stepRestart": "重新启动 Cindy",
+ "stepRelogin": "如果仍未恢复,退出登录后重新登录",
+ "confirm": "知道了"
+ }
+ },
"localDbGate": {
"title": "本地数据暂时无法打开",
"description": "可以重试,或返回登录方式后重新选择使用模式。",
diff --git a/apps/desktop/src/renderer/lib/authService.ts b/apps/desktop/src/renderer/lib/authService.ts
index dbc2c0bf05..04d0c567c0 100644
--- a/apps/desktop/src/renderer/lib/authService.ts
+++ b/apps/desktop/src/renderer/lib/authService.ts
@@ -43,6 +43,8 @@ export interface AuthState {
deviceId: string;
hasAccountDeletionReceipt: boolean;
accountDeletionRestored: boolean;
+ /** 持久凭证库(safeStorage)连续多个刷新周期不可用(#1687);恢复后自动回 false。 */
+ credentialStoreUnavailable: boolean;
}
export interface AuthService {
@@ -77,6 +79,7 @@ export function createAuthService(): AuthService {
deviceId: rawState.deviceId,
hasAccountDeletionReceipt: rawState.hasAccountDeletionReceipt === true,
accountDeletionRestored: rawState.accountDeletionRestored === true,
+ credentialStoreUnavailable: rawState.credentialStoreUnavailable === true,
};
listeners.forEach((listener) => listener(normalized));
});
@@ -95,6 +98,7 @@ export function createAuthService(): AuthService {
deviceId: raw.deviceId,
hasAccountDeletionReceipt: raw.hasAccountDeletionReceipt === true,
accountDeletionRestored: raw.accountDeletionRestored === true,
+ credentialStoreUnavailable: raw.credentialStoreUnavailable === true,
};
},
diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.ts
index af67ee6b40..1eed868905 100644
--- a/apps/desktop/src/renderer/vite-env.d.ts
+++ b/apps/desktop/src/renderer/vite-env.d.ts
@@ -510,6 +510,8 @@ interface AuthStateChangePayload {
deviceId: string;
hasAccountDeletionReceipt: boolean;
accountDeletionRestored: boolean;
+ /** 持久凭证库(safeStorage)连续多个刷新周期不可用(#1687);旧版 main 不带此字段。 */
+ credentialStoreUnavailable?: boolean;
}
/**
@@ -1805,6 +1807,8 @@ interface ElectronAPI {
deviceId: string;
hasAccountDeletionReceipt: boolean;
accountDeletionRestored: boolean;
+ /** 持久凭证库(safeStorage)连续多个刷新周期不可用(#1687)。 */
+ credentialStoreUnavailable?: boolean;
}>;
authGetLoginState: () => Promise<DesktopLoginActionResult>;
authDispatchLoginAction: (action: DesktopLoginAction) => Promise<DesktopLoginActionResult>;