Preload plugin recommendations during session startup (#41375)

## Why

Fetching plugin recommendations while building the first-turn context delays that
context when the recommendation catalog is not already cached.

## What changed

- Start fetching recommendations during session initialization, in parallel with
  MCP and plugin setup, and reuse the in-flight request when building context.
- Centralize the feature checks that enable plugin recommendations.
- Prevent an invalidated recommendation request from repopulating the cache after
  a newer request has completed.

## Testing

Added coverage for startup feature gating, reuse of the in-flight fetch, legacy
behavior when recommendations are unavailable, and cache invalidation races.

GitOrigin-RevId: 708774b9bfc472c9847973ae8b2774b66e7321e4
This commit is contained in:
Matthew Zeng
2026-08-28 17:33:10 +00:00
committed by copyberry
parent 5ed294d49d
commit 8bcac28f93
7 changed files with 391 additions and 14 deletions
+14 -3
View File
@@ -1764,11 +1764,22 @@ impl PluginsManager {
.await
{
Ok(mode) => {
let mut cache = match self.recommended_plugins_cache.write() {
Ok(cache) => cache,
let refreshes = match self.recommended_plugins_refreshes.read() {
Ok(refreshes) => refreshes,
Err(err) => err.into_inner(),
};
cache.insert(cache_key.clone(), mode.clone());
// Hold the refresh lock through publication, matching cache-clear lock
// order. An invalidated initializer must not repopulate the cache.
if refreshes
.get(&cache_key)
.is_some_and(|current| Arc::ptr_eq(current, &refresh))
{
let mut cache = match self.recommended_plugins_cache.write() {
Ok(cache) => cache,
Err(err) => err.into_inner(),
};
cache.insert(cache_key.clone(), mode.clone());
}
mode
}
Err(err) => {