Skip to content

🐛 fix(index): stamp model on serve/git-hook index path (worktree "model: unknown") - #168

Merged
flupkede merged 4 commits into
developfrom
fix/worktree-index-model-unknown
Jul 28, 2026
Merged

🐛 fix(index): stamp model on serve/git-hook index path (worktree "model: unknown")#168
flupkede merged 4 commits into
developfrom
fix/worktree-index-model-unknown

Conversation

@flupkede

Copy link
Copy Markdown
Owner

Summary

  • Fixes the model: unknown bug on indexes created via the serve / git-hook (POST /repos) path — git worktrees especially.
  • Root cause: ensure_schema_version pre-creates metadata.json with only schema_version (no model fields); force-reindex then saw the file existed and skipped stamping the default model. Readers showed model: unknown, and that sentinel disabled the empty-index live-chunk-count self-heal → a good worktree index looked empty and agents fell back to grep.
  • Consolidates the model→metadata stamp into a single ModelType::write_metadata_fields source of truth across all five index-creation sites, correcting a pre-existing drift (auto-create-DB path wrote the Debug variant name AllMiniLML6V2Q as model_name).

Changes

  • src/index/manager.rs — Fix A (force_reindex_with_stores: stamp default model when metadata lacks it) + Fix B (perform_incremental_refresh_with_stores: persist resolved model) + regression test.
  • src/embed/embedder.rs — new ModelType::write_metadata_fields helper (single source of truth).
  • src/index/mod.rs — CLI partial-cancel + final save routed through helper; dead capture block removed.
  • src/mcp/mod.rs — auto-create-DB stamp routed through helper (drift fixed).
  • src/embed/mod.rs#[allow(dead_code)] on now-unused model_name() accessor.
  • CHANGELOG.md[Unreleased] entry.

Testing

  • cargo fmt --check, cargo check --all-targets, cargo clippy --all-targets -D warnings
  • cargo test --lib — 596 passed, 20 ignored (pre-push QC gate)
  • New regression test force_reindex_stamps_model_when_metadata_has_only_schema_version
  • 3 reviewer passes → clean ✅ PASS

Note

Existing worktree indexes (e.g. HUSQ.Aprimo-209169) need one reindex to pick up the stamped model.

🤖 Generated with Claude Code

Test User and others added 4 commits July 28, 2026 13:43
Fixes the "model: unknown" worktree bug. When a repo is registered via
POST /repos (the git-hook path), the store is opened first and
ensure_schema_version pre-creates a metadata.json containing only
schema_version — no model fields. force_reindex's Step 0 then saw the
file already existed and skipped the default-model stamp, so the index
was left with no model_short_name. Every reader showed "model: unknown",
and read_model_metadata's "unknown" sentinel disabled the empty-index
live-chunk-count self-heal — making the worktree index look empty so the
agent fell back to grep.

Fix A (force_reindex_with_stores): when the preserved metadata.json has
no model_short_name, stamp ModelType::default() (short_name/name/dims)
before the merge write.

Fix B (perform_incremental_refresh_with_stores): persist the resolved
embed_model alongside the chunk/file stats so incremental refreshes also
keep the model recorded.

Both use ModelType::default() rather than hardcoded strings, mirroring
the working CLI index path (src/index/mod.rs). Adds a regression test
reproducing the schema-version-only bootstrap state.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…metadata_fields

Addresses reviewer Important remark on df1e504: the ModelType -> 3 JSON
fields (model_short_name/model_name/dimensions) block was duplicated
across four index-creation sites (force_reindex override + Fix A + Fix B,
and the CLI index_with_options save + final save). The keys and value
derivation could drift and the sites already differed in style
(obj.insert closures vs Value indexing).

Extracts a single source of truth, ModelType::write_metadata_fields(obj),
and routes all four sites through it:
- force_reindex_with_stores: model override + default-stamp (via as_object_mut)
- perform_incremental_refresh_with_stores: Fix B write
- index_with_options: partial-cancel save + final save

The CLI final-save previously captured model_{short_name,name,dimensions}
strings from embedding_service before dropping the ONNX model; since the
service is built directly from model_type (EmbeddingService::with_cache_dir),
those values are identical to model_type.*, so the capture block is removed
and model_type is used directly. EmbeddingService::model_name() thereby
loses its last caller and gets #[allow(dead_code)] to match the sibling
accessor convention in embed/mod.rs.

No behavior change: same keys, same values. cargo check/clippy/test green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…a_fields

Addresses reviewer Important remark on 50c9397: the create-minimal-DB
path in serve (src/mcp/mod.rs) was a 5th, un-consolidated copy of the
three-key model stamp — and it had drifted, writing model_name as the
Debug variant name (format!("{:?}", model_type) → "AllMiniLML6V2Q")
instead of model_type.name() ("all-MiniLM-L6-v2-q") that every other
path writes. Display-only (readers key on model_short_name), so no
resolution defect, but it contradicted write_metadata_fields' own
"cannot drift" contract.

Routes this site through model_type.write_metadata_fields(obj) too, so
the helper's "every index-creation path" claim now holds literally and
model_name is consistent across all five sites. Drops the now-unused
local model_name; model_short_name/dimensions are still used below.

No functional change beyond correcting the drifted model_name value.
cargo check/clippy/test (mcp: 196, index: 21) green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add [Unreleased] CHANGELOG entry for the serve/git-hook "model: unknown"
worktree-index fix and the write_metadata_fields consolidation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@flupkede
flupkede merged commit 09b451a into develop Jul 28, 2026
2 checks passed
@flupkede
flupkede deleted the fix/worktree-index-model-unknown branch July 28, 2026 13:54
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