Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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`.
1 change: 1 addition & 0 deletions docs/decisions/INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
57 changes: 57 additions & 0 deletions src/backend/install/cuda-runtime-source-donor-vanished.test.ts
Original file line number Diff line number Diff line change
@@ -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())
})
})
23 changes: 20 additions & 3 deletions src/backend/install/cuda-runtime-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -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
}

Expand Down
Loading