Track VM service package roots and await connection notifications
diff --git a/packages/devtools_app/lib/src/service/service_manager.dart b/packages/devtools_app/lib/src/service/service_manager.dart
index d135837..14f2b68 100644
--- a/packages/devtools_app/lib/src/service/service_manager.dart
+++ b/packages/devtools_app/lib/src/service/service_manager.dart
@@ -125,11 +125,9 @@
       serviceTrafficLogger = VmServiceTrafficLogger(service!);
     }
 
-    unawaited(
-      server.notifyForVmServiceConnection(
-        vmServiceUri: serviceManager.serviceUri!,
-        connected: true,
-      ),
+    await server.notifyForVmServiceConnection(
+      vmServiceUri: serviceManager.serviceUri!,
+      connected: true,
     );
   }
 
diff --git a/packages/devtools_shared/lib/src/server/handlers/_vm_service.dart b/packages/devtools_shared/lib/src/server/handlers/_vm_service.dart
index 94fd867..ac60796 100644
--- a/packages/devtools_shared/lib/src/server/handlers/_vm_service.dart
+++ b/packages/devtools_shared/lib/src/server/handlers/_vm_service.dart
@@ -12,12 +12,15 @@
   ///
   /// This map is used to lookup package roots for a particular VM service when
   /// [handleNotifyForVmServiceConnection] is called for a VM service disconnect
-  /// in DevTools app.
-  ///
-  /// If the Dart Tooling Daemon was not started by DevTools, this map will
-  /// never be used.
+  /// in DevTools app, and to validate runtime package roots in
+  /// [ExtensionsManager.serveAvailableExtensions].
   static final _packageRootsForVmServiceConnections = <String, Uri>{};
 
+  /// Returns an unmodifiable view of the package root URIs for currently
+  /// connected VM services.
+  static Iterable<Uri> get packageRootsForVmServiceConnections =>
+      UnmodifiableListView(_packageRootsForVmServiceConnections.values);
+
   static Future<shelf.Response> handleNotifyForVmServiceConnection(
     ServerApi api,
     Map<String, String> queryParams,
@@ -32,12 +35,8 @@
     if (missingRequiredParams != null) return missingRequiredParams;
 
     final dtdUri = dtd?.localUri;
-    final dtdSecret = dtd?.secret;
-    if (dtdUri == null || dtdSecret == null) {
-      // If DevTools server did not start DTD, there is nothing for us to do.
-      // This assertion may change in the future if the DevTools server has
-      // other functionality that interacts with VM service connections from
-      // DevTools app clients.
+    if (dtdUri == null) {
+      // If DTD is not available, there is nothing for us to do.
       return api.success();
     }
 
@@ -60,10 +59,10 @@
     }
 
     DartToolingDaemon? dartToolingDaemon;
+    final dtdSecret = dtd?.secret;
     try {
-      dartToolingDaemon = await DartToolingDaemon.connect(dtd!.localUri);
+      dartToolingDaemon = await DartToolingDaemon.connect(dtdUri);
 
-      // ignore: unnecessary_null_comparison, intentionally added to guard against future logic changes.
       if (dtdSecret != null) {
         final uriAsString = vmServiceUri.toString();
         connected
@@ -85,12 +84,12 @@
       );
       if (detectRootResponse.success) {
         final rootUri = detectRootResponse.uri;
-        if (rootUri == null) {
+        if (rootUri == null || dtdSecret == null) {
           return api.success();
         }
         return await updateDtdWorkspaceRoots(
           dartToolingDaemon,
-          dtdConnectionInfo: dtd,
+          dtdConnectionInfo: dtd!,
           rootFromVmService: rootUri,
           connected: connected,
           api: api,
@@ -150,8 +149,8 @@
         vmService = null;
       }
     } else {
-      final cachedRootForVmService =
-          _packageRootsForVmServiceConnections[vmServiceUriAsString];
+      final cachedRootForVmService = _packageRootsForVmServiceConnections
+          .remove(vmServiceUriAsString);
       if (cachedRootForVmService == null) {
         // If there is no root to remove, there is nothing for us to do.
         return (success: true, message: null, uri: null);
diff --git a/packages/devtools_shared/test/server/general_api_test.dart b/packages/devtools_shared/test/server/general_api_test.dart
index f090230..470e083 100644
--- a/packages/devtools_shared/test/server/general_api_test.dart
+++ b/packages/devtools_shared/test/server/general_api_test.dart
@@ -775,6 +775,10 @@
             expect(response.message, isNull);
             expect(response.uri, isNotNull);
             expect(response.uri!.toFilePath(), endsWith(app!.directory.path));
+            expect(
+              server.VmServiceHandler.packageRootsForVmServiceConnections,
+              contains(response.uri),
+            );
 
             final disconnectResponse =
                 await server.VmServiceHandler.detectRootPackageForVmService(
@@ -790,6 +794,10 @@
               disconnectResponse.uri!.toFilePath(),
               endsWith(app!.directory.path),
             );
+            expect(
+              server.VmServiceHandler.packageRootsForVmServiceConnections,
+              isNot(contains(response.uri)),
+            );
           },
         );
       });