Skip to content

fix(pipeline): store the mtime of a file confirmed unchanged by hash - #502

Merged
HananKavitzAmat merged 7 commits into
chunkhound:mainfrom
fstrasz:fix/precheck-refresh-mtime-upstream
Nov 17, 2026
Merged

HananKavitzAmat merged 7 commits into
chunkhound:mainfrom
fstrasz:fix/precheck-refresh-mtime-upstream

Conversation

@fstrasz

@fstrasz fstrasz commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Updated after #500 merged. main is merged into this branch, so the diff is now this PR's change alone. #500's review moved the precheck into plan_rust_run / RustRunPlan. The refresh sits in the same place inside it: on Python's connection, before plan_rust_run returns, so before any handoff to Rust.

Problem

A file whose mtime differs from its stored modified_time, but whose xxh3_64 digest equals the stored content_hash, is classified as unchanged, and nothing is written. Its stored mtime therefore stays stale, so every later run hashes the same file again.

The common case is a fresh git checkout indexed from an existing index: every file has a new mtime and identical bytes. Each start then re-hashes the whole tree, and keeps doing so on every later start. That is the worktree case in #238 and #83: a new worktree seeded from another checkout's index pays this on every start.

Both Python classifiers have the gap:

  1. rust_incremental_precheck.classify_files (from fix(pipeline): an incremental run with nothing to write never takes the database from readers #500), which runs before every incremental, non-force Rust run, counts the file in skipped_by_hash and writes nothing.
  2. IndexingCoordinator.process_directory Phase 2.5, the Python pipeline's change scan, takes its "metadata changed but content didn't" branch and writes nothing.

The Rust differ has the same behaviour: it reuses the stored hash for such a file and never writes the new stat back.

Fix

A new provider method, refresh_file_mtimes(entries), with an async variant. Each entry is (stored path, current st_mtime, confirmed content_hash).

  1. It sets modified_time only, and only on rows whose content_hash still equals the confirmed hash. A concurrent writer that stored new content therefore never gets an older mtime attached to it.
  2. DuckDB does this in one statement, UPDATE files SET modified_time = to_timestamp(v.mtime) FROM (SELECT unnest(?) ...) v WHERE files.path = v.path AND files.content_hash = v.h. That is the same to_timestamp(?) form every other files writer uses, so both readers (the precheck's EXTRACT(EPOCH FROM modified_time::TIMESTAMPTZ) and Phase 2.5's datetime.timestamp()) read the value back exactly.
  3. LanceDB does it with one compare-and-swap merge, keyed on (path, content_hash, indexed_time) as read. Another process can index the same LanceDB database, because nothing locks the files table across connections. Every write of a file's content or skip state stamps a new indexed_time, so the merge matches only a row nobody has rewritten since it was read. It stores that row with the new modified_time and nothing else changed; a row rewritten in between keeps that writer's values. Lance 0.39 rejects a per-row value (CASE) in a conditional update, and fails a merge whose source has fewer columns than the table, so the merge carries the whole row as read.
  4. updated_at and skip_reason are left alone, because the content was confirmed, not re-indexed.

Both classifiers call it:

  1. The precheck refreshes the hash-confirmed files on Python's connection, before any handoff to Rust, so the write never races Rust's ownership of the file. Because the precheck runs before every incremental Rust run, the Rust differ also sees the refreshed mtime and takes its mtime fast path. No native change is needed.
  2. Phase 2.5 collects the same files and refreshes them in one call after the scan.

A failed refresh is logged as a warning and never fails the run. Its only cost is that the next run hashes the file again, which is today's behaviour. The Diff: and Change scan log lines now report N mtimes refreshed.

Measurement

Windows, a copy of a real 1,200-file DuckDB index, and a fresh checkout of the commit that index was built from (0 content changes). I ran chunkhound index three times in a row on the same copy.

Start Before After
1 1,200 files re-hashed, 16.9 s 1,200 re-hashed and 1,200 mtimes refreshed, 19.1 s
2 1,200 re-hashed, 16.9 s 0 re-hashed, 15.1 s
3 1,200 re-hashed, 17.0 s 0 re-hashed, 13.9 s

The log line goes from Diff: 0/1200 changed (1200 unchanged-by-hash) on every start to Diff: 0/1200 changed (0 unchanged-by-hash, 0 mtimes refreshed) from the second start on.

Tests

Two new tests in tests/contracts/test_rust_startup_reader_access.py, one per caller:

  1. Precheck: it indexes a repo, gives every file a new mtime with the same bytes, and runs the precheck twice.
    a. It asserts that run 1 confirms N files by hash and run 2 confirms 0.
    b. Before the fix it fails with assert 3 == 0, because run 2 still hashes every file.
  2. Python pipeline (CHUNKHOUND_USE_RUST=0): the same setup, running process_directory twice and counting hash computations.
    a. Run 1 must hash N files. That is a precondition, proving the "metadata changed" branch was reached. Run 2 must hash 0.
    b. Before the fix it fails with assert [3, 3] == [3, 0].

Removing either caller's refresh call makes only that caller's test fail.

  1. LanceDB under a concurrent writer, in tests/integration/test_lancedb_refresh_file_mtimes.py. Just before the refresh writes, a second connection rewrites one file's content and records another as skipped. Both rows keep that writer's values, and a third file gets only its new mtime. With the previous LanceDB write it fails: the rewritten content is rolled back.

On this branch, run serially on Windows: the contracts file, test_skip_unchanged_files, test_checksum_verify_flow, test_duckdb_compaction, test_lancedb_checksums, test_lancedb_skip_parity, test_lancedb_provider_helpers, test_rust_pipeline_lancedb_fallback and test_chunk_hashing. Result: 167 passed.

With the production files reset to #500's head, the two new tests fail as described above, and the two existing tests in the file pass.

After merging main, serially on Windows: tests/contracts 134 passed and 4 skipped (the platform-specific native-install and rpath tests); tests/test_smoke.py 14 passed. On the merged code, replacing the precheck's refresh call with refreshed = 0 again fails the precheck test with assert 3 == 0.

One test from #500 needed a change after the merge. test_precheck_agrees_with_the_rust_differ compares the precheck's verdict with the Rust differ's on the same rows. With the refresh, the precheck stores the new mtime first, so in its new-mtime-same-bytes case Rust took its mtime fast path and never compared hashes; a hash disagreement between the two would have passed. That test now takes the precheck's verdict with the refresh stubbed out. I checked it with a probe that makes the precheck's hash wrongly agree with a fake stored hash: with the refresh stubbed, the assert fails as it should; with the refresh live, it passed.

The tests ran against chunkhound-native 6.1.0, which main now requires (#499). Upstream's CI test matrix (Ubuntu, macOS, Windows) passed on the merged head on my fork before I pushed it here.

After the LanceDB fix, serially on Windows: every LanceDB test file, the contracts file, test_chunk_hashing, test_database_path_consistency and test_embedding_model_drift, 141 passed; tests/test_smoke.py 14 passed. Upstream's CI workflow on our fork at this head is green on every job: https://github.com/fstrasz/chunkhound/actions/runs/43264819556

I also checked the LanceDB method by hand on a scratch table, before the fix:

  1. An empty table returns 0.
  2. With 26 rows, every matching row is refreshed. The query sets .limit(len(paths)), because LanceDB returns 10 rows by default.
  3. A path containing ' is handled.
  4. A row whose hash does not match keeps its mtime.
  5. No column other than modified_time changes.

🤖 Generated with Claude Code, reviewed by FStrasz

fstrasz and others added 5 commits November 9, 2026 10:45
…he database from readers

Every incremental Rust run handed the database to Rust before Rust's own
diff ran: set_rust_pipeline_in_progress(True), close Python's connections,
run, reconnect. Every search in that window is refused with
DatabaseRustPipelineInProgressError. An MCP server's start-up catch-up does
this on every start, and the common start changes nothing -- a fresh
worktree seeded from another checkout's index has new mtimes and identical
bytes. Measured on a 1174-file index (real `chunkhound mcp`, regex search
every 2 s): a start with 0 content changes refused searches for 46 s, and
39 s on the next start. Rust spent ~1.5 s diffing and the rest opening the
file and compacting it on a run that wrote nothing.

process_directory() now decides on Python's own connection, before any
handoff, whether the Rust run has anything to write. The new
rust_incremental_precheck reads the same file-state columns as the Rust
differ's snapshot and classifies files by its rules (mtime, then xxh3_64
against the stored content_hash, then size), off the event loop:

- nothing changed or removed: Rust is not started; HNSW indexes a crashed
  run left missing are restored through the provider, as Rust's open()
  would have done;
- changes and no removals: Rust gets only the changed files with cleanup
  off, so its own diff no longer hashes the whole tree while it owns the
  file;
- removals: unchanged, the full list as before.

A file is called unchanged only when Rust would call it unchanged; a
matching hash means identical bytes. force_reindex is unchanged.

An otherwise-empty run no longer gives Rust a chance to compact. Python-side
writes are still compacted by the provider's sampled compact_if_needed, and
Rust still checks after every run that writes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sh; guard the narrowed run

compute_file_hash raises ValueError for a path that stopped being a regular file after stat(); count that file as changed, as Rust does, instead of failing the scan. The docstring now states the unchanged rule exactly.

New contract test: editing one file with nothing removed reindexes it and keeps every other file. It guards the cleanup-off requirement of the narrowed Rust run; removing that line deletes the unedited rows and fails the test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A file whose mtime differs from its stored modified_time but whose xxh3_64
equals the stored content_hash was classified unchanged and nothing was
written. The stored mtime stayed stale, so every later run hashed the same
file again. Measured on a 1200-file index with a fresh checkout of the
commit it was built from: every start reported "Diff: 0/1200 changed
(1200 unchanged-by-hash)".

Both Python classifiers now write the current mtime back:

- rust_incremental_precheck (every incremental non-force Rust run): the
  hash-confirmed files are refreshed on Python's connection, before any
  handoff to Rust, so the write never races Rust's ownership of the file.
  Because the precheck runs before every incremental Rust run, the Rust
  differ then sees the refreshed mtime and takes its mtime fast path too.
- indexing_coordinator Phase 2.5 (Python pipeline): the "metadata changed
  but content didn't" branch is collected and refreshed in one call.

New provider method refresh_file_mtimes(entries) (+ async), entries of
(stored path, current st_mtime, confirmed content_hash). It sets
modified_time only, and only on rows whose content_hash still equals the
confirmed hash, so a concurrent writer that stored new content never gets
an older mtime. DuckDB does it in one UPDATE ... FROM unnest(...) with
to_timestamp(?) like every other files writer; LanceDB with one
merge_insert of the matching rows. updated_at and skip_reason are left
alone: the content was confirmed, not re-indexed.

A failed refresh is logged at warning and never fails the run; its only
cost is the next run hashing again, which is today's behaviour. The Diff
and Change scan log lines report "N mtimes refreshed".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
chunkhound#500 merged upstream as squash 5a01b27, including its review round
(rust_mtime_epsilon, plan_rust_run/RustRunPlan, docstrings, two contract
tests). This branch still carried chunkhound#500's original commits, so three files
conflicted. Each resolution keeps main's code as is and ports this
branch's mtime refresh onto it.

chunkhound/services/rust_incremental_precheck.py (add/add):
  Main's version taken whole (RustRunPlan, plan_rust_run, PEP 257
  docstrings), with this branch's change re-applied on top: the module
  docstring paragraph on the mtime refresh; the refresh and
  mtimes_refreshed fields on RustIncrementalWork; the refresh collection
  in classify_files; and the refresh_file_mtimes call inside
  find_rust_incremental_work's worker, on Python's connection, before
  plan_rust_run returns and so before any handoff to Rust. A failed
  refresh still logs a warning and never fails the run. The sentence
  added to the find_rust_incremental_work docstring is re-wrapped into
  main's reformatted docstring.

