@@ -23,6 +23,7 @@ import type { PreparedModelRuntimeCatalogMode } from "./prepared-model-runtime.t
2323type PreparedModelRuntimeLeaseContext = {
2424 owners : Map < string , PreparedModelRuntimeOwner > ;
2525 agentBuildCompletions : Map < string , Promise < void > > ;
26+ workspacePluginRootPresenceResolutions : Map < string , Promise < boolean | undefined > > ;
2627 retainedDirectRunOwners : PreparedModelRuntimeOwnerRetention ;
2728 retainedGatewayRunOwners : PreparedModelRuntimeOwnerRetention ;
2829 getBuildTimeoutMs ( ) : number ;
@@ -35,6 +36,26 @@ type PreparedModelRuntimeLeaseContext = {
3536 ) : Promise < PreparedModelRuntimeSnapshot > ;
3637} ;
3738
39+ async function resolveCoalescedWorkspacePluginRootPresence (
40+ input : PreparedModelRuntimeInput ,
41+ context : PreparedModelRuntimeLeaseContext ,
42+ ) : Promise < boolean | undefined > {
43+ const key = ownerKey ( input ) ;
44+ const existing = context . workspacePluginRootPresenceResolutions . get ( key ) ;
45+ if ( existing ) {
46+ return await existing ;
47+ }
48+ const pending = resolveWorkspacePluginRootPresence ( input ) ;
49+ context . workspacePluginRootPresenceResolutions . set ( key , pending ) ;
50+ try {
51+ return await pending ;
52+ } finally {
53+ if ( context . workspacePluginRootPresenceResolutions . get ( key ) === pending ) {
54+ context . workspacePluginRootPresenceResolutions . delete ( key ) ;
55+ }
56+ }
57+ }
58+
3859export async function resolveWorkspacePluginRootPresence (
3960 input : PreparedModelRuntimeInput ,
4061) : Promise < boolean | undefined > {
@@ -85,7 +106,9 @@ export async function acquirePreparedModelRuntimeLeaseFromOwners(
85106 const workspacePluginRootPresent =
86107 rawInput . workspacePluginRootPresent ??
87108 retainedWorkspacePluginRootPresent ??
88- ( provenance === "run" ? await resolveWorkspacePluginRootPresence ( normalizedInput ) : undefined ) ;
109+ ( provenance === "run"
110+ ? await resolveCoalescedWorkspacePluginRootPresence ( normalizedInput , context )
111+ : undefined ) ;
89112 let input = normalizePreparedModelRuntimeInput ( {
90113 ...normalizedInput ,
91114 ...( workspacePluginRootPresent === undefined ? { } : { workspacePluginRootPresent } ) ,
0 commit comments