@@ -66,6 +66,14 @@ class HealthService extends Base {
6666 */
6767 #lastCheckTime = null ;
6868
69+ /**
70+ * Promise of the currently executing health check.
71+ * Used for request deduplication to prevent "thundering herd" of gh CLI calls.
72+ * @member {Promise<Object>|null} #healthCheckPromise
73+ * @private
74+ */
75+ #healthCheckPromise = null ;
76+
6977 /**
7078 * The status from the previous health check, used to detect state transitions
7179 * (e.g., recovery from 'unhealthy' to 'healthy') and log meaningful messages.
@@ -238,9 +246,22 @@ class HealthService extends Base {
238246 }
239247 }
240248
249+ // Check for in-flight request (deduplication)
250+ if ( this . #healthCheckPromise) {
251+ logger . debug ( '[HealthService] Joining in-flight health check...' ) ;
252+ return this . #healthCheckPromise;
253+ }
254+
241255 // Cache is stale, was unhealthy, or doesn't exist - perform a fresh check
242256 logger . debug ( '[HealthService] Performing fresh health check' ) ;
243- const health = await this . #performHealthCheck( ) ;
257+
258+ // Create the promise and store it
259+ this . #healthCheckPromise = this . #performHealthCheck( ) . finally ( ( ) => {
260+ // Always clear the promise when done, success or fail
261+ this . #healthCheckPromise = null ;
262+ } ) ;
263+
264+ const health = await this . #healthCheckPromise;
244265
245266 // Detect and log meaningful state transitions
246267 // This helps users understand when their fixes (like running `gh auth login`) succeed
0 commit comments