Skip to content

feat(runtime): incremental Merkle workspace index for run-snapshot change detection - #191

Merged
lg2m merged 1 commit into
devin/1790293834-k2-workspace-indexfrom
feat/workspace-index
Sep 25, 2026
Merged

lg2m merged 1 commit into
devin/1790293834-k2-workspace-indexfrom
feat/workspace-index

Conversation

@lg2m

@lg2m lg2m commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #172 (base is its head branch; retarget to main once #172 merges).

What

qq_core::WorkspaceIndex (crates/qq-core/src/workspace/index.rs): a Merkle index over the same contained, ignore-aware walker search/tree use, reworked from the index in #172. It is the change-detection primitive docs/plans/run-snapshots.md § Change Detection needs for the shadow store's dirty scan. Not a tool; no protocol change; no new dependencies.

  • build hashes every admitted file (SHA-256) and every directory over its children (kind\0name\0digest\n under a versioned tag). Names, not paths, so a moved subtree keeps its hash.
  • refresh(&previous) reuses a file's hash when size and mtime are unchanged and the mtime is strictly older than the previous walk (git's same-tick guard). A checkpoint on a quiet tree is a walk with zero reads.
  • diff merges two complete indexes into sorted added/modified/deleted.
  • A budget-stopped build is IndexOutcome::Partial: no root_hash, cannot be diffed. Completeness is in the type, not a flag.
  • Hashes are qq_protocol::ContentHash (32 bytes), not hex Strings.
  • EntryKind::File gains modified, read from the metadata() call the walker already makes.

Changes from the #172 version

Dropped: per-file line chunking (no consumer; tool-layer.md Non-Goals excludes a persistent search index), root_hash on partial builds, hex-string hashes, pub ListError. Added: incremental refresh, name-based directory hashing (the original comment claimed this; the code hashed full paths), moved to workspace/. Pinned fixture root hash recomputed independently in Python.

Measured

cargo bench -p qq-core --bench workspace_index, 10k files / 17.6 MB, 20 iterations × 3 runs, back to back on one machine:

#172 original this PR
build_10k 52.0 ms 26.1 ms
diff_10k_one_modified 73 µs 35 µs
refresh_10k_quiet — 6.8 ms (reused=10000 bytes_read=0)
refresh_10k_one_edit — 7.3 ms

search_walk unchanged within noise (the modified field costs no extra syscall).

Verification

cargo fmt --check, cargo clippy --workspace --all-targets --all-features -D warnings, cargo test --workspace (1895 passed). 10 focused tests: pinned root, ancestor propagation, moved subtree, sorted diff, .qqignore, refresh reuse / same-size change / racy mtime / no mtime, refresh across adds and deletes, partial on each budget axis, symlinks never followed, missing root.

Notes

  • No in-tree consumer yet beyond the bench; the shadow store (run-snapshots step 2) is the first. Fine to park if you'd rather not carry it until then.
  • No Linear issue exists for this work.
  • Ledger: docs/plans/progress/tool-layer.md 2026-09-25 entry.

…ange detection

Adds qq_core::WorkspaceIndex (workspace/index.rs) over the search/tree
walker: build hashes every admitted file and directory; refresh against a
previous index reuses a file's hash when size and mtime are unchanged and
the mtime is strictly older than the previous walk, so a checkpoint on a
quiet tree is a walk with no reads; diff yields sorted added/modified/
deleted paths. A budget-stopped build is IndexOutcome::Partial, which has
no root hash and cannot be diffed. Hashes are qq_protocol::ContentHash;
directory hashes cover child names so a moved subtree keeps its hash.

Reworked from the contribution in #172: chunking dropped (no consumer),
hex-String hashes replaced, partial root hash removed, incremental refresh
added. EntryKind::File gains modified from the metadata call the walker
already makes; search_walk is unchanged within noise.

Bench workspace_index, 10k files / 17.6 MB, original -> reworked:
build 52.0 -> 26.1 ms; diff 73 -> 35 us; refresh_quiet 6.8 ms with every
hash reused; refresh_one_edit 7.3 ms.

Co-Authored-By: romy <[email protected]>
@lg2m
lg2m added this pull request to stack #192 September 25, 2026 21:20
@lg2m
lg2m merged commit ac28bf2 into main Sep 25, 2026
@lg2m
lg2m deleted the feat/workspace-index branch September 25, 2026 21:29
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