Skip to content

fix(core): the active model keeps its LoRA across a restart; ModelFileType.gguf - #649

Merged
DenisovAV merged 4 commits into
mainfrom
fix/core-lora-restore-gguf
Oct 12, 2026
Merged

DenisovAV merged 4 commits into
mainfrom
fix/core-lora-restore-gguf

Conversation

@DenisovAV

@DenisovAV DenisovAV commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Two core gaps that #628 (llama.cpp through llamadart) has to work around today.

The active model keeps its LoRA across a restart

The persisted active identity named the model file only. After a restart core restored the model without its LoRA: it loaded with no adapter and no error, and a connector that reads spec.loraSource found none. #628 documents it: "Core does not persist the inference LoRA companion in its restart identity".

Mobile and web now persist the LoRA's filename and encoded source next to the model's (PreferencesKeys.activeInferenceLoraFilename / activeInferenceLoraSource, in the same one-key identity record) and restore it as loraSource. A LoRA whose file is gone restores nothing, the way a missing model file does, rather than the model without it. Identities written before this carry no LoRA field and restore as they did.

ModelFileType.gguf

A GGUF had to be declared as binary, which MediaPipe also claims at priority 0, so registration order decided which engine loaded it, and the connector told it apart by the file name. With gguf an engine is chosen by the declared type alone, as every other one is; MediaPipe does not claim it.

  • Chat template: raw, like litertlm and onnx — llama.cpp applies the template stored in the file.
  • Reply cleaning: as for binary. llama.cpp stops before the end-of-turn token, but a template that renders it as text must not reach the user, and binary is what the connector gets today.
  • .gguf joins FileNameUtils.supportedExtensions (found by Codex): without it the storage scan behind getStorageInfo, getOrphanedFiles and cleanupStorage filtered GGUF files out, so a multi-GB model went uncounted and an orphaned one could not be reclaimed.
  • That list also gives a model its base name, which prefixes its LoRA's file name: a GGUF's LoRA is now model__adapter.gguf, not model.gguf__adapter.gguf. Only the unpublished connector in feat: add llama.cpp inference through llamadart #628 installs GGUF with a LoRA today.
  • Adding an enum value breaks an exhaustive switch over ModelFileType in an app; nothing in this repo has one.

AGENTS.md, docs/models.md and docs/packages.md list it.

Tests

  • file_source_restore_test.dart: a model installed with a LoRA has it after a restart, with the same file names and paths, and is installed; a model whose LoRA file is gone restores nothing; a model without one restores without one. 41/41.
  • web_identity_write_atomicity_test.dart (Chrome): the same two cases after a page reload. 19/19. CI does not run browser tests.
  • gguf_file_type_test.dart: raw prompt for five families, systemInfo dropped, the tool-response wrapper kept; reply trimmed, a trailing <end_of_turn> / <|im_end|> stripped, a marker mid-text kept. 10/10.
  • getStorageInfo counts a .gguf file in core's directory; file_name_utils_test.dart covers the extension.
  • Mutation-checked: not persisting the LoRA, not restoring it, restoring the model without it (mobile and web), a non-raw template for gguf, trim-only cleaning, and dropping .gguf from the extensions each turn a test red.
  • Core: 1043/1043.
  • flutter analyze packages/: 0 errors, 0 warnings. dart tool/check_skills.dart and skills_lint: clean.
  • tool/test_all.sh: all packages pass; flutter_edge_ai_onnx and flutter_edge_ai_speech failed once in the full run under load and pass on their own (144/144, 308/308) — the worker-test flakiness test: worker tests survive CPU load — no fsync in fake logs, clock-free notice tests, bounded reset test #644 addresses.

The persisted identity named the model file only, so a restart restored
the model without its LoRA: it loaded with no adapter and no error, and
a connector reading spec.loraSource (llama.cpp, #628) found none.

Mobile and web now persist the LoRA's filename and source with the
model and restore it as loraSource. A LoRA whose file is gone restores
nothing, the way a missing model file does, rather than the model
without it. Identities written before this have no LoRA field and
restore as before.
A GGUF had to be declared as binary, which MediaPipe also claims at the
same priority, so registration order decided which engine loaded it,
and an engine could tell it apart only by the file name. Every other
engine is selected by its declared file type alone.

gguf: the chat template is the file's own (llama.cpp applies it), so
transformToChatPrompt passes messages through raw; replies are cleaned
as a binary's are, so a trailing end-of-turn marker a template renders
as text is stripped. MediaPipe does not claim it.
…aims GGUF files

Without it the storage scan behind getStorageInfo, getOrphanedFiles and cleanupStorage filtered GGUF files out: a multi-GB model went uncounted and an orphaned one could not be reclaimed. Found by Codex.
@DenisovAV
DenisovAV merged commit 63fd82e into main Oct 12, 2026
12 of 13 checks passed
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