Преглед на файлове

Consume user-initiated loop flag before canStartNewLoop guard

When the guard blocks (loop suspended, too soon since last loop, no
pump), nextLoopUserInitiated leaks to the next scheduled tick and
incorrectly bypasses dwell suppression for an error the user did not
request. Consume the flag unconditionally before the guard.
trioneer преди 2 седмици
родител
ревизия
0575eca675
променени са 1 файла, в които са добавени 10 реда и са изтрити 4 реда
  1. 10 4
      Trio/Sources/APS/APSManager.swift

+ 10 - 4
Trio/Sources/APS/APSManager.swift

@@ -236,14 +236,20 @@ final class BaseAPSManager: APSManager, Injectable {
         Task { [weak self] in
         Task { [weak self] in
             guard let self else { return }
             guard let self else { return }
 
 
+            // Consume the user-initiated flag unconditionally — it was set
+            // for the loop the user just triggered. If the guard below blocks
+            // (suspended, too-soon, no pump), the next scheduled tick must
+            // not inherit it and bypass dwell suppression for an error the
+            // user didn't request.
+            let userInitiated = self.nextLoopUserInitiated
+            self.nextLoopUserInitiated = false
+
             // Check if we can start a new loop
             // Check if we can start a new loop
             guard await self.canStartNewLoop() else { return }
             guard await self.canStartNewLoop() else { return }
 
 
-            // Consume the user-initiated flag for the duration of this loop —
-            // affects whether transient errors surface immediately instead of
+            // Affects whether transient errors surface immediately instead of
             // dwell-suppressed (see `surfaceErrorIfNeeded`).
             // dwell-suppressed (see `surfaceErrorIfNeeded`).
-            self.currentLoopUserInitiated = self.nextLoopUserInitiated
-            self.nextLoopUserInitiated = false
+            self.currentLoopUserInitiated = userInitiated
             defer { self.currentLoopUserInitiated = false }
             defer { self.currentLoopUserInitiated = false }
 
 
             // Setup loop and background task
             // Setup loop and background task