chunkhound/services/indexing_coordinator.py (content):
  The import and the Phase 2.6 block take main's side (plan_rust_run via
  rust_mtime_epsilon); this branch's inline copy of chunkhound#500's original
  narrowing logic is gone. The skip-branch "Diff: 0/N changed" log line
  keeps this branch's "N mtimes refreshed" count, read through main's
  variable as rust_plan.work.mtimes_refreshed instead of
  rust_work.mtimes_refreshed. The Python-path Phase 2.5 refresh merged
  without conflict.

tests/contracts/test_rust_startup_reader_access.py (add/add):
  Main's version taken whole (its four tests, including
  test_precheck_agrees_with_the_rust_differ and
  test_unchanged_reindex_restores_an_hnsw_index_a_crash_left_missing),
  plus this branch's _index_then_touch helper and its two tests,
  unmodified. This branch's one-line imports are covered by main's
  multi-line import of find_rust_incremental_work; the IndexingCoordinator
  import is added.

The provider files (database_provider, duckdb, lancedb, serial) merged
without conflict.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…re its refresh

test_precheck_agrees_with_the_rust_differ compares the precheck's verdict
with the Rust differ's on the same rows. The precheck now stores the new
mtime of every file it confirms unchanged by hash, so in the
new-mtime-same-bytes case the Rust run that follows took its mtime fast path
and never reached its hash path: that case checked only what untouched
checks, and a hash disagreement between the two would pass. The test's
precheck call now runs with the refresh stubbed out, so Rust's differ sees
the rows the precheck classified.

