Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: await pending-merge checkout probes (#13226, #13227)
Adam Eivy8293c55e16cd
diff --git a/server/services/pendingMergeGuard.js b/server/services/pendingMergeGuard.jsindex 266c977975..47657c76b4 100644--- a/server/services/pendingMergeGuard.js+++ b/server/services/pendingMergeGuard.js@@ -31,15 +31,17 @@ async function supportsPendingMergeGuard(repoPath) {export async function verifyPendingMergeCheckout(repoPath, worktreePath, branch, headSha) {if (!worktreePath || resolve(repoPath) === resolve(worktreePath)) return false;const read = async (args, cwd = worktreePath) => (await execGit(args, cwd)).stdout.trim();- const checked = await Promise.all([+ // A rejected probe still owns its sibling Git processes until they settle.+ // In particular, detached HEAD must not release a checkout while status runs.+ const checked = await Promise.allSettled([read(['rev-parse', '--path-format=absolute', '--git-common-dir']),read(['rev-parse', '--path-format=absolute', '--git-common-dir'], repoPath),read(['rev-parse', '--verify', 'HEAD^{commit}']),read(['symbolic-ref', '--quiet', '--short', 'HEAD']),read(['status', '--porcelain=v1', '--untracked-files=all']),- ]).catch(() => null);- if (!checked) return false;- const [common, primaryCommon, head, ref, status] = checked;+ ]);+ if (checked.some(result => result.status === 'rejected')) return false;+ const [common, primaryCommon, head, ref, status] = checked.map(result => result.value);return common === primaryCommon && head === headSha && ref === branch && !status;}diff --git a/server/services/pendingMergeGuard.lifecycle.test.js b/server/services/pendingMergeGuard.lifecycle.test.jsnew file mode 100644index 0000000000..c9a888aff6--- /dev/null+++ b/server/services/pendingMergeGuard.lifecycle.test.js@@ -0,0 +1,28 @@+import { expect, it, vi } from 'vitest';++vi.mock('../lib/execGit.js', () => ({ execGit: vi.fn() }));+import { execGit } from '../lib/execGit.js';+import { verifyPendingMergeCheckout } from './pendingMergeGuard.js';++it('retains checkout ownership until every Git probe settles after one probe rejects', async () => {+ const status = Promise.withResolvers();+ execGit.mockImplementation(async args => {+ if (args[0] === 'symbolic-ref') throw new Error('detached HEAD');+ if (args[0] === 'status') return status.promise;+ return { stdout: args.includes('HEAD^{commit}') ? 'a'.repeat(40) : '/common' };+ });+ const settled = vi.fn();+ const checking = verifyPendingMergeCheckout('/repo', '/claim', 'claim/issue-1', 'a'.repeat(40));+ const observed = checking.then(settled);+ try {+ // Drain the rejected probe's promise reactions without advancing time.+ // The outstanding status probe still owns the checkout's working directory.+ await new Promise(resolve => setImmediate(resolve));+ expect(settled).not.toHaveBeenCalled();+ status.resolve({ stdout: '' });+ await expect(checking).resolves.toBe(false);+ } finally {+ status.resolve({ stdout: '' });+ await observed;+ }+});