The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(cli): a concurrent native helper preparer accepts a target linked mid-check (#2371)
harness-for-autonomous[bot]901cae1da9ab
diff --git a/cli/src/lib/nativeProcessImages.spec.ts b/cli/src/lib/nativeProcessImages.spec.tsindex dc8ebf325..ede73c65f 100644--- a/cli/src/lib/nativeProcessImages.spec.ts+++ b/cli/src/lib/nativeProcessImages.spec.ts@@ -5,13 +5,17 @@ import { join } from 'node:path'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { env } from '../config/env.js'-const host = vi.hoisted(() => ({ platform: 'darwin', execFile: vi.fn(), beforeStat: undefined as Promise<void> | undefined }))+const host = vi.hoisted(() => ({+ platform: 'darwin', execFile: vi.fn(), beforeStat: undefined as Promise<void> | undefined,+ onStat: undefined as ((path: string) => Promise<void>) | undefined,+}))vi.mock('node:os', async original => ({ ...await original<typeof import('node:os')>(), platform: () => host.platform }))vi.mock('node:child_process', async original => ({ ...await original<typeof import('node:child_process')>(), execFile: host.execFile }))vi.mock('node:fs/promises', async original => {const fs = await original<typeof import('node:fs/promises')>()return { ...fs, lstat: async (...args: Parameters<typeof fs.lstat>) => {await host.beforeStat+ await host.onStat?.(String(args[0]))return fs.lstat(...args)} }})@@ -36,6 +40,7 @@ beforeEach(async () => {host.platform = 'darwin'host.execFile.mockReset()host.beforeStat = undefined+ host.onStat = undefined})afterEach(async () => {env.ADAPTER_RUNTIME_DIR = originalRuntime@@ -99,6 +104,22 @@ describe('bundled native helper preparation', () => {expect(await prepareProcessImageHelper(artifact, root)).toBe(path)})+ // Linux CI, #2358 at d618a08: the concurrent test above returned one path and one null.+ // A preparer found no target, then another linked it before this one's existence+ // check, which took the new, complete helper for a foreign file. Force that order.+ it('accepts a helper another preparer completes between its check and its lstat', async () => {+ const target = join(root, 'process-images', artifact.sha256)+ let raced = false+ host.onStat = async path => {+ if (path !== target || raced) return+ raced = true+ expect(await prepareProcessImageHelper(artifact, root)).toBe(target)+ }+ expect(await prepareProcessImageHelper(artifact, root)).toBe(target)+ expect(raced).toBe(true)+ expect(await readdir(join(root, 'process-images'))).toEqual([artifact.sha256])+ })+it('rejects an invalid embedded hash without writing a file', async () => {expect(await prepareProcessImageHelper({ ...artifact, sha256: '0'.repeat(64) }, root)).toBeNull()expect(await readdir(root)).toEqual([])diff --git a/cli/src/lib/nativeProcessImages.ts b/cli/src/lib/nativeProcessImages.tsindex 28be913b1..c509df7ea 100644--- a/cli/src/lib/nativeProcessImages.ts+++ b/cli/src/lib/nativeProcessImages.ts@@ -86,7 +86,9 @@ export async function prepareProcessImageHelper(await privateDirectory(directory)const target = join(directory, artifact.sha256)if (await verifyFile(target, artifact)) return target- try { await lstat(target); return null }+ // Another daemon may link a complete helper after the check above (#2358 on Linux CI).+ // An existing target is only ever verified again, never replaced.+ try { await lstat(target); return await verifyFile(target, artifact) ? target : null }catch (error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error }// A bad existing target stays untouched and cannot be executed. link()// below is create-only, so concurrent writers cannot replace one another.