Skip to content

explore: commitParsedFileOwnedOutline can leave word_index and trigram_index diverged on OOM #252

@justrach

Description

@justrach

Problem

Explorer.commitParsedFileOwnedOutline updates word_index, trigram_index, and outlines in sequence with no atomic rollback. word_index.indexFile calls removeFile first (destructive) before building new entries. If trigram_index.indexFile subsequently fails with OOM, the indexes are left in a split state:

  • word_index: has the new content (removeFile + indexFile completed)
  • trigram_index: has the old content removed, new content never inserted
  • outlines: restored by errdefer to the previous outline

Results: content searches via word_index return results for the new file version, but trigram searches miss the file entirely.

// src/explore.zig — commitParsedFileOwnedOutline
try self.word_index.indexFile(stable_path, content);    // ← removes old first, succeeds
try self.trigram_index.indexFile(stable_path, content); // ← fails OOM: word and trigram now diverged

Fix

Either:

  • Re-index word_index on trigram failure (errdefer that re-runs word_index.indexFile with old content)
  • Or stage all mutations before committing: compute new trigrams and words without modifying indexes, then apply atomically under lock

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions