sgm-index on a mistyped or empty folder overwrites the existing index with an empty one and exits 0
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 78/100
Research direction
Start with build_index and main in src/sqlite_graph_memory/index_notes.py, then read check_index in src/sqlite_graph_memory/doctor.py. Run the focused tests in tests/test_incremental_index.py and tests/test_doctor.py; they use a fake encoder. Done when missing or empty note folders preserve a valid index and exit non-zero, zero-chunk runs can be followed by a normal run, and doctor flags a zero-row index.
Written by the indexing model from the issue text.
Description
What happens
If sgm-index finds no indexable notes, it still writes the index files. An existing good index is replaced by an empty one, and the exit code is 0.
Reproduction on a clone of master (0.3.9, Windows 11, Python 3.12, [lite] backend), with BRAIN_INDEX_DIR pointing at a fresh folder and the 202-note bench/vault copied to ./notes:
$ sgm-index ./notes
indexed 204 chunks from 202 files -> <index folder>
$ ls -la <index folder>
626816 _brain_e5.npy
93762 _brain_e5_meta.pkl
$ sgm-index ./notez # typo, folder does not exist
no indexable .md notes found under notez
$ echo $?
0
$ ls -la <index folder>
128 _brain_e5.npy
171 _brain_e5_manifest.json
5 _brain_e5_meta.pkl
$ sgm-ask "ouzel"
0 hits (scope=all) -> _brain_answer.txt
$ echo $?
0
The 626 KB index is gone and has to be re-embedded from scratch. The same happens with an existing folder that contains no .md files: _brain_e5.npy goes from 626816 to 128 bytes, exit code 0.
In code: build_index() in src/sqlite_graph_memory/index_notes.py never checks that notes_dir exists (iter_notes uses rglob, which returns nothing for a missing folder), and lines 248-251 write _brain_e5.npy, the meta pickle and the manifest unconditionally. main() prints the "no indexable" line at 269-270 and returns normally.
Three follow-on symptoms on the resulting empty index:
sgm-doctorreports[ok] Index Index found in <folder> (0.0 MB).and ends withAll good., exit code 0.- When the empty index comes from a first run (no previous index, so line 246 writes shape
(0, 0)),sgm-askstops with a traceback:ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0 ... (size 768 is different from 0)fromquery_sims(brain_ask.py:261). - After such a first run, adding a valid note and running
sgm-index ./notesagain also stops with a traceback:ValueError: all the input array dimensions except for the concatenation axis must match exactly ... the array at index 0 has size 0 and the array at index 1 has size 768, raised frombuild_indexatindex_notes.py:240.sgm-index --full ./notesgets out of it.
Why it matters
One typo in the path, or an unmounted drive, silently destroys an index that can take a long time to build on a large vault. Because the exit code is 0, a scheduled re-index or an agent following the README cannot notice. After that, recall returns nothing and the health check says everything is fine.
Suggested approach
- In
main()(or at the top ofbuild_index): ifnotes_diris not an existing directory, print one line to stderr and exit 1 before touching the index folder. - In
build_index: when the run would produce zero chunks, do not overwrite an existing non-empty index and do not write a(0, 0)array. Return the zero result and letmain()exit non-zero with a message that says the existing index was kept. - In
sgm-doctorcheck_index: treat an index with zero rows as a failure with the hintRebuild it: sgm-index /path/to/your/notes(the 0-byte file case is already handled there). - Optional, same PR or a follow-up: make
sgm-askprint one line instead of a traceback on a zero-row index.
Done when
sgm-index ./does-not-existexits non-zero, prints a clear message on stderr, and leaves the files inBRAIN_INDEX_DIRbyte-for-byte unchanged.sgm-indexon an existing folder with no.mdfiles does not replace a non-empty index.- A zero-chunk first run followed by a normal run does not crash.
- New tests in
tests/test_incremental_index.py(they already inject a fake encoder, so no model is needed) cover these cases and fail on current master. - A test in
tests/test_doctor.pyasserts that a zero-row index is not reported as OK. python -m pytest -qshows no new failures.
Where to start
src/sqlite_graph_memory/index_notes.py:build_index(ends at line 254) andmain(from line 257)src/sqlite_graph_memory/doctor.py:check_index(from line 121)tests/test_incremental_index.py,tests/test_doctor.py
New here? Comment that you are taking it and ask anything in this thread; small PRs are reviewed within a day.
- Dominant language
- Python
- Stars
- 9
- Forks
- 6
- Avg merge
- 13h 8m
- Merged PRs (30d)
- 40
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tonydzi/sqlite-graph-memory
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
tonydzi/sqlite-graph-memory#133 · 1 comment ·
Maintainers usually reply within 1 day
-
bug documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
tonydzi/sqlite-graph-memory#131 ·
Maintainers usually reply within 1 day
-
bug help wanted
Difficulty 4/5 3-5 days Newbie friendliness 56/100
tonydzi/sqlite-graph-memory#132 ·
Maintainers usually reply within 1 day
-
bug help wanted
Difficulty 4/5 3-5 days Newbie friendliness 45/100
tonydzi/sqlite-graph-memory#126 ·
Maintainers usually reply within 1 day
-
bug help wanted
Difficulty 4/5 3-5 days Newbie friendliness 48/100
tonydzi/sqlite-graph-memory#125 ·
Maintainers usually reply within 1 day
All issues in tonydzi/sqlite-graph-memory
Similar issues
-
review-panel severity:low
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kristovatlas/coin-accounting#576 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 78/100
anthropics/skills#2328 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
repo-harnesses: the entrypoint-guard check greps a message `#13692` reworded, so it fails on mainOpen
Difficulty 1/5 Under an hour Newbie friendliness 88/100
daniel-ospina/tortoise#14947 ·
Maintainers usually reply within 1 day
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 82/100