diff --git a/mercurial/store.py b/mercurial/store.py
index a32d739b0ffbd9fdfede54081d419658218b3f77_bWVyY3VyaWFsL3N0b3JlLnB5..5a62d56e395570cc1dae80a4d310d91862c3cc4e_bWVyY3VyaWFsL3N0b3JlLnB5 100644
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -686,6 +686,12 @@
                 )
 
     def top_entries(self, phase=False) -> Generator[BaseStoreEntry, None, None]:
+        if phase and self.vfs.exists(b'phaseroots'):
+            yield SimpleStoreEntry(
+                entry_path=b'phaseroots',
+                is_volatile=True,
+            )
+
         files = reversed(self._walk(b'', False))
 
         changelogs = collections.defaultdict(dict)
@@ -725,11 +731,6 @@
                     target_id=b'',
                     details=file_details,
                 )
-        if phase and self.vfs.exists(b'phaseroots'):
-            yield SimpleStoreEntry(
-                entry_path=b'phaseroots',
-                is_volatile=True,
-            )
 
     def walk(
         self, matcher=None, phase=False
diff --git a/tests/test-stream-bundle-v2.t b/tests/test-stream-bundle-v2.t
index a32d739b0ffbd9fdfede54081d419658218b3f77_dGVzdHMvdGVzdC1zdHJlYW0tYnVuZGxlLXYyLnQ=..5a62d56e395570cc1dae80a4d310d91862c3cc4e_dGVzdHMvdGVzdC1zdHJlYW0tYnVuZGxlLXYyLnQ= 100644
--- a/tests/test-stream-bundle-v2.t
+++ b/tests/test-stream-bundle-v2.t
@@ -82,5 +82,6 @@
   adding [s] data/C.i (66 bytes)
   adding [s] data/D.i (66 bytes)
   adding [s] data/E.i (66 bytes)
+  adding [s] phaseroots (43 bytes)
   adding [s] 00manifest.i (584 bytes)
   adding [s] 00changelog.i (595 bytes)
@@ -85,6 +86,5 @@
   adding [s] 00manifest.i (584 bytes)
   adding [s] 00changelog.i (595 bytes)
-  adding [s] phaseroots (43 bytes)
   adding [c] branch2-served (94 bytes)
   adding [c] rbc-names-v1 (7 bytes)
   adding [c] rbc-revs-v1 (40 bytes)
@@ -139,5 +139,6 @@
   adding [s] data/C.i (66 bytes)
   adding [s] data/D.i (66 bytes)
   adding [s] data/E.i (66 bytes)
+  adding [s] phaseroots (43 bytes)
   adding [s] 00manifest.i (584 bytes)
   adding [s] 00changelog.i (595 bytes)
@@ -142,6 +143,5 @@
   adding [s] 00manifest.i (584 bytes)
   adding [s] 00changelog.i (595 bytes)
-  adding [s] phaseroots (43 bytes)
   adding [c] branch2-served (94 bytes)
   adding [c] rbc-names-v1 (7 bytes)
   adding [c] rbc-revs-v1 (40 bytes)