Skip to content

Commit e4314b7

Browse files
bellorrclaude
andcommitted
fix(docker): resolve llama.cpp header overwrite causing SIGSEGV
COPY . . overwrites the fresh llama.cpp b8157 headers (copied from the build stage) with the stale b7285 headers committed to the repo. The resulting struct size mismatch causes a SIGSEGV in create_gen_context when llama_init_from_model reads garbage for the new samplers field added in b8157. Fix: move the header COPY to after COPY . . in all affected Dockerfiles so the correct versioned headers always take precedence. Fixes crash: "the backend samplers must be of type llama_sampler_chain" Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 41ad1eb commit e4314b7

File tree

6 files changed

+40
-13
lines changed

6 files changed

+40
-13
lines changed

docker/Dockerfile.amd64-cuda

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ ENV PATH="/usr/local/go/bin:${PATH}" CUDA_HOME=/usr/local/cuda
4747

4848
WORKDIR /build
4949

50-
# Copy llama artifacts
50+
# Copy llama static libraries (before COPY . . for better layer caching)
5151
COPY --from=llama /output/lib/*.a /build/lib/llama/
52-
COPY --from=llama /output/include/*.h /build/lib/llama/
5352

5453
# Go dependencies
5554
COPY go.mod go.sum ./
@@ -59,6 +58,11 @@ RUN go mod download
5958
COPY . .
6059
COPY --from=ui /ui/dist ./ui/dist
6160

61+
# Overwrite repo headers with ones matching LLAMA_VERSION (must be AFTER COPY . .)
62+
# COPY . . would otherwise replace these with the stale headers committed to the repo,
63+
# causing a struct size mismatch between the compiled library and the CGo bindings.
64+
COPY --from=llama /output/include/*.h /build/lib/llama/
65+
6266
# Build with CUDA + localllm (with or without UI based on HEADLESS arg)
6367
RUN COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") && \
6468
BUILD_TIME=$(date -u +%Y%m%d-%H%M%S) && \

docker/Dockerfile.amd64-cuda-heimdall

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ ENV PATH="/usr/local/go/bin:${PATH}" CUDA_HOME=/usr/local/cuda
4444

4545
WORKDIR /build
4646

47-
# Copy llama artifacts
47+
# Copy llama static libraries (before COPY . . for better layer caching)
4848
COPY --from=llama /output/lib/*.a /build/lib/llama/
49-
COPY --from=llama /output/include/*.h /build/lib/llama/
5049

5150
# Go dependencies
5251
COPY go.mod go.sum ./
@@ -56,6 +55,11 @@ RUN go mod download
5655
COPY . .
5756
COPY --from=ui /ui/dist ./ui/dist
5857

58+
# Overwrite repo headers with ones matching LLAMA_VERSION (must be AFTER COPY . .)
59+
# COPY . . would otherwise replace these with the stale headers committed to the repo,
60+
# causing a struct size mismatch between the compiled library and the CGo bindings.
61+
COPY --from=llama /output/include/*.h /build/lib/llama/
62+
5963
# Build with CUDA + localllm + heimdall
6064
RUN echo "Building with CUDA + localllm + heimdall..." && \
6165
CGO_ENABLED=1 go build -tags "cuda localllm heimdall" \

docker/Dockerfile.amd64-vulkan-heimdall

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ RUN git clone --depth 1 --branch b8157 https://github.com/ggml-org/llama.cpp.git
4848
-DBUILD_SHARED_LIBS=ON \
4949
-DCMAKE_BUILD_TYPE=Release && \
5050
cmake --build build -j${LLAMA_BUILD_JOBS} && \
51-
mkdir -p /output/lib && \
51+
mkdir -p /output/lib /output/include && \
5252
cp build/bin/*.so /output/lib/ 2>/dev/null || true && \
5353
cp build/src/*.so /output/lib/ 2>/dev/null || true && \
5454
cp build/ggml/src/*.so /output/lib/ 2>/dev/null || true && \
55-
cp build/ggml/src/ggml-cpu/*.so /output/lib/ 2>/dev/null || true
55+
cp build/ggml/src/ggml-cpu/*.so /output/lib/ 2>/dev/null || true && \
56+
cp include/llama.h /output/include/ && \
57+
cp ggml/include/*.h /output/include/
5658

5759
# =============================================================================
5860
# Stage 3: Go build with Vulkan + localllm (CPU)
@@ -68,7 +70,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
6870
libvulkan-dev \
6971
&& rm -rf /var/lib/apt/lists/*
7072

71-
# Copy llama.cpp CPU libraries
73+
# Copy llama.cpp CPU libraries (before COPY . . for better layer caching)
7274
COPY --from=llama-builder /output/lib /build/lib/llama/
7375

7476
# Go dependencies
@@ -79,6 +81,11 @@ RUN go mod download
7981
COPY . .
8082
COPY --from=ui /ui/dist ./ui/dist
8183

84+
# Overwrite repo headers with ones matching the cloned LLAMA_VERSION (must be AFTER COPY . .)
85+
# COPY . . would otherwise leave the stale headers committed to the repo,
86+
# causing a struct size mismatch between the compiled library and the CGo bindings.
87+
COPY --from=llama-builder /output/include/*.h /build/lib/llama/
88+
8289
# Build with Vulkan + localllm (CPU-based inference for Heimdall)
8390
RUN COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") && \
8491
BUILD_TIME=$(date -u +%Y%m%d-%H%M%S) && \

docker/Dockerfile.arm64-metal

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ WORKDIR /build
6565

6666
RUN apt-get update && apt-get install -y --no-install-recommends build-essential && rm -rf /var/lib/apt/lists/*
6767

68-
# Copy llama artifacts
68+
# Copy llama static library (before COPY . . for better layer caching)
6969
COPY --from=llama /out/libllama_combined.a /build/lib/llama/libllama_linux_arm64.a
70-
COPY --from=llama /out/*.h /build/lib/llama/
7170

7271
# Go dependencies
7372
COPY go.mod go.sum ./
@@ -77,6 +76,11 @@ RUN go mod download
7776
COPY . .
7877
COPY --from=ui /ui/dist ./ui/dist
7978

79+
# Overwrite repo headers with ones matching LLAMA_VERSION (must be AFTER COPY . .)
80+
# COPY . . would otherwise replace these with the stale headers committed to the repo,
81+
# causing a struct size mismatch between the compiled library and the CGo bindings.
82+
COPY --from=llama /out/*.h /build/lib/llama/
83+
8084
# Build (with or without UI based on HEADLESS arg)
8185
# NOTE: Cannot use -static linking because Go plugins require dynamic linking
8286
RUN if [ "$HEADLESS" = "true" ]; then \

docker/Dockerfile.arm64-metal-heimdall

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ WORKDIR /build
6464

6565
RUN apt-get update && apt-get install -y --no-install-recommends build-essential && rm -rf /var/lib/apt/lists/*
6666

67-
# Copy llama artifacts
67+
# Copy llama static library (before COPY . . for better layer caching)
6868
COPY --from=llama /out/libllama_combined.a /build/lib/llama/libllama_linux_arm64.a
69-
COPY --from=llama /out/*.h /build/lib/llama/
7069

7170
# Go dependencies
7271
COPY go.mod go.sum ./
@@ -76,6 +75,11 @@ RUN go mod download
7675
COPY . .
7776
COPY --from=ui /ui/dist ./ui/dist
7877

78+
# Overwrite repo headers with ones matching LLAMA_VERSION (must be AFTER COPY . .)
79+
# COPY . . would otherwise replace these with the stale headers committed to the repo,
80+
# causing a struct size mismatch between the compiled library and the CGo bindings.
81+
COPY --from=llama /out/*.h /build/lib/llama/
82+
7983
# Build with full features (localllm for both embedding and SLM generation)
8084
RUN echo "Building NornicDB with Heimdall support..." && \
8185
CGO_ENABLED=1 go build -tags=localllm \

docker/Dockerfile.cpu-bge

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ WORKDIR /build
6666

6767
RUN apt-get update && apt-get install -y --no-install-recommends build-essential && rm -rf /var/lib/apt/lists/*
6868

69-
# Copy llama artifacts - use TARGETARCH to determine the library name
69+
# Copy llama static library (before COPY . . for better layer caching)
7070
COPY --from=llama /out/libllama_combined.a /build/lib/llama/libllama_linux_${TARGETARCH}.a
71-
COPY --from=llama /out/*.h /build/lib/llama/
7271

7372
# Go dependencies
7473
COPY go.mod go.sum ./
@@ -78,6 +77,11 @@ RUN go mod download
7877
COPY . .
7978
COPY --from=ui /ui/dist ./ui/dist
8079

80+
# Overwrite repo headers with ones matching LLAMA_VERSION (must be AFTER COPY . .)
81+
# COPY . . would otherwise replace these with the stale headers committed to the repo,
82+
# causing a struct size mismatch between the compiled library and the CGo bindings.
83+
COPY --from=llama /out/*.h /build/lib/llama/
84+
8185
# Build with localllm tag for embedded embeddings
8286
RUN if [ "$HEADLESS" = "true" ]; then \
8387
echo "Building headless CPU-only with embeddings..." && \

0 commit comments

Comments
 (0)