Skip to content

Commit 1782440

Browse files
authored
Merge pull request #702 from Extra-Chill/fix/issue-699-worktree-remove-timeout
Make cleanup worktree removal timeout resumable
2 parents e65ae18 + 19ce162 commit 1782440

8 files changed

Lines changed: 211 additions & 55 deletions

inc/Abilities/WorkspaceAbilities.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2288,6 +2288,10 @@ private function registerAbilities(): void {
22882288
'type' => 'boolean',
22892289
'description' => 'Schedule each candidate as a single-row worktree_cleanup_chunk job for resumable async apply.',
22902290
),
2291+
'remove_timeout' => array(
2292+
'type' => 'integer',
2293+
'description' => 'Timeout in seconds for destructive git worktree remove calls during apply. Defaults to the cleanup removal timeout.',
2294+
),
22912295
'include_repaired_metadata' => array(
22922296
'type' => 'boolean',
22932297
'description' => 'Also include repaired metadata rows. Requires explicit opt-in and still runs fresh safety probes before removal.',
@@ -4031,7 +4035,7 @@ public static function worktreeCleanupArtifacts( array $input ): array|\WP_Error
40314035
/**
40324036
* Apply only worktrees with explicit lifecycle cleanup_eligible metadata in a bounded batch.
40334037
*
4034-
* @param array $input Input parameters (dry_run, limit, older_than, sort, force, via_jobs, source).
4038+
* @param array $input Input parameters (dry_run, limit, older_than, sort, force, via_jobs, remove_timeout, source).
40354039
* @return array<string,mixed>|\WP_Error
40364040
*/
40374041
public static function worktreeBoundedCleanupEligibleApply( array $input ): array|\WP_Error {
@@ -4051,6 +4055,9 @@ public static function worktreeBoundedCleanupEligibleApply( array $input ): arra
40514055
if ( isset($input['sort']) && '' !== trim( (string) $input['sort']) ) {
40524056
$opts['sort'] = trim( (string) $input['sort']);
40534057
}
4058+
if ( isset($input['remove_timeout']) ) {
4059+
$opts['remove_timeout'] = (int) $input['remove_timeout'];
4060+
}
40544061
if ( isset($input['source']) && '' !== trim( (string) $input['source']) ) {
40554062
$opts['source'] = trim( (string) $input['source']);
40564063
}

inc/Cli/Commands/WorkspaceCommand.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,10 +2960,14 @@ private function renderGitOperationResult( string $operation, array $result, arr
29602960
* metadata older than the compact duration (cleanup only, e.g. 7d, 24h).
29612961
* Candidate worktrees without valid `created_at` metadata are skipped.
29622962
*
2963-
* [--sort=<field>]
2964-
* : Sort cleanup candidates by reporting field. For artifact cleanup,
2965-
* `--sort=size` scans the cheap inventory once and returns the largest
2966-
* artifact opportunities without manual pagination.
2963+
* [--remove-timeout=<seconds>]
2964+
* : Timeout for destructive `git worktree remove` during cleanup apply.
2965+
* Defaults to a larger removal-specific budget than cheap git probes.
2966+
*
2967+
* [--sort=<field>]
2968+
* : Sort cleanup candidates by reporting field. For artifact cleanup,
2969+
* `--sort=size` scans the cheap inventory once and returns the largest
2970+
* artifact opportunities without manual pagination.
29672971
* ---
29682972
* options:
29692973
* - size
@@ -3492,6 +3496,9 @@ public function worktree( array $args, array $assoc_args ): void {
34923496
if ( isset($assoc_args['sort']) && '' !== trim( (string) $assoc_args['sort']) ) {
34933497
$input['sort'] = trim( (string) $assoc_args['sort']);
34943498
}
3499+
if ( isset($assoc_args['remove-timeout']) && '' !== trim( (string) $assoc_args['remove-timeout']) ) {
3500+
$input['remove_timeout'] = (int) $assoc_args['remove-timeout'];
3501+
}
34953502
break;
34963503
}
34973504

inc/Tasks/WorktreeCleanupChunkTask.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public function executeTask( int $jobId, array $params ): void {
111111
'skip_github' => array_key_exists('skip_github', $params) ? (bool) $params['skip_github'] : true,
112112
'include_repaired_metadata' => ! empty($params['include_repaired_metadata']),
113113
'stale_liveness_only' => ! empty($params['stale_liveness_only']),
114+
'remove_timeout' => isset($params['remove_timeout']) ? (int) $params['remove_timeout'] : null,
114115
)
115116
),
116117
default => new \WP_Error('invalid_cleanup_chunk_type', sprintf('Unknown cleanup chunk type: %s', $chunk_type), array( 'status' => 400 )),

inc/Workspace/Workspace.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class Workspace {
5959
*/
6060
protected const CLEANUP_GIT_PROBE_TIMEOUT = 5;
6161

62+
/**
63+
* Bound destructive git worktree removal separately from cheap probes.
64+
*/
65+
protected const CLEANUP_GIT_REMOVE_TIMEOUT = 60;
66+
6267
/**
6368
* Closed PR pages to inspect per repo during cleanup.
6469
*/

0 commit comments

Comments
 (0)