Skip to content

Report when the search index is not saved for size - #25

Open
Leo-Y-Zhang wants to merge 1 commit into
context-dot-dev:mainfrom
Leo-Y-Zhang:report-index-size-skip
Open

Leo-Y-Zhang wants to merge 1 commit into
context-dot-dev:mainfrom
Leo-Y-Zhang:report-index-size-skip

Conversation

@Leo-Y-Zhang

Copy link
Copy Markdown

Summary

When an index would exceed SGREP_CACHE_MAX_BYTES, build() in src/index.rs returned Ok(None) at either of its two size checks without any output. Every later query then rebuilt from scratch, and from the outside that looks exactly like a working cache (#20 measured 10-23 s per query against 0.1 s when the index fits).

Both exits now print one line on stderr through a small helper, in the style of the file's existing sgrep: could not ... messages:

sgrep: search index not saved: estimated 1043 bytes is over the 100-byte cache limit; set SGREP_CACHE_MAX_BYTES to raise it

The first check runs before embedding and uses the existing estimate, so its line says "estimated"; the second reports the serialized size. stdout and exit codes are unchanged, and nothing is printed when the index is saved, when the limit is 0, or with --no-cache.

sgrep --help now documents the variable:

Environment:
  SGREP_CACHE_MAX_BYTES  Size limit in bytes for the search index cache (default 256 MiB); 0 disables the index cache.

The README's cache section says the skip is reported on stderr.

Before and after

A git-initialised folder with one file, SGREP_CACHE_DIR=<fresh> SGREP_CACHE_MAX_BYTES=100 sgrep shipping <folder>:

stdout stderr exit cache dir
main a.txt:1-1 / shipping oldneedle (empty) 0 .sgrep-index.lock
this branch same bytes the line above 0 .sgrep-index.lock

Tests

New checks in tests/cache_lifecycle.py, using its record() pattern (plus a call_output() helper that also returns stderr and the exit code):

  • estimated size limit reports once on stderr and preserves stdout
  • serialized size limit reports once on stderr and preserves stdout (limit = saved index size - 1)
  • exact size limit saves index without notice (limit = saved index size)
  • default size limit saves index without notice
  • zero size limit emits no notice
  • no-cache emits no size notice
  • help documents index cache size limit

Against a binary built from main, the three checks that need the new behaviour fail (two on the missing notice, one on --help); the four guards pass on both. With the change, every check in the receipt is ok: true.

Gate (README "Development" block, clean rust:1-bookworm container)

  • cargo build --release --locked: ok; cargo fmt --check: clean
  • tests/cache_lifecycle.py: 15/15 checks ok (8 existing + 7 new)
  • tests/e2e.py: ok, 31 checks
  • tests/hybrid.py: ok, 25 checks
  • tests/cache.py --online: ok, 16 checks

Fixes #20 for asks (1) and (2). Ask (3), saving a partial index when the full one is over the cap, changes what the cache stores, so I've left it for a separate proposal.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Index silently not persisted when the serialized index exceeds SGREP_CACHE_MAX_BYTES (256 MiB default) — every later query rebuilds from scratch

1 participant