codescout icon indicating copy to clipboard operation
codescout copied to clipboard

SQLite semantic memory store stays pinned to initial root after workspace switch; verifier recommends unnecessary migration

Open mic-urs opened this issue 1 month ago • 0 comments

What happened

With the sqlite-vec backend, semantic memory retrieval stays attached to the initial project root after targeting or activating a different project. File-based memory reads use the requested project, but memory(recall) returns no results and index(verify) incorrectly recommends memory migration.

Starting the same binary and local embedding model directly at the target root immediately recovers the existing memories. No migration, memory write, or vector rebuild was performed between these observations.

This report describes an observed run with identifying details replaced by placeholders. No raw logs, database files, memory contents, real paths, project/topic names, queries, or record/session identifiers are attached.

Expected behavior

workspace=<TARGET> should select both the project namespace and the corresponding SQLite memory storage for that call. After workspace(activate, path=<TARGET>), subsequent unpinned memory calls should use that target's store.

The verifier should inspect the intended target store and distinguish a routing problem from missing data. It should not recommend migration when that store already contains all structured memories and their vectors.

Steps to reproduce

Use an existing target project with known structured memories and a known successful recall query. The placeholders below represent the redacted values from the observed run, not a separately executed synthetic fixture.

  1. Start the MCP server with codescout start --project <PARENT>, where <TARGET> is a separate project below that directory.
  2. Call memory(action="list", workspace=<TARGET>) and memory(action="read", topic=<EXISTING_TOPIC>, workspace=<TARGET>). Both find the target's on-disk memories.
  3. Call memory(action="recall", query=<KNOWN_QUERY>, workspace=<TARGET>, project_id=<PROJECT_ID>, limit=3). Observed: count=0.
  4. Call index(action="verify", workspace=<TARGET>). Observed: 19 topics on disk, zero in the semantic store, and advice to run codescout migrate-memories --in-place.
  5. Activate the target using workspace(action="activate", path=<TARGET>, read_only=false). Activation succeeds and reports the correct target root. Repeat recall and verification without the workspace override: the same empty recall and incorrect memory counts persist.
  6. Inspect the server's open file descriptors. The open memory database is still <PARENT>/.codescout/embeddings/<PROJECT_ID>.memories.db, rather than the target's corresponding database.
  7. Start a separate temporary MCP process with the same binary/model using codescout start --project <TARGET>. Repeat the same known queries and verification. Recall now returns the expected memories, and verification reports all 19 structured topics present.

No activation protection was bypassed, and no database repair SQL was used.

Evidence

Read-only inspection of the actual target memory database found:

  • 23 memory_item records belonging to the target project: 19 structured, 1 preferences, and 3 unstructured.
  • 23 memory_vec_rowids, with zero missing vector identifiers and zero orphan identifiers.
  • A FLOAT[384] vector schema, matching the configured 384-dimensional local model.
  • PRAGMA integrity_check returning ok.
  • The source memory database remaining byte-identical throughout the investigation; its records and vector shadow tables also matched the coherent backup.
Observation Server initially rooted at parent, including after activation Same binary/model started directly at target
Direct topic reads Succeed Succeed
Known-query recall, limit 3 0 results 3 results; expected topic ranked first
Structured topics reported in store 0 of 19 19 of 19

Two distinct known queries produced the same before/after pattern. This supports a storage-routing problem, rather than absent data or incompatible vector dimensions.

After the separate code index was brought fully up to date, the affected parent-rooted process also produced this contradictory verification summary:

{
  "verdict": "complete",
  "memories": {
    "on_disk": 19,
    "in_store": 0,
    "missing_count": 19
  }
}

It still recommended migration. The target-rooted process instead reported in_store=19 and missing_count=0. The aggregate complete verdict should not obscure the memory-store discrepancy.

Suspected implementation seam

Inspection of the local source suggests:

  • src/agent/mod.rs, Agent::semantic_memory_store: a single self.semantic_memory.get_or_try_init(...) caches a store whose SQLite directory is derived from self.project_root().
  • src/tools/memory/mod.rs, the Memory::call recall branch: the project namespace is resolved through with_project_at(workspace_override), while the store comes from semantic_memory_store() without a per-call root.

Please check whether the cached store should be keyed by workspace/storage root, or otherwise resolved consistently for pinned calls and activation. The local source checkout was not proven identical to the installed binary, so this is a root-cause hypothesis; the runtime mismatch above is directly observed.

Suggested regression coverage: initialize the memory store under one root, then exercise both a pinned call to a second root and an activation to it. Use distinct existing stores, and assert that direct reads, recall, and verification all address the same target storage.

Environment

  • OS: Linux.
  • CodeScout version: 0.15.0.
  • Embedded build commit: 857c30c6, dirty build; build ID prefix 1d03a264fb19fd44.
  • MCP client: Codex, stdio transport.
  • Vector backend: sqlite-vec.
  • Embedding backend: local-onnx, existing local model, 384 dimensions; no remote embedder configured.
  • Rust version: not captured; tested an already installed binary.

Verified workaround

Start the CodeScout process directly at the intended project root before semantic memory access. In this observed build, workspace pinning and successful activation did not repair the already initialized store. Re-embedding or migrating the existing target memories was unnecessary.

mic-urs avatar Oct 27 '26 06:10 mic-urs