You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add load-time SHA-256 integrity gate for the chat/LLM model (companion to embedding gate) #1729
The embedding model now has a load-time SHA-256 integrity gate (ADR-058): EmbeddingService::initialize() verifies the on-disk GGUF against a pinned digest before handing it to native llama.cpp. The chat/LLM model has no equivalent load-time gate.
packages/nlp-engine/src/chat/mod.rs (~L202) — load_model takes a caller-supplied path and only does an exists() check before LlamaModel::load_from_file. No digest comparison.
The chat models are verified at download time (packages/agent/src/local_agent/model_manager.rs pins per-entry SHA-256 and stream-verifies), so the fetch path is sound. But a model swapped/tampered on disk after download is loaded without re-verification — the same post-install tamper window that the embedding load gate closes.
The chat model is parsed by the same native C++ (llama.cpp) inside the daemon with full authority, so an on-disk-substituted GGUF is both an integrity failure and a memory-safety attack surface.
Why separate from the embedding gate
The embedding model is a single pinned artifact (one digest). The chat models are a catalog (MODEL_CATALOG in model_manager.rs, each with its own pinned sha256), and the loaded model is selected at runtime. A load-time gate must look up the expected digest for the currently selected catalog entry and verify against it before load_from_file.
Acceptance criteria
Before LlamaModel::load_from_file in chat/mod.rs, verify the on-disk file against the pinned SHA-256 of the selected catalog entry (reuse the digests already in model_manager.rs)
Refuse to load on mismatch with a clear integrity error (mirror EmbeddingError::IntegrityError)
Handle models with no catalog entry / user-supplied paths explicitly (fail closed or documented escape hatch)
Context
Surfaced during review of the embedding-model load gate. Threat T9, ADR-058 (Model Artifact Integrity Verification), security-posture.md.
The chat/LLM model now has the same load-time SHA-256 integrity gate as the embedding model. Before native llama.cpp parses the GGUF, the on-disk file is verified against the pinned digest of the selected catalog entry; a swapped/tampered model is refused with ChatError::IntegrityError.
chat/mod.rs — load_model(path, expected_sha256: Option<&str>) verifies before load_from_file (mirrors the embedding gate). None = documented escape hatch for a user-supplied / non-catalog model (loads with a warning — nothing to verify against).
config.rs — extracted a generic, case-insensitiveverify_file_sha256(path, expected); verify_model_integrity delegates to it.
agent/model_manager.rs — expected_sha256_for_filename resolves the pinned digest from the catalog by GGUF basename; agent/inference.rs resolves it at load and passes it down, preserving the agent → nlp-engine dependency direction.
Verification
Four tests (digest match/mismatch; catalog-filename → digest / None; a wiring-invariant test that every catalog basename resolves to its pinned digest; and load_model → IntegrityError on mismatch before native load). nlp-engine 99 / agent 301 lib tests pass; clippy clean; full pre-push gate green. Independent adversarial review: no bypass / correctness bug / regression — the only production chat-load path always builds the path from entry.filename, so a catalog model always resolves Some(digest) and is verified; the daemon surface takes a model_id (never an arbitrary path), so the None branch is unreachable today.
Companion to the embedding-model load gate (#1715); Threat T9, ADR-058.
Activity
mstomar125 commentedon Jul 27, 2026
Resolved in #1749 (merged to
mainase4893537).What shipped
The chat/LLM model now has the same load-time SHA-256 integrity gate as the embedding model. Before native llama.cpp parses the GGUF, the on-disk file is verified against the pinned digest of the selected catalog entry; a swapped/tampered model is refused with
ChatError::IntegrityError.chat/mod.rs—load_model(path, expected_sha256: Option<&str>)verifies beforeload_from_file(mirrors the embedding gate).None= documented escape hatch for a user-supplied / non-catalog model (loads with a warning — nothing to verify against).config.rs— extracted a generic, case-insensitiveverify_file_sha256(path, expected);verify_model_integritydelegates to it.agent/model_manager.rs—expected_sha256_for_filenameresolves the pinned digest from the catalog by GGUF basename;agent/inference.rsresolves it at load and passes it down, preserving theagent → nlp-enginedependency direction.Verification
Four tests (digest match/mismatch; catalog-filename → digest /
None; a wiring-invariant test that every catalog basename resolves to its pinned digest; andload_model→IntegrityErroron mismatch before native load). nlp-engine 99 / agent 301 lib tests pass; clippy clean; full pre-push gate green. Independent adversarial review: no bypass / correctness bug / regression — the only production chat-load path always builds the path fromentry.filename, so a catalog model always resolvesSome(digest)and is verified; the daemon surface takes amodel_id(never an arbitrary path), so theNonebranch is unreachable today.Companion to the embedding-model load gate (#1715); Threat T9, ADR-058.