Skip to content

Persist project-cache snapshot after CLI indexing#343

Merged
justrach merged 1 commit intorelease/0.2.579from
fix/mcp-project-cache-after-cli
Apr 27, 2026
Merged

Persist project-cache snapshot after CLI indexing#343
justrach merged 1 commit intorelease/0.2.579from
fix/mcp-project-cache-after-cli

Conversation

@justrach
Copy link
Copy Markdown
Owner

Summary

  • persist a central ~/.codedb/projects/<hash>/codedb.snapshot after normal CLI scans
  • keep repo roots clean: codedb /path tree does not create /path/codedb.snapshot
  • reuse the central snapshot writer from snapshot mode and truncate project.txt when refreshing
  • add regression coverage for ProjectCache loading a project from the central snapshot cache only

Why

codedb /path tree printed indexed, but a later MCP call with project=/path failed with SnapshotLoadFailed because only side indexes were persisted. After this change, CLI indexing and MCP project loading agree on the cache contract.

Validation

  • zig build test
  • zig build -Doptimize=ReleaseFast
  • smoke: fresh throwaway project, run codedb /path tree, verify no root snapshot, verify central snapshot exists, verify MCP codedb_tree, codedb_symbol, and codedb_status load project=/path

@github-actions
Copy link
Copy Markdown

Benchmark Regression Report

Thresholds: 10.00% and 50,000 ns absolute delta

NOISE means the percentage threshold was exceeded, but the absolute delta was too small to fail CI.

Tool Base (ns) Head (ns) Delta Abs Delta (ns) Status
codedb_bundle 493620 494893 +0.26% +1273 OK
codedb_changes 54438 52571 -3.43% -1867 OK
codedb_deps 8582 8602 +0.23% +20 OK
codedb_edit 5432 6379 +17.43% +947 NOISE
codedb_find 61958 60986 -1.57% -972 OK
codedb_hot 97144 98321 +1.21% +1177 OK
codedb_outline 262401 264858 +0.94% +2457 OK
codedb_read 87879 87649 -0.26% -230 OK
codedb_search 175079 176923 +1.05% +1844 OK
codedb_snapshot 245951 259044 +5.32% +13093 OK
codedb_status 214900 214953 +0.02% +53 OK
codedb_symbol 59804 59691 -0.19% -113 OK
codedb_tree 43825 42190 -3.73% -1635 OK
codedb_word 70207 67968 -3.19% -2239 OK

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9500977377

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main.zig
Comment on lines +337 to +339
if (!std.mem.eql(u8, cmd, "snapshot")) {
snapshot_mod.writeProjectCacheSnapshot(io, &explorer, abs_root, allocator) catch |err| {
std.log.warn("could not persist project-cache snapshot: {}", .{err});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid blocking CLI scans on full project-cache snapshot write

This new unconditional call runs after every non-snapshot cold scan, so commands like tree and search now synchronously generate a full snapshot before returning. On larger repos (especially once in-memory content caching is exceeded), writeSnapshot re-reads uncached files from disk while writing the CONTENT section, effectively adding a second filesystem pass and causing a significant regression on the benchmark-critical indexing path (likely above the 10% threshold). Consider persisting this cache asynchronously or gating it so normal CLI scans do not pay full snapshot-write cost.

Useful? React with 👍 / 👎.

@justrach justrach merged commit c2779f3 into release/0.2.579 Apr 27, 2026
1 check passed
@justrach justrach deleted the fix/mcp-project-cache-after-cli branch April 27, 2026 09:11
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.

1 participant