Skip to content

fix: coalesce locator cache in-flight lookups#419

Merged
karthiknadig merged 4 commits intomainfrom
fix/issue-399
Apr 15, 2026
Merged

fix: coalesce locator cache in-flight lookups#419
karthiknadig merged 4 commits intomainfrom
fix/issue-399

Conversation

@karthiknadig
Copy link
Copy Markdown
Member

Summary:

  • Add per-key in-flight coordination to LocatorCache::get_or_insert_with so concurrent callers share the first closure result.
  • Share both Some and in-flight None results with current waiters while keeping None uncached for later retries.
  • Add concurrency and panic-cleanup tests, and update the conda mamba-manager cache comment for the new behavior.

Validation:

  • cargo test -p pet-core
  • cargo test -p pet-conda
  • cargo fmt --all
  • cargo clippy --all -- -D warnings

Fixes #399

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 12, 2026

Performance Report (Linux) ✅

Metric PR (P50) PR (P95) Baseline (P50) Delta Change
Server Startup 1ms 1ms 1ms 0ms 0%
Full Refresh 78ms 219ms 96ms -18ms -10.0%

Results based on 10 iterations. P50 = median, P95 = 95th percentile.


Legend
  • 🚀 Significant speedup (>100ms faster)
  • ✅ Faster than baseline
  • ➖ No significant change
  • 🔺 Slower than baseline (>100ms)
  • ⚠️ Significant slowdown (>500ms)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 12, 2026

Test Coverage Report (Linux)

Metric Value
Current Coverage 74.0%
Base Branch Coverage 73.6%
Delta .4% ✅

Coverage increased! Great work!

@karthiknadig karthiknadig requested a review from Copilot April 12, 2026 08:19
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 12, 2026

Performance Report (macOS)

Metric PR (P50) PR (P95) Baseline (P50) Delta
Server Startup 64ms 568ms 58ms 6ms
Full Refresh 148ms 27512ms 99ms 49ms

Results based on 10 iterations. P50 = median, P95 = 95th percentile.


Legend
  • 🚀 Significant speedup (>100ms faster)
  • ✅ Faster than baseline
  • ➖ No significant change
  • 🔺 Slower than baseline (>100ms)
  • ⚠️ Significant slowdown (>500ms)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 12, 2026

Performance Report (Windows) ➖

Metric PR (P50) PR (P95) Baseline (P50) Delta Change
Server Startup 10ms 12ms 8ms 2ms 25%
Full Refresh 166ms 1192ms 128ms 38ms 29.7%

Results based on 10 iterations. P50 = median, P95 = 95th percentile.


Legend
  • 🚀 Significant speedup (>100ms faster)
  • ✅ Faster than baseline
  • ➖ No significant change
  • 🔺 Slower than baseline (>100ms)
  • ⚠️ Significant slowdown (>500ms)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 12, 2026

Test Coverage Report (Windows)

Metric Value
Current Coverage 70.27%
Base Branch Coverage 69.86%
Delta 0.41% ✅

Coverage increased! Great work!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes issue #399 by eliminating the TOCTOU window in LocatorCache::get_or_insert_with, ensuring concurrent callers for the same key share a single in-flight computation (preventing duplicate side effects such as repeated process spawns in locators).

Changes:

  • Added per-key in-flight coordination to LocatorCache::get_or_insert_with using a mutex-protected in-flight map plus condvar waiters.
  • Ensured None results are shared with concurrent waiters but are not persisted in the cache (allowing later retries).
  • Added concurrency + panic-cleanup tests and updated the conda locator comment to reflect the new caching behavior.
Show a summary per file
File Description
crates/pet-core/src/cache.rs Implements per-key in-flight coalescing for get_or_insert_with and adds tests for concurrency, None sharing, and panic cleanup.
crates/pet-conda/src/lib.rs Updates the mamba-manager caching comment to reflect the new in-flight coalescing behavior.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates LocatorCache::get_or_insert_with to coalesce concurrent lookups per key, preventing duplicate closure execution (and side effects) while still allowing later retries when a computation returns None (by not caching None results).

Changes:

  • Add per-key “in-flight” coordination to LocatorCache::get_or_insert_with so concurrent callers share the first computation result.
  • Share None results with current waiters but avoid caching None, enabling subsequent retries.
  • Add concurrency/panic-cleanup tests and update the conda mamba-manager cache comment to reflect the new behavior.
Show a summary per file
File Description
crates/pet-core/src/cache.rs Implements per-key in-flight coordination and adds tests for coalescing, None sharing, and panic cleanup.
crates/pet-conda/src/lib.rs Updates comment describing mamba-manager lookup behavior now that the cache coalesces concurrent lookups.

Copilot's findings

Comments suppressed due to low confidence (1)

crates/pet-core/src/cache.rs:80

  • Drop calls publish_result(None) and that function currently uses expect(...) on mutex locks. If a panic is already in flight (e.g., the closure panicked) and a lock is poisoned, panicking again from Drop can cause an abort (double panic) and can also strand waiters. Drop cleanup should be best-effort and avoid panicking; recover from poison and still remove the key + notify.
impl<K: Eq + Hash, V> Drop for InFlightOwnerGuard<'_, K, V> {
    fn drop(&mut self) {
        if self.key.is_some() {
            self.publish_result(None);
        }
  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread crates/pet-core/src/cache.rs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates pet-core’s LocatorCache::get_or_insert_with to coordinate concurrent lookups per key, preventing duplicate closure execution (and side effects) under contention, and aligns Conda’s mamba-manager discovery commentary with the new behavior.

Changes:

  • Add per-key in-flight tracking (Mutex + Condvar) to coalesce concurrent get_or_insert_with calls for the same key.
  • Share an in-flight None result with current waiters while still not caching None for future retries.
  • Add new concurrency/panic-cleanup tests and update Conda’s cache comment for mamba discovery.
Show a summary per file
File Description
crates/pet-core/src/cache.rs Implements per-key in-flight coordination for get_or_insert_with and adds concurrency/panic/poisoning tests.
crates/pet-conda/src/lib.rs Updates comment to reflect that mamba discovery/reporting is coalesced per in-flight cache key.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread crates/pet-core/src/cache.rs
Comment thread crates/pet-core/src/cache.rs
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a TOCTOU window in pet-core’s LocatorCache::get_or_insert_with by adding per-key in-flight coordination so concurrent callers share a single computation (and its side effects), addressing #399. It also updates conda’s mamba-manager caching comment to reflect the new behavior and adds concurrency + panic-cleanup tests to validate the coordination logic.

Changes:

  • Add per-key “in-flight” tracking to coalesce concurrent get_or_insert_with calls for the same key.
  • Ensure None results are shared with current waiters but not cached (allowing future retries), and ensure owner panics wake waiters with a panic.
  • Add multi-threaded and panic/poison recovery tests; update related conda comment.
Show a summary per file
File Description
crates/pet-core/src/cache.rs Implements per-key in-flight lookup coordination for get_or_insert_with and adds concurrency/panic robustness tests.
crates/pet-conda/src/lib.rs Updates the mamba-manager cache comment to match the new coalescing semantics.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new

@karthiknadig karthiknadig marked this pull request as ready for review April 13, 2026 02:38
@karthiknadig karthiknadig enabled auto-merge (squash) April 13, 2026 02:40
@karthiknadig karthiknadig merged commit f827577 into main Apr 15, 2026
34 checks passed
@karthiknadig karthiknadig deleted the fix/issue-399 branch April 15, 2026 22: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.

LocatorCache::get_or_insert_with has TOCTOU window allowing duplicate side effects

3 participants