@@ -93,8 +93,16 @@ public static function evaluate( array $metrics, array $thresholds = array(), bo
9393 $ effective_refuse_bytes = $ thresholds ['refuse_free_bytes ' ];
9494 $ effective_warn_bytes = $ thresholds ['warn_free_bytes ' ];
9595 if ( null !== $ total_bytes && $ total_bytes > 0 ) {
96- $ effective_refuse_bytes = max ($ effective_refuse_bytes , (int ) ceil ($ total_bytes * ( $ thresholds ['refuse_free_percent ' ] / 100 )));
97- $ effective_warn_bytes = max ($ effective_warn_bytes , (int ) ceil ($ total_bytes * ( $ thresholds ['warn_free_percent ' ] / 100 )));
96+ $ effective_refuse_bytes = self ::effective_free_bytes_threshold (
97+ (int ) $ thresholds ['refuse_free_bytes ' ],
98+ $ thresholds ['refuse_free_percent ' ],
99+ $ total_bytes
100+ );
101+ $ effective_warn_bytes = self ::effective_free_bytes_threshold (
102+ (int ) $ thresholds ['warn_free_bytes ' ],
103+ $ thresholds ['warn_free_percent ' ],
104+ $ total_bytes
105+ );
98106 }
99107
100108 if ( null !== $ free_bytes ) {
@@ -104,15 +112,15 @@ public static function evaluate( array $metrics, array $thresholds = array(), bo
104112 'Free disk space is %.1f GiB%s, below the refusal threshold of %.1f GiB or %.1f%% free, whichever is stricter. ' ,
105113 self ::bytes_to_gib ($ free_bytes ),
106114 null === $ free_percent ? '' : sprintf (' (%.1f%%) ' , $ free_percent ),
107- self ::bytes_to_gib ($ thresholds ['refuse_free_bytes ' ]),
115+ self ::bytes_to_gib ( ( int ) $ thresholds ['refuse_free_bytes ' ] ),
108116 $ thresholds ['refuse_free_percent ' ]
109117 );
110118 } elseif ( $ free_bytes < $ effective_warn_bytes ) {
111119 $ warnings [] = sprintf (
112120 'Free disk space is %.1f GiB%s, below the warning threshold of %.1f GiB or %.1f%% free, whichever is stricter. ' ,
113121 self ::bytes_to_gib ($ free_bytes ),
114122 null === $ free_percent ? '' : sprintf (' (%.1f%%) ' , $ free_percent ),
115- self ::bytes_to_gib ($ thresholds ['warn_free_bytes ' ]),
123+ self ::bytes_to_gib ( ( int ) $ thresholds ['warn_free_bytes ' ] ),
116124 $ thresholds ['warn_free_percent ' ]
117125 );
118126 }
@@ -150,10 +158,10 @@ public static function evaluate( array $metrics, array $thresholds = array(), bo
150158 'workspace_size_exact ' => false ,
151159 'worktree_count ' => $ count ,
152160 'warn_free_bytes ' => $ thresholds ['warn_free_bytes ' ],
153- 'warn_free_gib ' => round (self ::bytes_to_gib ($ thresholds ['warn_free_bytes ' ]), 2 ),
161+ 'warn_free_gib ' => round (self ::bytes_to_gib ( ( int ) $ thresholds ['warn_free_bytes ' ] ), 2 ),
154162 'warn_free_percent ' => $ thresholds ['warn_free_percent ' ],
155163 'refuse_free_bytes ' => $ thresholds ['refuse_free_bytes ' ],
156- 'refuse_free_gib ' => round (self ::bytes_to_gib ($ thresholds ['refuse_free_bytes ' ]), 2 ),
164+ 'refuse_free_gib ' => round (self ::bytes_to_gib ( ( int ) $ thresholds ['refuse_free_bytes ' ] ), 2 ),
157165 'refuse_free_percent ' => $ thresholds ['refuse_free_percent ' ],
158166 'effective_refuse_bytes ' => $ effective_refuse_bytes ,
159167 'effective_refuse_gib ' => round (self ::bytes_to_gib ($ effective_refuse_bytes ), 2 ),
@@ -295,6 +303,28 @@ private static function count_worktree_like_dirs( string $workspace_path ): int
295303 return $ count ;
296304 }
297305
306+ /**
307+ * Calculate the free-space threshold for the measured filesystem.
308+ *
309+ * The absolute GiB floor protects normal workspaces, but bounded ephemeral
310+ * filesystems can be smaller than that floor. In that case, the percentage
311+ * threshold is the only attainable safety signal.
312+ *
313+ * @param int $absolute_bytes Absolute free-space threshold.
314+ * @param float $percent Percentage free-space threshold.
315+ * @param int $total_bytes Measured filesystem size.
316+ * @return int
317+ */
318+ private static function effective_free_bytes_threshold ( int $ absolute_bytes , float $ percent , int $ total_bytes ): int {
319+ $ percent_bytes = (int ) ceil ($ total_bytes * ( $ percent / 100 ));
320+
321+ if ( $ total_bytes < $ absolute_bytes ) {
322+ return $ percent_bytes ;
323+ }
324+
325+ return max ($ absolute_bytes , $ percent_bytes );
326+ }
327+
298328 /**
299329 * Convert bytes to GiB.
300330 *
0 commit comments