Also:
- plan_rust_run's docstring says it stores those mtimes.
- The Diff log line of a narrowed or full Rust run reports the precheck's
  refreshed count too, not only the skipped-run line.
- ruff format on the new test's signature.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fstrasz

fstrasz commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

#500 is merged, so I merged main into this branch (d3806b3, an ordinary merge; nothing rebased). The PR's diff is now this change alone.

🤖 Generated with Claude Code

@VakninAriel VakninAriel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code Review — PR #502

Verdict: 🚫 Request Changes

Summary

Files with changed mtimes but identical content hashes were classified as unchanged without updating stored mtimes, forcing every later scan to hash them again. At the reviewed pinned head, this PR adds batched mtime refreshes to the Rust precheck and Python change scan, layered on #500's precheck work. The goal is to refresh only metadata for hash-confirmed unchanged files, avoiding repeated hashing on later scans.

What's good

  • The DuckDB implementation updates only modified_time and checks the confirmed content hash in the same batched SQL statement, leaving unrelated metadata untouched.
  • Separate caller-level regression tests cover both the Rust precheck and Python pipeline by touching unchanged files and asserting that the second run no longer hashes them.

Freshness warning: Package freshness checked 2026-11-11T15:38:58.574960+00:00: STALE: included heads/eligibility changed; see overview and freshness audit before posting. This report applies only to its pinned SHA.

