Skip to content

fix: full review remarks — concurrency, tests, metadata consistency, doc-comments#102

Merged
flupkede merged 4 commits into
developfrom
fix/review-all-remarks
Jun 2, 2026
Merged

fix: full review remarks — concurrency, tests, metadata consistency, doc-comments#102
flupkede merged 4 commits into
developfrom
fix/review-all-remarks

Conversation

@flupkede
Copy link
Copy Markdown
Owner

@flupkede flupkede commented Jun 2, 2026

Summary

Fixes all issues found in the full code review of develop (v1.0.156):

Stage 1 — Doc-comments + safe_canonicalize

  • repos.rs: corrected "Pure (no disk I/O)" doc-comments on relocate_missing and prune_stale — both transitively perform disk I/O (filesystem traversal + git subprocess); callers in async contexts must use spawn_blocking
  • serve/mod.rs: replaced raw std::fs::canonicalize with safe_canonicalize in reload_if_changed so Windows \?\ UNC prefix is stripped before path comparison

Stage 2 — index/mod.rs quality

  • Extracted safety-net HNSW rebuild into ensure_hnsw_index_if_needed() (was inline, untestable); added 3 unit tests: unindexed-with-chunks rebuilds, already-indexed is idempotent, empty DB skips
  • metadata.json schema consistency: normal (non-cancelled) path now writes "partial": false so readers always see the field
  • Cancellation finalisation path: changed non-critical ? propagations to log-and-continue (metadata write, FileMetaStore save, stats read) — keeps partial chunks searchable even if any recovery step fails

Stage 3 — Concurrency

  • evaluate_csharp_rebuild: bootstrap_last_changed (git subprocess + ≤10k entry fs-walk) was running while holding config.write(), blocking all concurrent readers; fixed to run with no lock held
  • evaluate_csharp_rebuild call site in run_phase_2_csharp_scip: wrapped in spawn_blocking so the async runtime is not stalled during C# candidate scan
  • warmup_repo and add_repo_handler background task: two build_index() calls on async threads moved to spawn_blocking + blocking_write(), matching the established pattern

Test plan

  • cargo fmt --check — PASSED
  • cargo check --all-targets — PASSED
  • cargo clippy --all-targets -- -D warnings — PASSED
  • cargo test --lib — 432 passed, 0 failed (3 new tests added)

🤖 Generated with Claude Code

flupkede and others added 4 commits June 2, 2026 16:29
- repos.rs: correct "Pure (no disk I/O)" doc-comments on relocate_missing and
  prune_stale — both transitively call scan_for_remote which does read_dir and
  spawns a git subprocess; callers must use spawn_blocking in async contexts.
- serve/mod.rs: replace raw std::fs::canonicalize with safe_canonicalize in
  reload_if_changed so Windows UNC prefix (\?\) is stripped before comparison,
  consistent with the project-wide safe_canonicalize rule.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ts + metadata consistency + cancel best-effort

- Extract the safety-net HNSW rebuild into ensure_hnsw_index_if_needed() so
  the logic is unit-testable; add 3 tests (unindexed with chunks rebuilds,
  already-indexed is idempotent, empty DB skips rebuild).
- metadata.json schema consistency: add "partial": false to the normal
  (non-cancelled) path so readers always see the field regardless of how
  indexing ended.
- Cancellation finalisation path: change non-critical ? propagations to
  log-and-continue (metadata.json write, FileMetaStore update/save, stats
  read) — keeps partial chunks searchable even if any recovery step fails.
  store.build_index() still propagates errors as before.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…_index in spawn_blocking

Three related concurrency fixes in serve/mod.rs, consistent with the
reconcile_all_paths fix from PR #101:

1. evaluate_csharp_rebuild: bootstrap_last_changed (git subprocess + ≤10k
   file fs-walk) was running while holding config.write(), blocking every
   concurrent config.read() for the scan duration. Fixed by checking whether
   bootstrap is needed under a read lock, running the slow I/O with no lock
   held, then taking the write lock only for the brief config update.

2. evaluate_csharp_rebuild call site in run_phase_2_csharp_scip: even with the
   above fix the function still ran synchronously on a Tokio worker thread.
   Wrapped in spawn_blocking so the async runtime stays responsive while
   scanning all C# candidates at startup.

3. warmup_repo and add_repo_handler background task: two build_index() calls
   were running directly on async threads while holding a tokio RwLock write
   guard. build_index() is CPU-heavy (HNSW construction). Both are now
   offloaded via spawn_blocking + blocking_write(), matching the established
   pattern at serve/mod.rs:1249.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@flupkede flupkede merged commit 404cb0e into develop Jun 2, 2026
1 check passed
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