Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/feature-test-timings.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
"tests/Feature/V2/V2TerminalReasonDiagnosticsTest.php": 23.591816,
"tests/Feature/V2/V2TimeoutCleanupAdmissionTest.php": 4.969863,
"tests/Feature/V2/V2TimeoutCleanupMigrationTest.php": 10.047079,
"tests/Feature/V2/V2TimeoutCleanupSummaryMigrationTest.php": 10.047079,
"tests/Feature/V2/V2TimeoutCleanupTest.php": 22.127049,
"tests/Feature/V2/V2TimerDeadlineMigrationTest.php": 35.432759,
"tests/Feature/V2/V2TimerWorkflowTest.php": 12.113366,
Expand Down Expand Up @@ -498,6 +499,7 @@
"tests/Feature/V2/V2TerminalReasonDiagnosticsTest.php": 1.951918,
"tests/Feature/V2/V2TimeoutCleanupAdmissionTest.php": 7.510203,
"tests/Feature/V2/V2TimeoutCleanupMigrationTest.php": 2.120066,
"tests/Feature/V2/V2TimeoutCleanupSummaryMigrationTest.php": 2.120066,
"tests/Feature/V2/V2TimeoutCleanupTest.php": 15.088411,
"tests/Feature/V2/V2TimerDeadlineMigrationTest.php": 7.377256,
"tests/Feature/V2/V2TimerWorkflowTest.php": 12.996575,
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## Unreleased

- Run lists show the timeout cleanup outcome (#863). The run summary gains a
nullable `timeout_cleanup` JSON column holding what describe returns under
`run.timeout_cleanup` (`outcome: running` while cleanup is open, then the
recorded `completed`, `failed`, `expired` or `preempted` outcome), and
`RunListItemView` returns it, null when no cleanup was recorded. Migration
`2026_11_26_000100_add_timeout_cleanup_to_workflow_run_summaries` adds the
column outside the migrator transaction under the schema lock budget, with
no backfill. To fill it for opted-in runs that closed before the upgrade,
rebuild them with `workflow:v2:rebuild-projections --run-id=...`.

## 2.42.0 - 2026-11-26

2.42.0 has no database migration. It adds a replay-aware workflow logger,
Expand Down
11 changes: 11 additions & 0 deletions docs/architecture/timeout-cleanup.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ history export. When no cleanup was recorded, the response omits the field.
An expired outcome can omit `started_at` if the first detection was already
past the hard deadline.

Run lists carry the same value. The run summary (`workflow_run_summaries`)
stores it in a nullable `timeout_cleanup` JSON column, written whenever the
whole run is projected, which includes cleanup entry and every close, so
Waterline's run list and `RunListItemView` return `timeout_cleanup`, null
when no cleanup was recorded. The column is added without a backfill. A
summary projected before the upgrade gains the value the next time its run is
projected; an already closed opted-in run (`workflow_runs` with
`timeout_cleanup_work_deadline_at` set) keeps null until
`workflow:v2:rebuild-projections --run-id=...` rebuilds it. Describe, run
detail and the observation read history and are correct either way.

## Defaults and compatibility

- Without `withTimeoutCleanup()`, nothing changes: the hard timeout closes
Expand Down
1 change: 1 addition & 0 deletions src/V2/Models/WorkflowRunSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class WorkflowRunSummary extends Model
'is_current_run' => 'bool',
'repair_attention' => 'bool',
'task_attention' => 'array',
'timeout_cleanup' => 'array',
'task_problem' => 'bool',
'visibility_labels' => 'array',
'projection_schema_version' => 'integer',
Expand Down
7 changes: 7 additions & 0 deletions src/V2/Support/RunListItemView.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public static function fromSummary(WorkflowRunSummary $summary): array
'task_attention' => array_key_exists('task_attention', $summary->getAttributes())
? $summary->task_attention
: null,
// Additive (#863): the timeout cleanup state describe returns
// under run.timeout_cleanup; null when none was recorded.
'timeout_cleanup' => array_key_exists(TimeoutCleanup::SUMMARY_COLUMN, $summary->getAttributes())
&& is_array($summary->getAttribute(TimeoutCleanup::SUMMARY_COLUMN))
? $summary->getAttribute(TimeoutCleanup::SUMMARY_COLUMN)
: null,
'task_problem' => (bool) $summary->task_problem,
'task_problem_badge' => WorkflowTaskProblem::metadata(
(bool) $summary->task_problem,
Expand Down Expand Up @@ -149,6 +155,7 @@ public static function fields(): array
'repair_blocked_reason',
'repair_blocked',
'task_attention',
'timeout_cleanup',
'task_problem',
'task_problem_badge',
'declared_entry_mode',
Expand Down
3 changes: 3 additions & 0 deletions src/V2/Support/RunSummaryProjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ public static function project(WorkflowRun $run, bool $disposableRun = false): W
'repair_blocked_reason' => $repairBlockedReason,
'repair_attention' => RepairBlockedReason::needsAttention($repairBlockedReason),
...WorkflowTaskLeaseLoss::summaryAttributes($run),
// Cleanup is entered and closed only by transitions that
// project the whole run, so bounded projections keep it.
...TimeoutCleanup::summaryAttributes($run),
'task_problem' => $taskProblem,
'exception_count' => count($failureSnapshots),
'history_event_count' => $historyBudget['history_event_count'],
Expand Down
29 changes: 29 additions & 0 deletions src/V2/Support/TimeoutCleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ final class TimeoutCleanup
*/
public const STARTED_KEY = 'timeout_cleanup';

/**
* The additive `workflow_run_summaries` column and list-item field.
*/
public const SUMMARY_COLUMN = 'timeout_cleanup';

public static function assertEmbeddedAdmission(?int $allowanceSeconds): void
{
if ($allowanceSeconds !== null && config('workflows.v2.task_dispatch_mode') === 'poll') {
Expand Down Expand Up @@ -257,6 +262,30 @@ public static function observe(WorkflowRun $run, mixed $startedPayload): ?array
])), is_string(...));
}

