Skip to content

fix(ollama): set ContextSize via the embedded LLMConfig so the package builds#11049

Merged
mudler merged 1 commit into
masterfrom
fix/ollama-contextsize-literal
Jul 22, 2026
Merged

fix(ollama): set ContextSize via the embedded LLMConfig so the package builds#11049
mudler merged 1 commit into
masterfrom
fix/ollama-contextsize-literal

Conversation

@localai-bot

Copy link
Copy Markdown
Collaborator

Problem

make lint has been failing on master since bf19758, and takes tests-linux / tests-apple down with it on every PR branched after that commit:

core/http/endpoints/ollama/helpers_internal_test.go:33:31:
  unknown field ContextSize in struct literal of type
  "github.com/mudler/LocalAI/core/config".ModelConfig
core/http/endpoints/ollama/helpers_internal_test.go:44:30: (same)

ContextSize is not a direct field of ModelConfig. It lives on LLMConfig (core/config/model_config.go:1059), which ModelConfig embeds inline (core/config/model_config.go:106). Go permits reading a promoted field but not setting one in a composite literal, so config.ModelConfig{ContextSize: &existing} has never compiled.

Master lint history pins it exactly:

commit lint
48b7d6d8f success
bf19758e0 (#11032) failure
everything after failure (inherited)

Fix

Use the literal form already used everywhere else in the tree for this field (see core/backend/options_internal_test.go:301):

cfg := &config.ModelConfig{LLMConfig: config.LLMConfig{ContextSize: &existing}}

Two lines, test-only. No production code touched.

Why this matters beyond a green build

The specs were not merely uncompiled, they were inert. #11032 is a DoS fix: an unauthenticated client raising the context ceiling drives KV-cache allocation, and an oversized num_ctx can trigger a catastrophic OOM. The regression guard it shipped was never executing.

Confirmed the restored specs are functional rather than vacuous by stubbing out the ceiling clamp in applyOllamaOptions, which fails the intended spec:

[FAIL] applyOllamaOptions num_ctx clamping (issue #11022)
  [It] does not let an oversized num_ctx raise an existing context ceiling
  helpers_internal_test.go:37

The coverage gate corroborates it: coverage rose 54.2% -> 55.3% from this two-line change alone, because a whole package's tests started running.

Verification

  • go vet ./core/http/endpoints/ollama/ - clean
  • go test -count=1 ./core/http/endpoints/ollama/ - ok, 5/5 num_ctx specs execute
  • make lint (full repo) - 0 issues
  • Full pre-commit gate incl. coverage - passed, no --no-verify

Note on process

bf19758 merged carrying a self-contained compile error in its own new test file, so its PR either never ran lint or merged on a stale check. May be worth a look at why the gate allowed it.

Unrelated CI noise (no action needed here)

While diagnosing I checked the other red PRs:

…e builds

The num_ctx clamping specs added in #11032 construct their fixture with
`config.ModelConfig{ContextSize: &existing}`, but ContextSize is not a
direct field of ModelConfig: it belongs to LLMConfig, which ModelConfig
embeds inline. Go allows reading a promoted field but not setting one in
a composite literal, so the test file has never compiled:

  helpers_internal_test.go:33:31: unknown field ContextSize in struct
    literal of type "github.com/mudler/LocalAI/core/config".ModelConfig

This broke `make lint` on master from bf19758 onward, and because the
typecheck failure takes down the whole package it also reds tests-linux
and tests-apple on every PR branched after that commit.

Use the same literal form the rest of the tree already uses for this
field (see core/backend/options_internal_test.go).

Worth noting the specs were not merely uncompiled but inert: #11032 is a
DoS fix (an unauthenticated client raising the context ceiling drives
KV-cache allocation), and its regression guard was never actually
running. Verified the restored specs are functional by stubbing out the
ceiling clamp, which fails the "does not let an oversized num_ctx raise
an existing context ceiling" spec as intended.

Assisted-by: Claude Code:claude-opus-4-8[1m] [Read] [Edit] [Bash]
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
@mudler
mudler merged commit 7a8db9b into master Jul 22, 2026
22 of 23 checks passed
@mudler
mudler deleted the fix/ollama-contextsize-literal branch July 22, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants