Skip to content

codegraph_index_markdown` overwrites previously indexed documents in v0.19.1 #16

Description

@finix7776

Environment

  • CodeGraph: 0.19.1
  • Build: ef6a466
  • Platform: macOS ARM64
  • Transport: MCP through a resident --serve engine and --connect client
  • Client: OpenAI Codex

Description

Indexing multiple Markdown files does not preserve all previously indexed
documents.

codegraph_index_markdown returns status: success, but after indexing another
file, previously indexed sources or chunks disappear from
codegraph_list_doc_sources and can no longer be found with
codegraph_search_docs.

The issue still occurs with only one resident CodeGraph engine and one connected
client. All VS Code CodeGraph processes were disabled before reproducing it.

Minimal reproduction

Create two files:

a.md

# Alpha

unique-alpha-marker

b.md

# Beta

unique-beta-marker

Then run:

  1. codegraph_index_markdown(path: "/tmp/a.md")
  2. codegraph_list_doc_sources()
  3. codegraph_index_markdown(path: "/tmp/b.md")
  4. codegraph_list_doc_sources()
  5. Search for both unique markers with codegraph_search_docs.

Actual behavior

After indexing the second file, sections belonging to the first file can
disappear.

The response also appears to generate chunk IDs starting again from
doc-0001 for every source. This may cause collisions between chunks from
different Markdown files.

Expected behavior

Indexing a new Markdown source should add its chunks without removing chunks
belonging to other sources.

Chunk identifiers should be unique across sources, for example by including a
source-path hash or another stable namespace.

Additional evidence

The server documentation says that re-indexing should replace data only for the
same source file. In this case, indexing a different source affects previously
indexed sources.

Activity

  1. anvanster commented on Aug 10, 2026

    @anvanster
    Member

    Fixed in v0.20.1.

    Your hypothesis was exactly right, including the cause you suggested: chunk ids restarted at doc-0001 for every source and collided.

    Root cause

    parse_markdown initialised its counter per call, so every document minted doc-0001, doc-0002, and so on. That id is simultaneously:

    • the RocksDB key (doc:{id} and docvec:{id}),
    • the in-memory chunk cache key,
    • the HNSW point id,

    all of which are a single global namespace. So indexing b.md wrote straight over a.md's chunks, and a.md disappeared from codegraph_list_doc_sources and codegraph_search_docs while indexing still reported status: success.

    One detail worth adding to your report, because it explains the "can disappear" you observed rather than consistent loss: the damage is partial and size-dependent. A 3-chunk file overwrites only the first 3 chunks of a 10-chunk file, and the 7 survivors then make the next remove_source look like it did its job. Re-indexing the larger file afterwards wipes the smaller one entirely.

    Fix

    Chunk ids are now namespaced by the source path:

    doc-{fnv1a(source_file):016x}-{counter:04}
    

    FNV-1a rather than the standard library hasher because the value is written into a persisted key, and DefaultHasher's output is explicitly not stable across Rust releases, which would orphan every chunk on disk after a toolchain upgrade.

    Verified end to end with your exact reproduction against a real engine. Before: two files left list_doc_sources reporting 1 source. After: 2 sources, re-indexing the first no longer wipes the second, and both unique-alpha-marker and unique-beta-marker are findable. There is now a regression test for the store-level behaviour as well as the id generation.

    Existing indexes need re-indexing

    Upgrading does not repair data already lost, because the overwrite happened on disk. Old and new ids have different shapes, so they coexist safely and no migration is needed, but any source that was clobbered stays missing until it is indexed again.

    After upgrading, re-run codegraph_index_markdown once per source:

    codegraph_index_markdown(path: "/path/to/a.md")
    codegraph_index_markdown(path: "/path/to/b.md")
    

    Then codegraph_list_doc_sources should report every source, and both should be searchable.

    Thanks for the report. The minimal reproduction and the chunk-id observation pointed straight at the defect.

    Please reopen if anything is still missing after a re-index on 0.20.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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