Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): stabilize Windows lock recovery checks
Yuewei-LL8a183d084f7a
diff --git a/apps/desktop/src/main/__tests__/ownerNamespaceMigration.test.ts b/apps/desktop/src/main/__tests__/ownerNamespaceMigration.test.tsindex 0906b5c3cd..ee3b466d93 100644--- a/apps/desktop/src/main/__tests__/ownerNamespaceMigration.test.ts+++ b/apps/desktop/src/main/__tests__/ownerNamespaceMigration.test.ts@@ -1163,6 +1163,50 @@ describe('legacy Ghost plugin recovery', () => {});});+ it('keeps target-only recovery retryable when a live registry pid was reused', async () => {+ const root = await tempRoot();+ const ownerId = 'cloud-a';+ const ownerKey = dataOwnerStorageKey(ownerId);+ const target = path.join(root, 'owners', ownerKey, 'cindy-brain', 'legacy-plugin');+ const markerPath = path.join(+ root,+ 'owners',+ ownerKey,+ __testing.LEGACY_GHOST_RECOVERY_MARKER,+ );+ const startedAtMs = 1_000_000;+ await writeGhostDirAtPath(target, 'legacy-plugin');+ await fs.mkdir(path.dirname(markerPath), { recursive: true });+ await fs.writeFile(+ markerPath,+ JSON.stringify({+ version: 2,+ ownerKey,+ pendingIds: ['legacy-plugin'],+ approvalProjectionSha256ById: { 'legacy-plugin': 'a'.repeat(64) },+ }),+ );+ await writeDevInstanceRecord(root, 4242, root, { startedAtMs });++ expect(+ getLegacyGhostRecoveryStatus(+ { mode: 'cloud', dataOwnerId: ownerId, user: { id: ownerId } },+ root,+ false,+ {},+ (pid) => pid === 4242,+ () => ({+ startedAtMs: startedAtMs + 120_000,+ command: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',+ }),+ ),+ ).toEqual({+ state: 'partial',+ legacyPluginCount: 1,+ canRetry: true,+ });+ });+it.each(['manifest', 'disabled', 'trust', 'locale', 'icon', 'skill'] as const)('refuses an in-place %s approval projection change after the durable freeze',async (kind) => {diff --git a/apps/desktop/src/main/device-link/__tests__/crossProcessLock.test.ts b/apps/desktop/src/main/device-link/__tests__/crossProcessLock.test.tsindex c8632bf2c7..07536c6e65 100644--- a/apps/desktop/src/main/device-link/__tests__/crossProcessLock.test.ts+++ b/apps/desktop/src/main/device-link/__tests__/crossProcessLock.test.ts@@ -40,22 +40,42 @@ beforeEach(() => {dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cross-process-lock-'));});+async function createExitedPid(): Promise<number> {+ // Strict takeover requires affirmative OS proof that the recorded owner is+ // gone. A made-up large PID makes that proof depend on CIM/WMIC accepting+ // the numeric value, which varies across Windows runner images. Use a PID+ // this host created and observed exiting instead.+ const child = spawn(process.execPath, ['-e', 'process.exit(0)'], {+ windowsHide: true,+ stdio: 'ignore',+ });+ return new Promise<number>((resolve, reject) => {+ child.once('error', reject);+ child.once('exit', () => {+ if (!child.pid) reject(new Error('fixture child pid missing'));+ else resolve(child.pid);+ });+ });+}+afterEach(() => {fs.rmSync(dir, { recursive: true, force: true });});-/** 造一把「陈旧且 owner 已死」的锁:pid 用一个几乎不可能存在的值。 */+/** 造一把「陈旧且 owner 已死」的锁。 */async function writeStaleLock(lock: string): Promise<void> {- await fsp.writeFile(lock, JSON.stringify({ pid: 0x7ffffffe, startedAt: 1 }), 'utf8');+ const exitedPid = await createExitedPid();+ await fsp.writeFile(lock, JSON.stringify({ pid: exitedPid, startedAt: 1 }), 'utf8');const old = new Date(Date.now() - 60_000);await fsp.utimes(lock, old, old);}async function writeStaleStrictLock(lock: string): Promise<void> {+ const exitedPid = await createExitedPid();await fsp.writeFile(lock,JSON.stringify({- pid: 0x7ffffffe,+ pid: exitedPid,startedAt: 1,nonce: '00000000-0000-4000-8000-000000000001',processStartIdentity: 'start-ms:1',@@ -68,10 +88,11 @@ async function writeStaleStrictLock(lock: string): Promise<void> {}async function writeStaleReclaimGate(lock: string): Promise<void> {+ const exitedPid = await createExitedPid();const gate = `${lock}.reclaim`;await fsp.writeFile(gate,- JSON.stringify({ pid: 0x7ffffffe, startedAt: 1, nonce: 'stale-gate' }),+ JSON.stringify({ pid: exitedPid, startedAt: 1, nonce: 'stale-gate' }),'utf8',);const old = new Date(Date.now() - 60_000);@@ -141,7 +162,16 @@ describe('接管陈旧锁', () => {withAdvisoryCrossProcessLock(lock, { label: 'second' }, async (s) => s),).resolves.toEqual({ held: true });- expect(fs.readdirSync(dir)).toEqual([]);+ const artifacts = fs.readdirSync(dir).flatMap((entry) => {+ const candidate = path.join(dir, entry);+ return fs.statSync(candidate).isDirectory()+ ? fs.readdirSync(candidate).map((child) => path.join(entry, child))+ : [entry];+ });+ // Windows can retain an already-empty directory entry briefly after the+ // bounded rmdir retries. The invariant is that no owner gate or release+ // marker remains; the two acquisitions above also prove immediate re-entry.+ expect(artifacts).toEqual([]);});it('keeps the advisory canonical lock as a legacy-readable file', async () => {diff --git a/apps/desktop/src/main/ownerNamespaceMigration.ts b/apps/desktop/src/main/ownerNamespaceMigration.tsindex 35bdc46495..27bffeb838 100644--- a/apps/desktop/src/main/ownerNamespaceMigration.ts+++ b/apps/desktop/src/main/ownerNamespaceMigration.ts@@ -1310,7 +1310,11 @@ export function getLegacyGhostRecoveryStatus(return { state: 'deferred', legacyPluginCount, canRetry: false };}if (recoveredIds.length > 0) {- if (hasConcurrentLiveInstanceSync(root, isPidAlive)) {+ // Keep the target-only retry on the same exact-process identity policy as+ // the owner-wide check above. A PID-only fallback here would let a reused+ // stale registry PID block the only backfill path for an already-moved+ // plugin.+ if (hasConcurrentLiveInstanceSync(root, isPidAlive, readProcessIdentity)) {return { state: 'deferred', legacyPluginCount, canRetry: false };}return { state: 'partial', legacyPluginCount, canRetry: true };