/**
* The run summary's additive `timeout_cleanup` attribute: what `observe`
* returns, so run lists match describe and the run observation. None
* when the summary table has no such column.
*
* @return array<string, array<string, string>|null>
*/
public static function summaryAttributes(WorkflowRun $run): array
{
if (! WorkflowTaskLeaseLoss::summaryHasColumn(self::SUMMARY_COLUMN)) {
return [];
}

$started = $run->relationLoaded('historyEvents')
? $run->historyEvents->first(
static fn (WorkflowHistoryEvent $event): bool => $event->event_type === HistoryEventType::WorkflowStarted
)
: null;

return [
self::SUMMARY_COLUMN => self::observe($run, $started?->payload),
];
}

/**
* @return array{0: string|null, 1: CarbonInterface|null}
*/
Expand Down
30 changes: 22 additions & 8 deletions src/V2/Support/WorkflowTaskLeaseLoss.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* actions are unchanged. Failing the run instead is opt-in. None of this
* writes history or changes how a run whose task completes behaves.
*/
final class WorkflowTaskLeaseLoss

Check warning on line 34 in src/V2/Support/WorkflowTaskLeaseLoss.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Class "WorkflowTaskLeaseLoss" has 21 methods, which is greater than 20 authorized. Split it into smaller classes.

