Skip to content

fix: config/models.yaml parsing failures - #206

Merged
thushan merged 9 commits into
mainfrom
fix/issue-204-models-yaml-parse
Aug 5, 2026
Merged

thushan merged 9 commits into
mainfrom
fix/issue-204-models-yaml-parse

Conversation

@thushan

@thushan thushan commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

The shipped config/models.yaml used \d inside double-quoted YAML scalars, which is not
a vaalid YAML escape, so the file has never parsed on any install. loadConfigFromFile()
swallowed the error and silently fell back to embedded defaults, meaning user customisations
(e.g. capability tagging via name_patterns) were discarded with no diagnostic.

Changes

  • Parse fix: the three regex patterns containing \d are now single-quoted scalars.
  • INFO diagnostics at startup: config loading is now eager (triggered from
    unifier.NewFactory() at boot, not lazily on first request). Olla logs the loaded source
    at INFO, and a found-but-unparseable candidate at WARN with the path and YAML error -
    including when a later candidate path loads successfully (a broken ./models.yaml shadowed
    by a valid config/models.yaml warns about both).
  • Empty-config guard: a zero-byte or comment-only models.yaml parses "successfully" as
    a config with no rules; it now warns and falls through to the next candidate instead.
  • Candidate dedupe: with OLLA_CONFIG_DIR unset, the env candidate collapsed to a
    duplicate of ./models.yaml, doubling warnings; the candidate is now only added when the
    env var is set, and the list is deduped.
  • Defaults reconciled: because the file never loaded, it had drifted from
    getDefaultConfig(). Both sides are now identical, guarded by an equivalence test so they
    cannot drift silently again.

Behaviour changes

  • config/models.yaml (and user copies of it) now actually take effect.
  • New startup log lines: INFO model unification config loaded source=... or a WARN on
    parse failure.
  • Newly effective default mappings that previously only existed in the (never-loaded) file
    or only in code: Q4_K_XL → q4kxl, llama4 architecture mapping, and publisher mappings
    for falcon, vicuna, bloom, opt, gpt2, gptj and gptneox. Unified model IDs are unaffected -
    these change metadata in /olla/models only.

Tests

  • Regression: the shipped config/models.yaml must unmarshal into the real struct and every
    regex must compile.
  • Equivalence guard: shipped file and embedded defaults compared field by field.
  • Failure paths: broken file (original \d construct), empty file, comment-only file - each
    asserts the warning and clean fallback with no panic.
  • Fixed a pre-existing test-order flake (go test -shuffle) caused by singleton pollution.

Not in this PR

Will be subsequent PRs.

  • --validate-config CLI switch / config hashing.
  • profile.LoadProfiles() has the same silent-swallow pattern for broken profile YAMLs.
  • Exposing the active config source via /internal/status.

Summary by CodeRabbit

  • New Features

    • Expanded model recognition with additional family aliases, publisher mappings and llama4 architecture support.
    • Added support for the Q4_K_XL quantisation format.
    • Configuration status and source information are now reported at startup.
  • Bug Fixes

    • Improved configuration loading when files are empty, invalid or unavailable.
    • The system now continues using valid fallback settings and provides warnings when configuration issues occur.
  • Tests

    • Added coverage for configuration parsing, fallback behaviour and status reporting.

thushan added 5 commits August 4, 2026 22:16
…il-safe

LogConfigStatus was returning as soon as a later candidate path loaded
successfully, so a broken ./models.yaml sitting next to a working
config/models.yaml went unmentioned - the exact silence issue #204 was
about. Now it always surfaces parse warnings before checking the source.
Also promoted the healthy-path "config loaded" log from Debug to Info so
it's visible at default verbosity, guarded against a nil logger since
NewFactory now calls this unconditionally, and fixed a pre-existing test
that mutated the config singleton without restoring it (flaky under
-shuffle).
Two remaining silent-failure shapes from the #204 family: an empty or
comment-only models.yaml is valid YAML and unmarshals cleanly, so it was
being treated as a successful load with zero patterns or mappings inside.
loadConfigFromFile now checks for that and warns + skips the candidate
instead. Separately, the OLLA_CONFIG_DIR candidate collapsed to the same
"models.yaml" as the first candidate whenever the env var was unset,
double-reading (and double-warning on) the same broken file - only add
that candidate when the env var is actually set, and dedupe the list.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The change improves model configuration loading diagnostics and fallback handling, logs configuration status during factory initialisation, expands default model mappings, updates shipped YAML configuration, and adds validation tests.