Severity Count
🔴 Critical 0
🟠 High 0
🟡 Medium 1
🟢 Minor 0

Findings

🟡 [Make LanceDB mtime refresh conditional at write time and metadata-only] (#1 · Medium)

Location: chunkhound/providers/database/lancedb_provider.py — lines 812–821

With a LanceDB-backed direct MCP/HTTP process indexing while a separate CLI index process writes the same database, each process has its own serial executor; CLI startup does not consult the daemon lock unless a database lock exception occurs, and LanceDB connect takes no exclusive writer lock. When that second process updates a file after the refresh query returns but before merge_insert executes, the Python hash comparison sees the old snapshot and the unconditional whole-row merge overwrites the concurrent writer’s newer content_hash, size, indexed_time and skip_reason as well as modified_time. The per-provider serial executor does not serialize other connections. A supposedly metadata-only unchanged-file optimization can therefore roll back indexing metadata and leave the file row inconsistent with current content/chunks. Previously this unchanged-by-hash path performed no write, so the similar preexisting update_file pattern does not make this overwrite preexisting.

Suggested fix:

Enforce the path/hash condition atomically at the LanceDB write and modify only modified_time. Use a conditional partial update or a supported conditional merge with only the intended columns, preserving batched execution where supported. Add an interleaved second-connection regression test that changes content metadata after selection and verifies refresh cannot overwrite it.

Review metadata and audit

Draft review for human approval. Nothing has been posted to GitHub.

Pinned head SHA: 6fcf18d71c3a3226c55dbe13d5a430762217eac5

Package freshness checked 2026-11-11T15:38:58.574960+00:00: STALE: included heads/eligibility changed; see overview and freshness audit before posting. This report applies only to its pinned SHA.

PR: #502

Title: fix(pipeline): store the mtime of a file confirmed unchanged by hash

Author: fstrasz · Branches: fix/precheck-refresh-mtime-upstream → main

Diff merge base: 98be86f

Review scope: Full main...HEAD contribution, merge base 98be86f through pinned head 6fcf18d; all seven changed files and provider/caller contracts. The full diff includes inherited #500 precheck commits 47be431 and a1eff26; final commit 6fcf18d adds mtime refresh. The retained finding is in the final commit, not the inherited precheck.

Eligibility: Bug fix addressing existing behavior; no new feature.

Overall assessment (audit only)

The hash-confirmed mtime optimization is sound on the checked DuckDB path, but LanceDB refresh can replace a concurrent writer’s newer entire file row with stale metadata. One Medium finding retained; speculative batch-size concern discarded.

Strength evidence

  • {"strength_index": 0, "path": "chunkhound/providers/database/duckdb_provider.py", "source": "pr-502.pinned.diff", "detail": "_executor_refresh_file_mtimes uses UPDATE ... FROM unnested parameter arrays with files.path = v.path AND files.content_hash = v.h; modified_time is the only SET target. Praise is specific to DuckDB, not the LanceDB merge."}
  • {"strength_index": 1, "path": "tests/contracts/test_rust_startup_reader_access.py", "source": "pr-502.pinned.diff", "detail": "test_precheck_refreshes_the_mtime_of_a_hash_confirmed_file checks second.skipped_by_hash == 0; test_python_change_scan_refreshes_the_mtime_of_a_hash_confirmed_file checks hashes_per_run == [3, 0]. Test contents inspected, not a local pass claim."}

Finding #1 evidence

  • Final audit verified process-level reachability, not concurrent calls within one executor: run.py:265-271 configures the CLI provider directly and only checks daemon ownership on a DB lock exception; mcp.py:80-95 starts HTTP directly and :117-122 permits direct stdio; LanceDB _create_connection at 252-273 uses ordinary lancedb.connect without cross-process locking. The registry at 546 creates one provider per process, not a global executor across processes.
  • Fresh cross-process probe used actual production _executor_update_file in a separate uv subprocess, plus production refresh in the first process and real LanceDB tables. Fresh connection confirmed hash=new,size=99,mtime=999 before refresh; afterward hash=old,size=1,mtime=300. Exit 0. /tmp/chunkhound-final-lance-qupcur8y/probe.py and writer.py. Only the interleaving point is forced; no concurrent use of a single executor was assumed. Native CLI/MCP startup itself was not executed.
  • The new provider interface at database_provider.py:207-215 promises only modified_time changes and only while the confirmed hash still matches. LanceDB reads full rows at :805-810, checks their hashes in Python at :814, and unconditionally replaces matched rows at :819-821.
  • Provider connection creation uses ordinary lancedb.connect; no cross-connection writer lock protects this sequence. Installed LanceDB 0.25.3 permits the demonstrated second connection update.
  • Reconciler reran the inspected production-body probe against fresh temporary real tables. A second connection committed hash=new, size=99, modified_time=999, indexed_time=999, skip_reason=new-state; refresh restored hash=old, size=1, modified_time=300, indexed_time=1, skip_reason=None. Exit 0.
  • The same probe passed matching/mismatched-hash and unrelated-column checks in DuckDB 1.4.4 and noninterleaved LanceDB, including 26 rows and quoted paths.

Reviewer keys: sonnet, astra

Verification

  • Reconciler: git -C /tmp/chunkhound-pr-reviews-20261111/pr-502 rev-parse HEAD matched manifest; git diff --check 98be86f 6fcf18d and git status --short exited 0 with no output. Both completed reports were read. All assistant-message provider/model/responseModel identities, successful runner statuses, valid provenance, pinned heads and report SHA256 values were checked; two distinct response models confirmed.
  • Astra: timeout 120s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync mypy chunkhound --cache-dir=/tmp/chunkhound-pr-502-astra-a1-jrlt7ny8/mypy-cache -> exit 1, 993 errors in 89 files (375 checked). Repeated with the six final-commit production files shadowed from HEAD^ in /tmp/chunkhound-pr-502-astra-a1-jrlt7ny8/parent-<basename> and cache mypy-parent-cache -> exit 1, identical line-normalized diagnostics.
  • Astra: timeout 90s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 CHUNKHOUND_USE_RUST=0 uv run --no-sync pytest -p no:cacheprovider --basetemp=/tmp/chunkhound-pr-502-astra-a1-jrlt7ny8/pytest-unit --timeout=30 tests/unit/test_skip_unchanged_files.py tests/unit/test_checksum_verify_flow.py -> exit 1, two native-import setup errors, no tests passed.
  • Astra: timeout 60s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync pytest -p no:cacheprovider --basetemp=/tmp/chunkhound-pr-502-astra-a1-jrlt7ny8/pytest-contract --timeout=30 tests/contracts/test_rust_startup_reader_access.py -> exit 2, one native-import collection error, zero tests collected.
  • Astra: timeout 60s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync python /tmp/chunkhound-pr-502-astra-a1-jrlt7ny8/provider_probe.py -> final exit 0. Its initial probe query mishandled DuckDB naive timestamps; corrected to production TIMESTAMPTZ cast before final success. Reconciler inspected the script and reran its unchanged method bodies via timeout 60s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync python - with only TMP replaced by tempfile.TemporaryDirectory(prefix="reconcile-502-") to avoid reusing the existing table; exit 0 with the same stale-row overwrite.
  • Sonnet independently exercised the DuckDB UPDATE with a path index and chunks foreign key: only the matching-hash row updated. Its mypy report contained 993 errors in 89 files; displayed exit 0 belonged to tail, not mypy. Its startup-reader contract selection was blocked at native import.

Limitations

  • Native-dependent tests did not execute successfully: the shared environment lacks chunkhound_native.chunkhound_native. No native build, dependency installation, network call, source edit or environment repair was performed. CI is only the captured green snapshot, not a fresh run.
  • Supplemental probes extract production definitions and use real external libraries/processes with simplified surrounding state. They are not end-to-end native indexing or MCP verification.
  • The concurrency reproduction uses a real second LanceDB connection but not a complete pair of indexing services. The frequency of concurrent writers was not measured.
  • CI is a captured snapshot, not a fresh run or a guarantee of current branch status.
  • Model identities are verified declarations supplied by the reconciler; the renderer does not inspect raw reports or provenance events.

Disposition of discarded / merged findings

  • Final audit keeps the Medium finding after challenging executor reachability. Same-provider concurrent calls serialize and cannot trigger the race, but supported direct MCP/HTTP and CLI index paths can create separate processes/providers against LanceDB without a shared writer lock. The strengthened reproduction commits the second write in another process using the production update method, not a mocked unsupported concurrent provider call. Do not describe ordinary same-executor tasks as vulnerable; whole-row stale snapshots remain vulnerable across processes.
  • Merged Sonnet’s low-confidence Minor atomicity concern and Astra’s reproduced Medium finding into one Medium correctness finding. The trigger requires another connection, so High is not justified; actual stale whole-row replacement makes Minor too low.
  • Discarded Sonnet’s unbounded IN-list concern: no failing supported repository size, expression limit or measured performance regression was supplied. It was explicitly speculative; refresh failure also degrades to old rehash behavior.
  • Do not retain a separate missing-LanceDB-test or documentation-only finding. Regression coverage is part of the suggested correctness fix, not an independently substantiated bug.

Independent reviewer provenance

  • sonnet — provider: amat-tfy; requested model: standard-chat-dev/claude-sonnet-5.5; verified response model: aws-aidev-models/us.anthropic.claude-sonnet-5-5. Identity evidence · Raw report
  • astra — provider: amat-tfy; requested model: frontier-chat-dev/gpt-6-astra; verified response model: gpt-6-astra. Identity evidence · Raw report

CI snapshot

Captured: 2026-11-11T14:18:23.581921+00:00. Eligibility green: True. Counts: {"SKIPPED": 2, "SUCCESS": 23}

Reviewed by Ariel Vaknin via pi.dev

… row

Review of 4027df2 found that the LanceDB refresh read the rows, compared
hashes in Python, then merged the whole row back by id. Another process
indexing the same database (nothing locks the files table across
connections) could rewrite a row in between; the merge then restored the
old content_hash, size, indexed_time and skip_reason along with the new
modified_time.

The write is now a compare-and-swap: one merge keyed on (path,
content_hash, indexed_time) as read. Every write of a file's content or
skip state stamps a new indexed_time, so the merge matches only a row
nobody rewrote since it was read, and stores it with the new
modified_time and nothing else changed. Lance 0.39 rejects a per-row
value (CASE) in a conditional update and fails a merge whose source has
fewer columns than the table, so the merge carries the row as read. One
merge per batch, as before; 2,000 of 22,000 rows take 0.14 s either way.

The new test has a second connection rewrite one file's content and
record another as skipped just before the refresh writes; both keep that
writer's values, and the third file gets only its new mtime.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fstrasz

fstrasz commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Fixed in 5d2fb27.

The LanceDB refresh is now a compare-and-swap: one merge keyed on (path, content_hash, indexed_time) as read. Every write of a file's content or skip state stamps a new indexed_time, so the merge matches only a row nobody has rewritten since it was read. It stores that row with the new modified_time and nothing else changed. A row another connection rewrote in between keeps that writer's values: content hash, size, indexed_time, skip_reason and mtime. It is still one merge per batch; 2,000 of 22,000 rows take 0.14 s, the same as the merge on id.

I tried the two forms you suggested first. Lance 0.39 rejects them:

  • a conditional update with a per-row value: CASE path WHEN ... END is "not supported SQL in lance";
  • a conditional merge with only the intended columns: a source of path, content_hash and modified_time makes the merge panic ("Incorrect number of arrays for StructArray fields, expected 3 got 4").

So the merge carries the whole row as read, and the key makes it conditional.

The new test, tests/integration/test_lancedb_refresh_file_mtimes.py, has a second connection rewrite one file's content and record another file as skipped, just before the refresh writes. Both rows keep that writer's values, and a third file gets only its new mtime. On 4027df2 it fails: the rewritten content is rolled back.

Serially on Windows: every LanceDB test file, the contracts file and related unit tests, 141 passed; smoke 14 passed. Upstream's CI workflow on our fork at this head is green on every job: https://github.com/fstrasz/chunkhound/actions/runs/43264819556 (after two reruns of macOS test shards that GitHub cancelled on the earlier attempts; one of them could not get a hosted runner).

The description is updated to match.

🤖 Generated with Claude Code, reviewed by FStrasz

@fstrasz

fstrasz commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@VakninAriel, following up on your review. The LanceDB finding was addressed in 5d2fb27 (details):

  • The refresh is a compare-and-swap: one merge keyed on (path, content_hash, indexed_time) as read. Every write of a file row stamps a new indexed_time, so the merge matches only a row no other connection has rewritten, and only modified_time changes.
  • It writes the whole row as read because Lance 0.39 rejects both narrower forms. A conditional update with a per-row value is "not supported SQL in lance". A merge with only the intended columns panics ("Incorrect number of arrays for StructArray fields").
  • test_refresh_never_rolls_back_a_concurrent_writer passed today on ubuntu, macOS and Windows at f2f9e9b.

Does that resolve the finding, or would you still like a narrower write?

🤖 Generated with Claude Code, reviewed by FStrasz

@HananKavitzAmat

Copy link
Copy Markdown
Collaborator

Looks good

@HananKavitzAmat
HananKavitzAmat dismissed VakninAriel’s stale review November 17, 2026 11:46

The reported issue is resolved

@HananKavitzAmat
HananKavitzAmat added this pull request to the merge queue Nov 17, 2026
Merged via the queue into chunkhound:main with commit a34ec48 Nov 17, 2026
25 checks passed
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in chunkhound#526, chunkhound#502 and chunkhound#533. CHANGELOG.md conflicted only because this PR and chunkhound#526 each add a line at the top of [Unreleased] ### Fixed; both entries are kept, this PR's first. No other conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

3 participants