Skip to content

desktop: vault_info loads the real model on every call — its "model-free read" comment is wrong #133

Description

@samkeen

Found during the pure-refactor pass on claude/rust-codebase-refactor-7ot3v1; deliberately not fixed there because the fix is a behavior decision, not a refactor.

What the code says vs. what it does

vault_info_impl (crates/b2-desktop/src/commands.rs) documents itself as a model-free read — "the real model is never loaded here." But it calls crate::semantic_available() (crates/b2-desktop/src/main.rs), and that calls LocalEmbedder::load — which parses config.json, builds the tokenizer, mmaps model.safetensors, and constructs a full BertModel (crates/b2-embed/src/model.rs).

So vault_info pays a full model load on every call, and it sits on the first-paint path — exactly the path the project/embed split (index-engine.md) exists to keep model-free. The comment is load-bearing and currently says the opposite of what happens, which is why the surrounding code shouldn't be refactored around until this is settled.

Options (each changes observable behavior somewhere)

  1. Probe files, don't loadsemantic_available uses EmbedConfig::is_model_provisioned / b2_embed::model::files_present (the one "installed" check after the refactor) instead of a full load. Cheap and honest for the common case, but a present-but-corrupt model would report semantic: true and only fail later at reindex/search. That failure is already fail-fast and actionable, so this may be acceptable.
  2. Cache the probe — keep the full-load check but do it once (e.g. OnceLock), invalidated when the configured model changes. Keeps the "loadable, not just present" guarantee; adds cache-staleness rules (a model provisioned mid-session should flip the flag).
  3. Reuse what the call already knowsvault_info_impl opens the vault read-path; the semantic answer the UI actually needs may be derivable from embed_status + the recorded embedder without probing the model at all.

Whichever way it lands, the doc comment on vault_info_impl needs to match the implementation again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions