From d23decf5a83008bf33a205ab02e0e267d9172015 Mon Sep 17 00:00:00 2001 From: atomic-sentry-bot Date: Sun, 29 Nov 2026 04:36:40 +0000 Subject: [PATCH] fix: address Sentry issue 7872816480 --- ...through-to-the-next-cuda-runtime-source.md | 12 ++++ docs/decisions/INDEX.md | 1 + ...cuda-runtime-source-donor-vanished.test.ts | 57 +++++++++++++++++++ src/backend/install/cuda-runtime-source.ts | 23 +++++++- 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 docs/decisions/2026-11-29-a-vanished-donor-dll-falls-through-to-the-next-cuda-runtime-source.md create mode 100644 src/backend/install/cuda-runtime-source-donor-vanished.test.ts diff --git a/docs/decisions/2026-11-29-a-vanished-donor-dll-falls-through-to-the-next-cuda-runtime-source.md b/docs/decisions/2026-11-29-a-vanished-donor-dll-falls-through-to-the-next-cuda-runtime-source.md new file mode 100644 index 00000000..1ec20ad7 --- /dev/null +++ b/docs/decisions/2026-11-29-a-vanished-donor-dll-falls-through-to-the-next-cuda-runtime-source.md @@ -0,0 +1,12 @@ +--- +date: 2026-11-29 +title: "Let a vanished donor DLL fall through to the next CUDA runtime source" +--- + +# 2026-11-29 — Let a vanished donor DLL fall through to the next CUDA runtime source + +- **Context:** Delivering a Windows CUDA runtime lists a donor directory (another installed pack, the legacy `llamacpp/lib` folder, or a host CUDA toolkit) and then copies every expected DLL. On Windows an antivirus quarantine or a concurrent backend update can remove a file between that listing and the copy. The raw `ENOENT` escaped the donor loop and aborted the whole install before the release companion, NVIDIA redistributables or the pinned companion were tried; the backend layer reported it as an unknown failure, so the user saw only a generic install error. +- **Decision:** Treat a per-file `ENOENT`/`ENOTDIR` during a donor copy as "this donor cannot supply the set" and return `false` so the caller continues with the next source. Every other filesystem error (`EACCES`, `ENOSPC`, …) still propagates, and a source is only accepted after the whole set is copied. +- **Consequences:** A quarantined or concurrently replaced donor DLL no longer fails an install that another source could satisfy. Partial files from the abandoned donor are overwritten by the next source, which copies the complete set; if no source succeeds the install still fails with `ENGINE_BINARY_BROKEN` and the list of tried sources. Copy failures on real write problems remain visible rather than being retried as a different source. +- **Owner:** `team`. +- **Links:** `src/backend/install/cuda-runtime-source.ts`, `src/backend/install/cuda-runtime-source-donor-vanished.test.ts`, ADR `2026-11-04-keep-cuda-runtime-repair-cancellable-and-coherent.md`. diff --git a/docs/decisions/INDEX.md b/docs/decisions/INDEX.md index 5bc5036d..8eda9bff 100644 --- a/docs/decisions/INDEX.md +++ b/docs/decisions/INDEX.md @@ -297,3 +297,4 @@ add a new one that says which record it supersedes. - [2026-11-23 — Compact overflowing chat history on every engine](2026-11-23-compact-overflowing-chat-history-on-every-engine.md) - [2026-11-23 — Map every engine's context overflow to one error](2026-11-23-map-every-engines-context-overflow-to-one-error.md) - [2026-11-23 — Default every engine to the largest window that fits](2026-11-23-default-every-engine-to-the-largest-window-that-fits.md) +- [Let a vanished donor DLL fall through to the next CUDA runtime source](2026-11-29-a-vanished-donor-dll-falls-through-to-the-next-cuda-runtime-source.md) diff --git a/src/backend/install/cuda-runtime-source-donor-vanished.test.ts b/src/backend/install/cuda-runtime-source-donor-vanished.test.ts new file mode 100644 index 00000000..dedf5516 --- /dev/null +++ b/src/backend/install/cuda-runtime-source-donor-vanished.test.ts @@ -0,0 +1,57 @@ +import { mkdir, readdir, writeFile } from 'node:fs/promises' +import { join } from 'node:path' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { cudaRuntimeZip } from '../../../test/helpers/backend-install-e2e.js' +import { makeTmpDataFolder } from '../../../test/helpers/tmp-data-folder.js' +import type { TmpDataFolder } from '../../../test/helpers/tmp-data-folder.js' +import type { DownloadItem } from '../../downloads/index.js' +import { deliverWindowsCudaRuntime } from './cuda-runtime-source.js' + +let data: TmpDataFolder +beforeEach(async () => { + data = await makeTmpDataFolder('atomic-core-cuda-donor-') +}) +afterEach(() => data.cleanup()) + +const runtime = ['cudart64_12.dll', 'cublas64_12.dll', 'cublasLt64_12.dll'] + +const packDir = (version: string, backend: string) => + join(data.layout.provider('llamacpp-upstream').backendsDir, version, backend) + +describe('deliverWindowsCudaRuntime with a donor that lost a DLL', () => { + it('falls back to the next source when a listed donor DLL has vanished before the copy', async () => { + // The donor directory exists and its listing names the whole runtime, but the files are gone by + // the time the copy runs: on Windows an antivirus quarantine or a concurrent backend update does + // exactly this. The install must treat that donor as unusable and use the next source. + const donor = join(packDir('b11000', 'win-cuda-12.4-x64'), 'build', 'bin') + await mkdir(donor, { recursive: true }) + const listDir = (dir: string) => + dir === donor ? Promise.resolve([...runtime]) : readdir(dir).catch(() => [] as string[]) + + const items: DownloadItem[] = [] + const download = vi.fn(async (_task: string, batch: DownloadItem[]) => { + for (const item of batch) { + if (!item.url.endsWith('cudart-llama-bin-win-cuda-12.4-x64.zip')) throw new Error('offline') + items.push(item) + await writeFile(item.save_path, cudaRuntimeZip(12, '')) + } + }) + + const target = { + provider: 'llamacpp-upstream' as const, + version: 'b12019', + backend: 'win-cuda-12.4-x64', + packDir: packDir('b12019', 'win-cuda-12.4-x64'), + } + const source = await deliverWindowsCudaRuntime(target, { + layout: data.layout, + downloader: { download }, + taskId: 'donor-vanished', + env: {}, + listDir, + }) + + expect(source).toBe('pinned-companion') + expect((await readdir(join(target.packDir, 'build', 'bin'))).sort()).toEqual([...runtime].sort()) + }) +}) diff --git a/src/backend/install/cuda-runtime-source.ts b/src/backend/install/cuda-runtime-source.ts index 1372f81b..9080c210 100644 --- a/src/backend/install/cuda-runtime-source.ts +++ b/src/backend/install/cuda-runtime-source.ts @@ -16,7 +16,8 @@ * * An incomplete runtime is replaced as a whole from one source: existing cuBLAS and cuBLASLt may * belong to different releases, so filling only the missing filenames is not enough. A failed copy is never reported as a successful repair; the caller decides how to - * handle a pack that remains unusable. + * handle a pack that remains unusable. A donor whose listed DLL disappears before the copy (antivirus + * quarantine, concurrent pack update) is an unusable source, not a fatal install error. */ import { copyFile, mkdir, readdir, rm } from 'node:fs/promises' @@ -123,6 +124,13 @@ function archOfPack(provider: string, backend: string): 'x64' | 'arm64' { const defaultList = (dir: string) => readdir(dir).catch(() => [] as string[]) +/** An entry named by the listing that is gone before the copy: this donor cannot supply the set. */ +function donorEntryMissing(error: unknown): boolean { + if (!(error instanceof Error)) return false + const code = (error as NodeJS.ErrnoException).code + return code === 'ENOENT' || code === 'ENOTDIR' +} + /** Copy `names` from `fromDir` into `toDir` when it has every one of them (case-insensitive). */ async function copyAllFrom( fromDir: string, @@ -134,8 +142,17 @@ async function copyAllFrom( const sources = names.map((name) => byLower.get(name.toLowerCase())) if (sources.some((s) => s === undefined)) return false await mkdir(toDir, { recursive: true }) - for (const [i, name] of names.entries()) - await copyFile(join(fromDir, sources[i] as string), join(toDir, name)) + for (const [i, name] of names.entries()) { + try { + await copyFile(join(fromDir, sources[i] as string), join(toDir, name)) + } catch (error) { + // The listing is only a snapshot: a quarantined or concurrently replaced file makes this + // source unusable, and the next source may still supply the whole set. Other fs errors + // (EACCES, ENOSPC, …) are real problems for the install and keep propagating. + if (donorEntryMissing(error)) return false + throw error + } + } return true }