Changes

Model configuration

Layer / File(s) Summary
Configuration loading and startup status
internal/adapter/unifier/model_config.go, internal/adapter/unifier/factory.go, internal/adapter/unifier/model_config_test.go
Configuration loading now tracks source paths and warnings, handles invalid candidates, rejects empty files, and falls back to embedded defaults. NewFactory logs configuration status during initialisation. Tests cover loading, fallback, warnings, logging, and cache isolation.
Default mappings and shipped configuration
config/models.yaml, internal/adapter/unifier/model_config.go
The shipped configuration and embedded defaults include expanded family aliases, publisher mappings, Q4_K_XL, preserved family names, and the llama4 architecture mapping.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NewFactory
  participant LogConfigStatus
  participant LoadModelConfig
  participant ConfigCandidates
  participant StyledLogger
  NewFactory->>LogConfigStatus: log configuration status
  LogConfigStatus->>LoadModelConfig: load configuration
  LoadModelConfig->>ConfigCandidates: inspect candidate files
  ConfigCandidates-->>LoadModelConfig: configuration or warning
  LogConfigStatus->>StyledLogger: report source and warnings
Loading

Possibly related issues

  • thushan/olla issue 204: The change addresses YAML regex parsing failures and adds warning and source reporting for configuration fallback.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: fixing parsing failures in config/models.yaml.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-204-models-yaml-parse

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/adapter/unifier/model_config.go`:
- Around line 75-88: Update the Go doc comments for LoadModelConfig and
ConfigSource to explain why process-wide caching via configOnce is required and
why configuration loading is deferred until an entry point is called. Retain the
existing behavioral details only as supporting context, while making the
comments focus on the rationale.
- Around line 77-81: The configOnce initialization around loadConfigFromFile and
configInstance.compilePatterns must fall back when pattern compilation fails:
replace configInstance with compiled embedded defaults, clear configSource, and
preserve the original compilation error in configParseWarnings before reporting
configuration details. Add a regression test using valid YAML containing an
invalid regular-expression pattern to verify the fallback and warning behavior.
- Around line 116-119: Update the warning logic around configParseWarnings and
configSource to distinguish empty-file warnings from parse failures and report
the actual unusable candidate cause. Use the final active configSource in the
message instead of always claiming embedded defaults, and add coverage for an
empty candidate plus a broken earlier candidate followed by a valid later
candidate.
- Around line 126-128: Update loadConfigFromFile to ignore os.ReadFile errors
only when errors.Is(err, fs.ErrNotExist); retain all other read errors in
configParseWarnings so unreadable candidates are not reported as absent. Add a
test using a directory named models.yaml and verify the resulting warning
behavior.
- Around line 191-195: Update ModelUnificationConfig.isEffectivelyEmpty to
include every populated configuration collection, including FamilyAliases,
PublisherMappings, TypeCapabilities, ContextThresholds, and both SpecialRules
lists, so any configured section is treated as usable. Add a test covering a
configuration file containing only family_aliases and verify it is not replaced
by embedded defaults.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 49721cd1-6308-43cf-9b45-618e19b79359

📥 Commits

Reviewing files that changed from the base of the PR and between 7523a29 and 6f18508.

📒 Files selected for processing (4)
  • config/models.yaml
  • internal/adapter/unifier/factory.go
  • internal/adapter/unifier/model_config.go
  • internal/adapter/unifier/model_config_test.go

Comment on lines 75 to +88
// LoadModelConfig loads the model unification configuration
func LoadModelConfig() (*ModelUnificationConfig, error) {
configOnce.Do(func() {
configInstance = loadConfigFromFile()
configInstance, configSource, configParseWarnings = loadConfigFromFile()
if configInstance != nil {
errConfig = configInstance.compilePatterns()
}
})
return configInstance, errConfig
}

// loadConfigFromFile loads configuration from the YAML file
func loadConfigFromFile() *ModelUnificationConfig {
// ConfigSource returns the path models.yaml was loaded from, triggering the
// load if it hasn't happened yet. An empty string means embedded defaults
// are in use - check the returned warnings via LogConfigStatus to see why.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Document the reason for these entry points.

The comments repeat API behaviour. State why process-wide caching and on-demand loading are necessary.

As per coding guidelines, Go comments must explain "why", not "what".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/adapter/unifier/model_config.go` around lines 75 - 88, Update the Go
doc comments for LoadModelConfig and ConfigSource to explain why process-wide
caching via configOnce is required and why configuration loading is deferred
until an entry point is called. Retain the existing behavioral details only as
supporting context, while making the comments focus on the rationale.

