fix: /api/diagnostics 500 « dictionary changed size during iteration » — snapshot des dicts avant itération BUG-079
CI / lint (push) Successful in 2m3s
CI / security (push) Successful in 1m27s
CI / test (push) Successful in 4m22s
CI / build (push) Successful in 1m22s
CI / e2e (push) Successful in 13m36s

This commit is contained in:
2026-09-24 17:13:40 -04:00
parent 943005328c
commit e20fd6bf97
12 changed files with 67 additions and 16 deletions
+6 -3
View File
@@ -4231,7 +4231,9 @@ async def api_diagnostics(current_user=Depends(require_admin)):
vault_stats = {}
total_files = 0
total_tags = 0
for vname, vdata in index.items():
# Snapshot both dicts first: the indexer mutates them from background
# threads, and iterating a live dict raises "dictionary changed size".
for vname, vdata in list(index.items()):
file_count = len(vdata.get("files", []))
tag_count = len(vdata.get("tags", {}))
vault_stats[vname] = {"file_count": file_count, "tag_count": tag_count}
@@ -4239,7 +4241,8 @@ async def api_diagnostics(current_user=Depends(require_admin)):
total_tags += tag_count
# Memory estimate for inverted index
word_index_entries = sum(len(docs) for docs in inv.word_index.values())
word_index = inv.word_index.copy()
word_index_entries = sum(len(docs) for docs in word_index.values())
mem_estimate_mb = round(
(sys.getsizeof(inv.word_index) + word_index_entries * 80
+ len(inv.doc_info) * 200
@@ -4253,7 +4256,7 @@ async def api_diagnostics(current_user=Depends(require_admin)):
"vaults": vault_stats,
},
"inverted_index": {
"unique_tokens": len(inv.word_index),
"unique_tokens": len(word_index),
"total_postings": word_index_entries,
"documents": inv.doc_count,
"sorted_tokens": len(inv._sorted_tokens),