Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): decouple App session boundary from Ghost durable owner
Yuewei-LLd906830c14ac
diff --git a/apps/desktop/src/main/__tests__/appCapabilitiesIpc.test.ts b/apps/desktop/src/main/__tests__/appCapabilitiesIpc.test.tsindex c565fa671b..90d65131c8 100644--- a/apps/desktop/src/main/__tests__/appCapabilitiesIpc.test.ts+++ b/apps/desktop/src/main/__tests__/appCapabilitiesIpc.test.ts@@ -34,11 +34,14 @@ describe('requireAppCapability IPC errors', () => {expect(() => requireAppCapability('canUseDeviceLink')).toThrow(/\[PRECONDITION_FAILED\]/);});- it('keeps cloud capabilities closed while the durable owner is unstable', () => {+ it('keeps normal cloud capabilities available when only the Ghost projection owner differs', () => {state.mode = 'cloud';state.ownerStable = false;- expect(() => requireAppCapability('canUseCindyAccountServices')).toThrow(- /\[PRECONDITION_FAILED\]/,- );+ expect(() => requireAppCapability('canUseCindyAccountServices')).not.toThrow();+ expect(() => requireAppCapability('canUseCindyGateway')).not.toThrow();+ expect(() => requireAppCapability('canUseDeviceLink')).not.toThrow();+ expect(() => requireAppCapability('canUseSkillHubCloud')).not.toThrow();+ expect(() => requireAppCapability('canUseCindyOAuthBroker')).not.toThrow();+ expect(() => requireAppCapability('canUseCindyHeartbeat')).not.toThrow();});});diff --git a/apps/desktop/src/main/__tests__/appSessionBoundary.test.ts b/apps/desktop/src/main/__tests__/appSessionBoundary.test.tsnew file mode 100644index 0000000000..9b2b0432ab--- /dev/null+++ b/apps/desktop/src/main/__tests__/appSessionBoundary.test.ts@@ -0,0 +1,43 @@+import { describe, expect, it, vi } from 'vitest';++const ghostBoundary = vi.hoisted(() => ({ stable: false }));++vi.mock('electron', () => ({+ app: {+ getPath: (name: string) => `C:/tmp/cindy-${name}`,+ },+}));++vi.mock('../logger.js', () => ({+ createLogger: () => ({ info: vi.fn() }),+}));++vi.mock('../maker-host/override-settings-file.js', () => ({+ createOverrideSettingsFile: () => ({+ read: () => ({ activeMode: 'signed-out' }),+ writePatch: vi.fn(),+ }),+}));++vi.mock('../authBoundaryQuarantine.js', () => ({+ isGhostSkillProjectionBoundaryStableForOwner: () => ghostBoundary.stable,+}));++import {+ beginAppSessionBoundary,+ isAppSessionBoundaryPending,+} from '../appSessionState.js';++describe('application session boundary isolation', () => {+ it('does not treat a different durable Ghost projection owner as an App transition', () => {+ ghostBoundary.stable = false;+ expect(isAppSessionBoundaryPending()).toBe(false);+ });++ it('still fails closed during a real process-local App owner transition', () => {+ const release = beginAppSessionBoundary();+ expect(isAppSessionBoundaryPending()).toBe(true);+ release();+ expect(isAppSessionBoundaryPending()).toBe(false);+ });+});diff --git a/apps/desktop/src/main/__tests__/appSessionPolicy.test.ts b/apps/desktop/src/main/__tests__/appSessionPolicy.test.tsindex 95edef4068..1380c218cb 100644--- a/apps/desktop/src/main/__tests__/appSessionPolicy.test.ts+++ b/apps/desktop/src/main/__tests__/appSessionPolicy.test.ts@@ -21,12 +21,6 @@ describe('local app-session policy', () => {expect(deriveAppCapabilities('cloud', false).canUseCindyAccountServices).toBe(true);});- it('fails closed while the durable cloud owner is not stable', () => {- expect(deriveAppCapabilities('cloud', false, false).canUseCindyAccountServices).toBe(false);- expect(deriveAppCapabilities('cloud', false, false).canUseCindyGateway).toBe(false);- expect(deriveAppCapabilities('cloud', false, true).canUseCindyAccountServices).toBe(true);- });-it('rejects local DB work while the matching owner boundary is pending', () => {const state = { dataOwnerId: 'cloud-a' };expect(isLocalDbOwnerCurrent(state, 'cloud-a', false)).toBe(true);diff --git a/apps/desktop/src/main/__tests__/authSessionExpiredDetection.test.ts b/apps/desktop/src/main/__tests__/authSessionExpiredDetection.test.tsindex 8285f4e732..5d943da4f6 100644--- a/apps/desktop/src/main/__tests__/authSessionExpiredDetection.test.ts+++ b/apps/desktop/src/main/__tests__/authSessionExpiredDetection.test.ts@@ -200,5 +200,16 @@ describe('desktop auth session-expiry detection', () => {const requireBody = ghostSource.slice(requireStart, requireEnd);expect(requireBody).toContain("throwIpcError(\n 'PRECONDITION_FAILED'");expect(requireBody).toContain('isAppSessionBoundaryPending()');+ // A durable Ghost owner mismatch must stay a retryable precondition error+ // (not a misleading PERMISSION_DENIED) even when the App session itself is+ // not switching. The owner-stable check has to sit inside the+ // PRECONDITION_FAILED branch, so require it to appear before the+ // PERMISSION_DENIED throw — otherwise a regression that moves it into the+ // permission branch would still pass a mere toContain.+ const ownerStableIndex = requireBody.indexOf('!isGhostSkillProjectionBoundaryStableForOwner(activeOwner)');+ const permissionDeniedIndex = requireBody.indexOf("'PERMISSION_DENIED'");+ expect(ownerStableIndex).toBeGreaterThan(-1);+ expect(permissionDeniedIndex).toBeGreaterThan(-1);+ expect(ownerStableIndex).toBeLessThan(permissionDeniedIndex);});});diff --git a/apps/desktop/src/main/appCapabilities.ts b/apps/desktop/src/main/appCapabilities.tsindex 05296530a1..41c04192aa 100644--- a/apps/desktop/src/main/appCapabilities.ts+++ b/apps/desktop/src/main/appCapabilities.ts@@ -10,7 +10,6 @@ import {isAppSessionBoundaryPending,type AppSessionMode,} from './appSessionState.js';-import { isGhostSkillProjectionBoundaryStableForOwner } from './authBoundaryQuarantine.js';import { throwIpcError } from './utils/ipcValidate.js';export interface AppCapabilities {@@ -25,9 +24,8 @@ export interface AppCapabilities {export function deriveAppCapabilities(mode: AppSessionMode,boundaryPending = false,- ownerStable = true,): AppCapabilities {- const cloud = mode === 'cloud' && !boundaryPending && ownerStable;+ const cloud = mode === 'cloud' && !boundaryPending;return {canUseCindyAccountServices: cloud,canUseCindyGateway: cloud,@@ -40,11 +38,7 @@ export function deriveAppCapabilities(export function getAppCapabilities(): AppCapabilities {const session = getActiveAppSession();- return deriveAppCapabilities(- session.mode,- isAppSessionBoundaryPending(),- isGhostSkillProjectionBoundaryStableForOwner(session.dataOwnerId),- );+ return deriveAppCapabilities(session.mode, isAppSessionBoundaryPending());}export function requireAppCapability(@@ -53,9 +47,8 @@ export function requireAppCapability(): void {const session = getActiveAppSession();const boundaryPending = isAppSessionBoundaryPending();- const ownerStable = isGhostSkillProjectionBoundaryStableForOwner(session.dataOwnerId);- if (deriveAppCapabilities(session.mode, boundaryPending, ownerStable)[capability]) return;- if (boundaryPending || (session.mode === 'cloud' && !ownerStable)) {+ if (deriveAppCapabilities(session.mode, boundaryPending)[capability]) return;+ if (boundaryPending) {throwIpcError('PRECONDITION_FAILED','App session is switching; retry after the owner boundary settles.',diff --git a/apps/desktop/src/main/appSessionState.ts b/apps/desktop/src/main/appSessionState.tsindex 33a35ca3c4..ea42b8bdbf 100644--- a/apps/desktop/src/main/appSessionState.ts+++ b/apps/desktop/src/main/appSessionState.ts@@ -13,7 +13,6 @@ import { createLogger } from './logger.js';import { createOverrideSettingsFile } from './maker-host/override-settings-file.js';import { LOCAL_PROFILE_DATA_OWNER_ID } from './profile/profileRegistryModel.js';import type { DataOwnerPushStamp } from '../shared/dataOwnerPush.js';-import { isGhostSkillProjectionBoundaryStableForOwner } from './authBoundaryQuarantine.js';export type AppSessionMode = 'signed-out' | 'local' | 'cloud';@@ -143,12 +142,10 @@ export function beginAppSessionBoundary(): () => void {}export function isAppSessionBoundaryPending(): boolean {- if (boundaryDepth > 0) return true;- const session = ensureLoaded();- return !isGhostSkillProjectionBoundaryStableForOwner(session.dataOwnerId);+ return boundaryDepth > 0;}-/** Process-local transition state, excluding a durable owner mismatch. */+/** Backward-compatible alias for the process-local application transition. */export function isAppSessionBoundaryLocallyPending(): boolean {return boundaryDepth > 0;}diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.tsindex f7fc086d93..24617b228a 100644--- a/apps/desktop/src/main/cindy-brain/index.ts+++ b/apps/desktop/src/main/cindy-brain/index.ts@@ -900,7 +900,11 @@ export function listAvailableGhostsForAuthorization(): InstalledGhost[] {function requireGhostAvailableForActiveSession(id: string): void {if (!isGhostAvailableForActiveSession(id)) {- if (isAppSessionBoundaryPending()) {+ const activeOwner = getActiveAppSession().dataOwnerId;+ if (+ isAppSessionBoundaryPending() ||+ !isGhostSkillProjectionBoundaryStableForOwner(activeOwner)+ ) {throwIpcError('PRECONDITION_FAILED','Ghost projection is switching owners; retry after the boundary settles.',