Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): release abandoned pool checkpoint refs
david919c660b8dcf
diff --git a/apps/desktop/src/main/__tests__/worktreeRecovery.git-integration.test.ts b/apps/desktop/src/main/__tests__/worktreeRecovery.git-integration.test.tsindex 6a71e4f32b..a462cdacc9 100644--- a/apps/desktop/src/main/__tests__/worktreeRecovery.git-integration.test.ts+++ b/apps/desktop/src/main/__tests__/worktreeRecovery.git-integration.test.ts@@ -446,6 +446,30 @@ describe('worktree recovery with real Git', () => {expect(await git(repo, 'for-each-ref', 'refs/cindy/worktree-recovery/moving/')).toBe('');}, 30_000);+ // PR #6898 r4357569426: previous capture-abort coverage stops before capture returns.+ // Exercise checkpointWorktreeForReuse with an edit just after ref creation: rejecting reuse+ // must leave the edit intact and no orphan ref. Real refs require the git-integration tier.+ it('drops the pool checkpoint ref when the checkout changes before reuse', async () => {+ const meta = await createFixture('pool-checkpoint');+ const refsBefore = await git(repo, 'for-each-ref', 'refs/cindy/worktree-recovery/');+ const mocked = vi.mocked(gitExec);+ const real = mocked.getMockImplementation()!;+ mocked.mockImplementation(async (args, cwd, options) => {+ const result = await real(args, cwd, options);+ if (args[0] === 'update-ref' && args[1]?.startsWith('refs/cindy/')) {+ await fs.writeFile(path.join(meta.path, 'draft.txt'), 'edited after capture\n');+ }+ return result;+ });+ try {+ await expect(checkpointWorktreeForReuse(meta)).rejects.toThrow('pooled worktree changed before reuse');+ } finally {+ mocked.mockImplementation(real);+ }+ expect(await git(repo, 'for-each-ref', 'refs/cindy/worktree-recovery/')).toBe(refsBefore);+ expect(await fs.readFile(path.join(meta.path, 'draft.txt'), 'utf8')).toBe('edited after capture\n');+ }, 30_000);+it('notices staging that happens while the full tree is compared', async () => {const meta = await createFixture('staged-meanwhile');const snapshot = await captureWorktreeContent(meta.path, 'refs/cindy/worktree-recovery/meanwhile/tree', { includeUntracked: true });diff --git a/apps/desktop/src/main/worktree/managedRecycle.ts b/apps/desktop/src/main/worktree/managedRecycle.tsindex 7b9c77f063..b671a043b8 100644--- a/apps/desktop/src/main/worktree/managedRecycle.ts+++ b/apps/desktop/src/main/worktree/managedRecycle.ts@@ -48,15 +48,23 @@ export async function checkpointWorktreeForReuse(meta: WorktreeMeta): Promise<vo}const gitLink = await fs.lstat(path.join(meta.path, '.git'));if (!gitLink.isFile() || gitLink.isSymbolicLink()) throw new Error('pooled worktree Git link is missing');- record.snapshot = await captureWorktreeContent(meta.path, `refs/cindy/worktree-recovery/${record.id}/${randomUUID()}`, { includeUntracked: true });- if (hasLiveSessionReference(meta, await loadLiveSessionPathKeys({ contextPath: meta.path }))- || !(await worktreeContentMatches(meta.path, record.snapshot))) {- throw new Error('pooled worktree changed before reuse');+ const snapshot = await captureWorktreeContent(meta.path, `refs/cindy/worktree-recovery/${record.id}/${randomUUID()}`, { includeUntracked: true });+ record.snapshot = snapshot;+ try {+ if (hasLiveSessionReference(meta, await loadLiveSessionPathKeys({ contextPath: meta.path }))+ || !(await worktreeContentMatches(meta.path, snapshot))) {+ throw new Error('pooled worktree changed before reuse');+ }+ await assertManagedResourcePath(meta, store.getAllPaths());+ await assertWorktreeGitIdentity(meta);+ if (await directoryIdentity(meta.path) !== record.directoryIdentity) throw new Error('pooled directory replaced');+ } catch (error) {+ // Reuse is abandoned with the checkout intact, and no record names this ref yet.+ await releaseSnapshotRef(meta.baseRepo, snapshot);+ throw error;}- await assertManagedResourcePath(meta, store.getAllPaths());- await assertWorktreeGitIdentity(meta);- if (await directoryIdentity(meta.path) !== record.directoryIdentity) throw new Error('pooled directory replaced');record.phase = 'removed';+ // Keep the ref if this throws: history may already be durable before the current record fails.await writeRecycleRecord(record);}