See more on https://sonarcloud.io/project/issues?id=durable-workflow_workflow&issues=AaIYwSi_TgEXewAd4OED&open=AaIYwSi_TgEXewAd4OED&pullRequest=1313
{
public const CODE = 'workflow_task_lease_lost';

Expand All @@ -50,6 +50,12 @@
*/
private const SCHEMA_RECHECK_SECONDS = 60;

/**
* Run-summary columns added after the table, which a schema rollback can
* remove again.
*/
private const ADDITIVE_SUMMARY_COLUMNS = ['task_attention', TimeoutCleanup::SUMMARY_COLUMN];

/**
* @var array<string, array{tracked: bool, checked_at: int}>
*/
Expand Down Expand Up @@ -284,7 +290,16 @@
*/
public static function summaryTracked(bool $fresh = false): bool
{
return self::hasColumn(self::summaryModel(), 'task_attention', $fresh);
return self::summaryHasColumn('task_attention', $fresh);
}

/**
* Whether the configured run-summary table has an additive column, with
* the same cached, rollback-aware check as `task_attention`.
*/
public static function summaryHasColumn(string $column, bool $fresh = false): bool
{
return self::hasColumn(self::summaryModel(), $column, $fresh);
}

/**
Expand Down Expand Up @@ -317,11 +332,12 @@
}

/**
* Write a run summary whose values may carry task_attention.
* Write a run summary whose values may carry an additive column
* (`task_attention`, `timeout_cleanup`).
*
* A schema rollback can drop the column while the cached check still
* A schema rollback can drop such a column while the cached check still
* reports it. On that error the cache is forgotten and $write runs again
* without task_attention. A failed statement aborts a caller's open
* without the additive columns. A failed statement aborts a caller's open
* PostgreSQL transaction, so there the error is rethrown instead and the
* caller's retry sees the current schema.
*
Expand All @@ -332,7 +348,7 @@
*/
public static function writeSummary(array $values, callable $write): mixed
{
if (! array_key_exists('task_attention', $values)) {
if (array_intersect_key($values, array_flip(self::ADDITIVE_SUMMARY_COLUMNS)) === []) {
return $write($values);
}

Expand All @@ -350,9 +366,7 @@
throw $exception;
}

unset($values['task_attention']);

return $write($values);
return $write(array_diff_key($values, array_flip(self::ADDITIVE_SUMMARY_COLUMNS)));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
use Illuminate\Support\Facades\Schema;
use Workflow\Support\WorkflowMigration;
use Workflow\V2\Models\WorkflowRunSummary;
use Workflow\V2\Support\ConfiguredV2Models;

return new class() extends WorkflowMigration {
private const COLUMN = 'timeout_cleanup';

/**
* Deadline-triggered cleanup (#863): the run summary's additive
* `timeout_cleanup` field, the same portable shape describe and the run
* observation return, so run lists show the cleanup outcome.
*
* The column is nullable and nothing is backfilled: a summary gains the
* value the next time it is projected. The summary table is hot, so the
* column is added outside the migrator transaction under the schema lock
* budget, and a repeated run skips work already done.
*/
public $withinTransaction = false;

public function up(): void
{
$schema = $this->schema();

foreach ($this->summaryTables($schema, withColumn: false) as $table) {
$this->withSchemaLockBudget(static fn () => $schema->table(
$table,
static fn (Blueprint $blueprint) => $blueprint->json(self::COLUMN)
->nullable(),
));
}
}

public function down(): void
{
$schema = $this->schema();

foreach ($this->summaryTables($schema, withColumn: true) as $table) {
$schema->table($table, static fn (Blueprint $blueprint) => $blueprint->dropColumn(self::COLUMN));
}
}

private function schema(): Builder
{
return Schema::connection($this->getConnection());
}

/**
* The existing run-summary tables (the package table and a configured
* model's table) that have, or lack, the column.
*
* @return list<string>
*/
private function summaryTables(Builder $schema, bool $withColumn): array
{
$model = ConfiguredV2Models::resolve('run_summary_model', WorkflowRunSummary::class);
$tables = array_unique(['workflow_run_summaries', (new $model())->getTable()]);

return array_values(array_filter(
$tables,
static fn (string $table): bool => $schema->hasTable($table)
&& $schema->hasColumn($table, self::COLUMN) === $withColumn,
));
}
};
46 changes: 46 additions & 0 deletions tests/Feature/V2/V2EmbeddedReplayRegressionCorpusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,47 @@ public function testTimeoutCleanupObservationCorpusKeepsTheRecordedClockAndOutco
$this->assertEquals($scenario['terminal'], $observer->runDetail($run)['timeout_cleanup'] ?? null);
}

public function testTimeoutCleanupSummaryCorpusListsTheRecordedOutcome(): void
{
$path = self::FIXTURE_DIR . '/timeout-cleanup-summary-listed.json';
if (! is_file($path)) {
$this->markTestSkipped('The timeout cleanup summary evidence is absent.');
}
$fixture = json_decode((string) file_get_contents($path), true, flags: JSON_THROW_ON_ERROR);
$scenario = $fixture['summary'];
config([
'queue.default' => 'database',
]);
Queue::fake();
$this->travelTo(Carbon::parse($fixture['history'][0]['recorded_at']));
$stub = WorkflowStub::make($fixture['workflow']['type'], $fixture['id']);
$stub->start($fixture['workflow']['arguments'][0], new StartOptions(
executionTimeoutSeconds: $scenario['execution_timeout_seconds'],
timeoutCleanupSeconds: $scenario['timeout_cleanup_seconds'],
));
$runId = $stub->runId();
$this->runReadyTaskOfType($runId, TaskType::Workflow);
$observer = $this->app->make(OperatorObservabilityRepository::class);
$listed = static fn (): mixed => $observer->listItem(
WorkflowRunSummary::query()->findOrFail($runId)
)['timeout_cleanup'];
$this->assertNull($listed());

// The watchdog enters cleanup and projects the run.
$this->travel($scenario['detect_after_seconds'])->seconds();
TaskWatchdog::runPass(runIds: [$runId]);
$this->assertEquals($scenario['running'], $listed());

// The cleanup turn returns; the close projects the recorded outcome.
$this->runReadyTaskOfType($runId, TaskType::Workflow);
$this->assertSame(RunStatus::Failed, WorkflowRun::query()->findOrFail($runId)->status);
$this->assertEquals($scenario['terminal'], $listed());
$this->assertEquals(
$scenario['terminal'],
WorkflowRunSummary::query()->findOrFail($runId)->toArray()['timeout_cleanup']
);
}

public function testTimeoutCleanupTaskExpiryCorpusKeepsTheOutcome(): void
{
$path = self::FIXTURE_DIR . '/timeout-cleanup-task-expiry.json';
Expand Down Expand Up @@ -3303,6 +3344,11 @@ public function testFixturesExecuteThroughDeclaredReplayConsumers(): void
continue;
}

if ($fixture['id'] === 'timeout-cleanup-summary-listed') {
// The live projection at entry and close runs in the dedicated corpus test.
continue;
}

if ($fixture['id'] === 'version-usage-retained-reused-decision') {
config()->set('app.key', 'version-usage-corpus-signing-key');
$this->assertVersionUsageRetainedDecision($fixture);
Expand Down
Loading