Source: Coding guidelines

Comment on lines +116 to +119
if len(configParseWarnings) > 0 {
log.Warn("model unification config: found models.yaml but could not parse it, falling back to embedded defaults",
"details", strings.Join(configParseWarnings, "; "))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Report the actual warning cause and active source.

configParseWarnings also contains empty-file warnings, although the file parsed successfully. A later candidate can also set configSource, but this message still says embedded defaults are active.

Report an unusable candidate without claiming a parse failure or default fallback. Add coverage for an empty candidate and for a broken earlier candidate followed by a valid later candidate.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/adapter/unifier/model_config.go` around lines 116 - 119, Update the
warning logic around configParseWarnings and configSource to distinguish
empty-file warnings from parse failures and report the actual unusable candidate
cause. Use the final active configSource in the message instead of always
claiming embedded defaults, and add coverage for an empty candidate plus a
broken earlier candidate followed by a valid later candidate.

thushan added 4 commits August 5, 2026 11:26
The empty-file guard added in 6f18508 only checked family_patterns, name
patterns, quantization mappings and architecture mappings, so a valid
partial file that only set (say) family_aliases was wrongly treated as
empty and discarded. Now every top-level section counts.
If a candidate parsed as valid YAML but had a pattern that wasn't a valid
regex, LoadModelConfig handed back the uncompiled config alongside the
error, and getConfig() in metadata_extractor.go swapped in
getDefaultConfig() - which is never compiled either. Every regex-driven
lookup then silently no-opped instead of erroring or working. Now a
compile failure is recorded as a warning naming the source, and the
embedded defaults are built and compiled in its place.
The warning always said "falling back to embedded defaults", even when a
later candidate loaded fine and defaults were never touched. Reworded to
"found unusable models.yaml candidate(s)" and only claim the defaults
fallback when configSource is actually empty - otherwise name the source
that's really active.
os.ReadFile failing was always treated as "candidate doesn't exist" and
skipped without comment. That's right for the common case (most of the
search path is speculative) but wrong for a real problem like permission
denied or a directory named models.yaml - those got the same silence as
a file that was never there. Only fs.ErrNotExist is skipped silently now;
anything else is recorded as a warning.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/adapter/unifier/model_config_test.go (1)

276-277: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove or replace this helper comment.

Line 276 repeats the helper behaviour. Remove it, or state why diagnostics must name the unusable candidate.

As per coding guidelines, “Comment on why, not what. Concise and direct.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/adapter/unifier/model_config_test.go` around lines 276 - 277, Update
the comment above requireWarningNaming to remove the redundant description of
the helper’s behavior, or replace it with a concise rationale explaining why
diagnostics must identify the unusable candidate.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/adapter/unifier/model_config_test.go`:
- Around line 276-277: Update the comment above requireWarningNaming to remove
the redundant description of the helper’s behavior, or replace it with a concise
rationale explaining why diagnostics must identify the unusable candidate.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1707a3c7-5697-4672-9cc5-ea0298aec487

📥 Commits

Reviewing files that changed from the base of the PR and between 6f18508 and e276c79.

📒 Files selected for processing (2)
  • internal/adapter/unifier/model_config.go
  • internal/adapter/unifier/model_config_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/adapter/unifier/model_config.go

@thushan
thushan merged commit ee08930 into main Aug 5, 2026
5 checks passed
@thushan
thushan deleted the fix/issue-204-models-yaml-parse branch August 5, 2026 03:42
@coderabbitai coderabbitai Bot mentioned this pull request Aug 5, 2026
@thushan thushan mentioned this pull request Aug 5, 2026
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.

1 participant