Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
65d02dc
Keep fan-out workflow tasks linear in the member count (#1231, #1203)
rmcdaniel Nov 19, 2026
a5be70c
Read a fan-out parent's namespace once per workflow task (#1203)
rmcdaniel Nov 19, 2026
99b7bf1
Weight the fan-out width scaling test for the feature shards
rmcdaniel Nov 19, 2026
6d7cc4c
Cache and retry the fan-out scaling job's Composer install
rmcdaniel Nov 19, 2026
d2e2fc6
Index replay identity checks and keep single lookups early-exit (#1231)
rmcdaniel Nov 19, 2026
439d91c
Merge remote-tracking branch 'origin/main' into general/1231-fanout-q…
rmcdaniel Nov 19, 2026
acf8f23
Batch each started child's call row with the task's published work (#…
rmcdaniel Nov 19, 2026
dd4f1b0
Check pending-member limits against a running bound within a task (#1…
rmcdaniel Nov 19, 2026
a4d199d
Bound each literal fan-out workflow task at 50 s
rmcdaniel Nov 19, 2026
e7d2c87
Run each literal fan-out kind as its own job; report the child case
rmcdaniel Nov 19, 2026
d3ad78d
Merge remote-tracking branch 'origin/main' into general/1231-fanout-q…
rmcdaniel Nov 19, 2026
d118e4e
Make the literal child fan-out job blocking again
rmcdaniel Nov 19, 2026
a29bf78
Keep the literal child fan-out job non-blocking (#1238)
rmcdaniel Nov 19, 2026
a13fcd6
Push batched jobs after commit and never continue a dead batch (#1235…
rmcdaniel Nov 19, 2026
bc358ec
Merge remote-tracking branch 'origin/main' into general/1231-fanout-q…
rmcdaniel Nov 19, 2026
291d99f
Merge branch 'main' into general/1231-fanout-quadratic
rmcdaniel Nov 19, 2026
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
4 changes: 4 additions & 0 deletions .github/feature-test-timings.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"tests/Feature/V2/V2ChildTerminalOutcomeTest.php": 10.083904,
"tests/Feature/V2/V2ChildWorkflowExternalOutputReplayTest.php": 0.475813,
"tests/Feature/V2/V2ChildWorkflowNamespaceProjectionTest.php": 0.230284,
"tests/Feature/V2/V2CoalescedTaskPublishTest.php": 12.0,
"tests/Feature/V2/V2CodFundingMachineTest.php": 671.423589,
"tests/Feature/V2/V2CodMerchantSettlementTest.php": 171.978789,
"tests/Feature/V2/V2CodProcessLossTest.php": 420.587435,
Expand Down Expand Up @@ -121,6 +122,7 @@
"tests/Feature/V2/V2FailedRunRedrivePlanTest.php": 1.295295,
"tests/Feature/V2/V2FailedRunRedriveTest.php": 310.561609,
"tests/Feature/V2/V2FailureMessageStorageMigrationTest.php": 1.444116,
"tests/Feature/V2/V2FanOutWidthScalingTest.php": 420.0,
"tests/Feature/V2/V2FinallyCleanupTest.php": 48.866892,
"tests/Feature/V2/V2FinancialInspectionTest.php": 31.853246,
"tests/Feature/V2/V2FinancialRetainedScopeTest.php": 38.727937,
Expand Down Expand Up @@ -337,6 +339,7 @@
"tests/Feature/V2/V2ChildTerminalOutcomeTest.php": 6.158146,
"tests/Feature/V2/V2ChildWorkflowExternalOutputReplayTest.php": 0.25019,
"tests/Feature/V2/V2ChildWorkflowNamespaceProjectionTest.php": 0.330892,
"tests/Feature/V2/V2CoalescedTaskPublishTest.php": 10.0,
"tests/Feature/V2/V2CodFundingMachineTest.php": 310.971588,
"tests/Feature/V2/V2CodMerchantSettlementTest.php": 81.328249,
"tests/Feature/V2/V2CodProcessLossTest.php": 217.0842,
Expand Down Expand Up @@ -374,6 +377,7 @@
"tests/Feature/V2/V2FailedRunRedrivePlanTest.php": 0.9241,
"tests/Feature/V2/V2FailedRunRedriveTest.php": 184.550012,
"tests/Feature/V2/V2FailureMessageStorageMigrationTest.php": 1.397007,
"tests/Feature/V2/V2FanOutWidthScalingTest.php": 360.0,
"tests/Feature/V2/V2FinallyCleanupTest.php": 34.060109,
"tests/Feature/V2/V2FinancialInspectionTest.php": 17.846207,
"tests/Feature/V2/V2FinancialRetainedScopeTest.php": 25.234874,
Expand Down
126 changes: 126 additions & 0 deletions .github/workflows/fan-out-scaling.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Fan-out scaling

# The literal documented fan-out limit (#1203, #1231): one all() of 1,000
# activities and one of 1,000 child workflows with 10 KB arguments. Each
# workflow task must finish inside the default 60-second queue job
# timeout and cost roughly ten times the 100-member run's. The 30-versus-300
# member guard runs in the ordinary feature shards.

on:
pull_request:
branches: [main]
paths:
- 'src/V2/**'
- 'tests/Performance/FanOutWidthLiteralTest.php'
- 'tests/Support/FanOutWidthProbe.php'
- 'tests/Support/MemberPhaseProjectionRole.php'
- 'tests/Fixtures/V2/TestFanOutPayload*.php'
- '.github/workflows/fan-out-scaling.yml'
schedule:
- cron: '17 4 * * *'
workflow_dispatch:

permissions:
contents: read

concurrency:
group: fan-out-scaling-${{ github.event_name }}-${{ github.event_name == 'pull_request' && github.ref || github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
literal-fan-out:
name: Literal 1,000-member fan-out (${{ matrix.kind }}, ${{ matrix.database }})
runs-on: ubuntu-latest
timeout-minutes: 60
# Starting 1,000 children takes 33-65 s on hosted MySQL runners, around
# the bound (#1238); report it without failing the build until then.
continue-on-error: ${{ matrix.kind == 'children' }}
strategy:
fail-fast: false
matrix:
database: [sqlite, mysql]
kind: [activities, children]

services:
mysql:
image: mysql
env:
MYSQL_ROOT_PASSWORD: password
options: >-
--tmpfs /var/lib/mysql:rw,noexec,nosuid,size=2048m
ports:
- 3306

redis:
image: redis
ports:
- 6379

steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
persist-credentials: false

- name: Cache Composer packages
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5
with:
path: vendor
key: ${{ github.event_name }}-${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ github.event_name }}-${{ runner.os }}-php-

- name: Install dependencies
run: |
for attempt in 1 2 3; do
composer install --prefer-dist --no-progress && exit 0
sleep $((attempt * 20))
done
exit 1

- name: Resolve service endpoints and export test defaults
env:
DATABASE: ${{ matrix.database }}
MYSQL_PUBLISHED_PORT: ${{ job.services.mysql.ports['3306'] }}
REDIS_PUBLISHED_PORT: ${{ job.services.redis.ports['6379'] }}
run: |
{
echo "APP_KEY=base64:i3g6f+dV8FfsIkcxqd7gbiPn2oXk5r00sTmdD6V5utI="
echo "REDIS_HOST=127.0.0.1"
echo "REDIS_PORT=${REDIS_PUBLISHED_PORT}"
echo "REDIS_PASSWORD="
echo "QUEUE_CONNECTION=redis"
echo "QUEUE_FAILED_DRIVER=null"
echo "CACHE_DRIVER=array"
echo "CACHE_STORE=array"
if [ "$DATABASE" = mysql ]; then
echo "DB_CONNECTION=mysql"
echo "DB_HOST=127.0.0.1"
echo "DB_PORT=${MYSQL_PUBLISHED_PORT}"
echo "DB_DATABASE=testbench"
echo "DB_USERNAME=root"
echo "DB_PASSWORD=password"
else
echo "DB_CONNECTION=sqlite"
echo "DB_DATABASE=${RUNNER_TEMP}/fan-out-scaling.sqlite"
fi
} >> "$GITHUB_ENV"

- name: Create the database
run: |
if [ "$DB_CONNECTION" = mysql ]; then
mysql -e 'CREATE DATABASE testbench' -h"$DB_HOST" -uroot -ppassword -P "$DB_PORT"
else
touch "$DB_DATABASE"
fi

- name: Run the literal 1,000-member fan-out
run: >-
vendor/bin/phpunit --no-coverage --fail-on-skipped
--filter "testLiteralThousandMemberFanOut@${KIND}"
--log-junit build/test-results/fan-out-scaling.xml
tests/Performance/FanOutWidthLiteralTest.php
env:
FANOUT_LITERAL: '1'
KIND: ${{ matrix.kind }}
XDEBUG_MODE: off
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,25 @@ in a minor release: `DurableScope::reserveChild()`, original root admission
The activity calls and their order are unchanged, so recorded commands are the
same. Examples only.

- A wide `all()` no longer makes its workflow tasks grow with the square of the
fan-out width (#1231, #1203). A 300-member fan-out of 10 KB activities took
134 s to schedule and 58–85 s to finish on 2.32.0, so Laravel's default
60-second queue job timeout killed it on every retry. Per-member cost is now
roughly constant:
- A workflow task publishes the tasks it committed in bounded batches and
refreshes each affected run summary once, instead of rebuilding the run's
whole summary, in its own transaction, for every member it published.
- Replay, child-call, parallel-group, lineage and activity lookups index the
loaded history by sequence once, instead of rescanning the whole history
for every member. A child closure no longer rescans the parent's history
for every sibling.
- Activity starts refresh only their own timeline points, like outcomes, and
projections skip decoding payloads that cannot name the activity or a
failure.

Recorded history and every projection row are unchanged. Each member's own
activity or child task still rebuilds its run summary once.

## 2.32.0 - 2026-11-19

Compensation scopes remain **experimental** in 2.32.0, without a
Expand Down
11 changes: 11 additions & 0 deletions src/V2/Jobs/RunWorkflowTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Workflow\V2\Support\TaskCompatibility;
use Workflow\V2\Support\TaskDispatcher;
use Workflow\V2\Support\TaskOutcomeCarrier;
use Workflow\V2\Support\TaskScopeMemo;
use Workflow\V2\Support\TaskTraceTimings;
use Workflow\V2\Support\TraceCarrier;
use Workflow\V2\Support\WorkerCompatibilityFleet;
Expand Down Expand Up @@ -55,6 +56,16 @@
}

public function handle(WorkflowExecutor $executor): void
{
// A fan-out publishes one task per member after commit. Refresh each
// affected run summary once for the whole task, and repeat a member's
// immutable lookups at most once per task (#1203, #1231).
TaskScopeMemo::scope(
fn () => TaskDispatcher::coalescingRunSummaries(fn () => $this->handleTask($executor)),
);
}

private function handleTask(WorkflowExecutor $executor): void

Check warning on line 68 in src/V2/Jobs/RunWorkflowTask.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This method has 4 returns, which is more than the 3 allowed.

See more on https://sonarcloud.io/project/issues?id=durable-workflow_workflow&issues=AaHzWuQKpXvIZvq32Ng9&open=AaHzWuQKpXvIZvq32Ng9&pullRequest=1235
{
// Apps sharing a database and queue names can receive each other's
// jobs. Refuse a task outside this app's namespaces before any effect.
Expand Down
75 changes: 50 additions & 25 deletions src/V2/Support/ActivityReplayIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Workflow\V2\Enums\HistoryEventType;
use Workflow\V2\Exceptions\ActivityRetryPolicyMismatchException;
use Workflow\V2\Models\WorkflowHistoryEvent;
use Workflow\V2\Models\WorkflowRun;

final class ActivityReplayIdentity
Expand Down Expand Up @@ -41,34 +42,21 @@ public static function assertCall(
if (! $run->relationLoaded('historyEvents')) {
$run->load('historyEvents');
}
foreach ($run->historyEvents as $event) {
if ($event->event_type !== HistoryEventType::ActivityScheduled) {
continue;
}

$recordedSequence = $event->payload['sequence'] ?? null;
if (is_string($recordedSequence) && is_numeric($recordedSequence)) {
$recordedSequence = (int) $recordedSequence;
}
if ($recordedSequence !== $sequence
|| ($event->payload['execution_mode'] ?? null) === LocalActivityRuntime::EXECUTION_MODE
|| ($event->payload['activity']['execution_mode'] ?? null) === LocalActivityRuntime::EXECUTION_MODE) {
continue;
}

$snapshot = $event->payload['activity']['retry_policy'] ?? $event->payload['retry_policy'] ?? null;
if ($snapshot === null) {
// Legacy absence is not an invitation to invent today's class defaults.
return;
}
if (! is_array($snapshot)) {
throw new ActivityRetryPolicyMismatchException($sequence, 'retry_policy');
}

self::assertPolicy($snapshot, $call->options, $sequence);
$event = self::scheduledEventForSequence($run, $sequence);
if (! $event instanceof WorkflowHistoryEvent) {
return;
}

$snapshot = $event->payload['activity']['retry_policy'] ?? $event->payload['retry_policy'] ?? null;
if ($snapshot === null) {
// Legacy absence is not an invitation to invent today's class defaults.
return;
}
if (! is_array($snapshot)) {
throw new ActivityRetryPolicyMismatchException($sequence, 'retry_policy');
}

self::assertPolicy($snapshot, $call->options, $sequence);
}

/**
Expand Down Expand Up @@ -129,4 +117,41 @@ public static function assertPolicy(array $snapshot, ?ActivityOptions $options,
}
}
}

/**
* The first non-local ActivityScheduled event for a recorded sequence, in
* history order. Every member of a replayed fan-out is checked, so the
* loaded history is indexed as far as each lookup needs instead of
* scanned per member (#1231).
*/
private static function scheduledEventForSequence(WorkflowRun $run, int $sequence): ?WorkflowHistoryEvent
{
/** @var WorkflowHistoryEvent|null $event */
$event = HistoryEventIndex::find(
$run->historyEvents,
'activity-scheduled-event-by-sequence',
$sequence,
static function (mixed $event): array {
if ($event->event_type !== HistoryEventType::ActivityScheduled) {
return [];
}

$recordedSequence = $event->payload['sequence'] ?? null;
if (is_string($recordedSequence) && is_numeric($recordedSequence)) {
$recordedSequence = (int) $recordedSequence;
}
if (! is_int($recordedSequence)
|| ($event->payload['execution_mode'] ?? null) === LocalActivityRuntime::EXECUTION_MODE
|| ($event->payload['activity']['execution_mode'] ?? null) === LocalActivityRuntime::EXECUTION_MODE) {
return [];
}

return [
$recordedSequence => $event,
];
},
);

return $event;
}
}
Loading