Skip to content

Commit e54e784

Browse files
authored
Merge pull request #828 from Extra-Chill/issue-826-cleanup-continuation-output
Clarify cleanup restart continuations
2 parents 691bf6b + 665ef1b commit e54e784

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

inc/Workspace/WorkspaceAbandonedCleanupOrchestrator.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,21 @@ private function build_continuation( string $stage, array $step, int $limit, int
520520
'pagination' => $pagination,
521521
);
522522
if ( $restart ) {
523+
$written = (int) ( $step['summary']['written'] ?? 0 );
524+
$removed = (int) ( $step['summary']['removed'] ?? 0 );
525+
523526
$continuation['candidate_set_changed_restart_required'] = true;
524527
$continuation['reason'] = 'candidate_set_changed_restart_required';
528+
$continuation['reason_description'] = 'The previous cleanup pass changed the candidate set, so the next safe continuation intentionally restarts this stage from offset 0.';
529+
$continuation['progress_delta'] = array(
530+
'written' => $written,
531+
'removed' => $removed,
532+
'total_mutations' => $written + $removed,
533+
'previous_offset' => $current,
534+
'restart_offset' => $next_offset,
535+
'candidate_set_now' => 'changed',
536+
);
537+
$continuation['next_command_label'] = 'Restart this stage from offset 0 because the cleanup candidate set changed.';
525538
}
526539

527540
return $continuation;

tests/smoke-abandoned-cleanup-orchestrator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ static function () use ( &$clock_index, $clock_values ): float {
261261
$restart_result = $orchestrator->run(array( 'active_no_signal_drain' => true, 'apply' => true, 'limit' => 10, 'passes' => 1, 'until_budget' => '1s' ));
262262
abandoned_cleanup_assert(! is_wp_error($restart_result), 'active/no-signal restart result succeeds');
263263
abandoned_cleanup_assert(! empty($restart_result['continuation']['candidate_set_changed_restart_required']), 'restart continuation exposes candidate set changed evidence');
264+
abandoned_cleanup_assert('candidate_set_changed_restart_required' === $restart_result['continuation']['reason'], 'restart continuation exposes machine-readable restart reason');
265+
abandoned_cleanup_assert(str_contains((string) $restart_result['continuation']['reason_description'], 'candidate set'), 'restart continuation explains why offset zero is expected');
266+
abandoned_cleanup_assert(1 === (int) $restart_result['continuation']['progress_delta']['written'], 'restart continuation exposes written progress delta');
267+
abandoned_cleanup_assert(1 === (int) $restart_result['continuation']['progress_delta']['total_mutations'], 'restart continuation exposes total mutation progress delta');
268+
abandoned_cleanup_assert(0 === (int) $restart_result['continuation']['progress_delta']['restart_offset'], 'restart continuation exposes the intentional restart offset');
269+
abandoned_cleanup_assert(str_contains((string) $restart_result['continuation']['next_command_label'], 'candidate set changed'), 'restart continuation labels the restart command');
264270
abandoned_cleanup_assert('active-no-signal-drain' === explode(' ', (string) $restart_result['continuation']['next_command'])[5], 'restart next command uses active/no-signal drain');
265271

266272
fwrite(STDOUT, 'abandoned cleanup orchestrator smoke passed' . PHP_EOL);

0 commit comments

Comments
 (0)