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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ all three runtimes and the artifact versions used for the run.
The qualified tuple in
[`polyglot/qualified-artifact-tuple.json`](polyglot/qualified-artifact-tuple.json)
pins every published artifact the journeys use: native Durable Workflow Server
3.0.5 (by image digest), Workflow 2.20.1, Waterline 2.13.2, PHP SDK 3.9.1,
3.0.5 (by image digest), Workflow 2.20.1, Waterline 2.13.2, PHP SDK 3.9.4,
Python SDK 2.13.0, Rust SDK 4.10.3 and CLI 2.3.3. `artifacts.workflow` selects
the embedded application's Composer package; the Composer lock must match it.
Native Server is one process that creates its schema and `default` namespace
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"require": {
"php": "^8.4",
"durable-workflow/ai": "dev-main",
"durable-workflow/sdk": "^3.9.1",
"durable-workflow/sdk": "^3.9.4",
"durable-workflow/waterline": "^2.0",
"durable-workflow/workflow": "^2.20.1",
"laravel/ai": "^0.6.0",
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion microservice/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "MIT",
"require": {
"php": "^8.4",
"durable-workflow/sdk": "^3.9.1",
"durable-workflow/sdk": "^3.9.4",
"durable-workflow/workflow": "^2.20.1",
"durable-workflow/waterline": "^2.0",
"laravel/framework": "^12.69",
Expand Down
16 changes: 8 additions & 8 deletions microservice/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion playground/php-runtime/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "MIT",
"require": {
"php": "^8.4",
"durable-workflow/sdk": "^3.9.1"
"durable-workflow/sdk": "^3.9.4"
},
"config": {
"allow-plugins": false,
Expand Down
16 changes: 8 additions & 8 deletions playground/php-runtime/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion polyglot/qualified-artifact-tuple.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"serverImage": "durableworkflow/server:3.0.5@sha256:3cb6e5bf8ec766ac2abd933369b40a77af62794b6d7b921ce21d3fb263e88b72",
"artifacts": {
"cli": "2.3.3",
"sdk-php": "3.9.1",
"sdk-php": "3.9.4",
"sdk-python": "2.13.0",
"sdk-rust": "4.10.3",
"server": "3.0.5",
Expand Down
110 changes: 107 additions & 3 deletions tests/Feature/Workflows/ServiceMode/ConversationWorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Workflows\ServiceMode\Conversation\ConversationActivities;
use App\Workflows\ServiceMode\Conversation\ConversationWorkflow;
use App\Workflows\ServiceMode\WelcomeWorkflow;
use DateTimeImmutable;
use DurableWorkflow\Bridge\Laravel\WorkerFactory;
use DurableWorkflow\Client;
use DurableWorkflow\Codec\AvroPayloadCodec;
Expand Down Expand Up @@ -50,6 +51,8 @@ final class ConversationWorkflowTest extends TestCase

private int $nextSequence = 1;

private DateTimeImmutable $clock;

/** @var array{type: string, value: mixed}|null */
private ?array $closed = null;

Expand Down Expand Up @@ -163,6 +166,71 @@ public function test_undecided_proposal_changes_nothing_after_its_timeout(): voi
$this->assertSame(0, ConversationRecord::query()->where('kind', 'action')->count());
}

public function test_a_wrong_decision_keeps_the_five_minute_approval_deadline(): void
{
$this->start([]);
$this->signal('message', 'Please refund my order');
$this->assertSame(300, $this->lastEvent('ConditionWaitOpened')['timeout_seconds']);

// Any signal wakes the open wait. The predicate is still false, so the
// worker reopens the wait with the time left, not another five minutes.
$this->advance(120);
$this->signal('decision', 'not-this-proposal', true, 'Stale');
$reopened = $this->lastEvent('ConditionWaitOpened');
$this->assertSame('decision-1', $reopened['condition_key']);
$this->assertSame(180, $reopened['timeout_seconds']);

$this->advance(150);
$this->signal('decision', 'still-not-this-proposal', true, 'Stale');
$this->assertSame(30, $this->lastEvent('ConditionWaitOpened')['timeout_seconds']);

$this->advance(30);
$this->timeOutOpenWait();

$this->assertSame(
['Turn 1: I can refund the most recent order once a reviewer approves. No decision arrived in time, so nothing was changed.'],
$this->replies(),
);
}

public function test_an_orphaned_duplicate_wait_timing_out_does_not_break_replay(): void
{
$this->start([]);
$this->signal('message', 'Please refund my order');
$orphan = $this->lastEvent('ConditionWaitOpened');

// A second queued workflow task replays to the open wait and sends it
// again. Native Server 3.0.x opens another wait and leaves the first
// one, with its timer, unresolved (sdk-php#283).
$this->duplicateOpen();
$this->assertNotSame($orphan['sequence'], $this->lastEvent('ConditionWaitOpened')['sequence']);

$this->advance(120);
$this->signal('decision', 'not-this-proposal', true, 'Stale');
$this->assertSame(180, $this->lastEvent('ConditionWaitOpened')['timeout_seconds']);

// The orphan's timer fires at its own five minutes. Replay must keep
// treating it as the same logical wait instead of failing.
$this->advance(180);
$this->record('TimerFired', [
'sequence' => $orphan['sequence'],
'timer_kind' => 'condition_timeout',
'condition_key' => $orphan['condition_key'],
'condition_wait_id' => $orphan['condition_wait_id'],
'condition_definition_fingerprint' => $orphan['condition_definition_fingerprint'],
'delay_seconds' => 300,
]);
$this->process();
$this->assertNull($this->closed);

$this->timeOutOpenWait();

$this->assertSame(
['Turn 1: I can refund the most recent order once a reviewer approves. No decision arrived in time, so nothing was changed.'],
$this->replies(),
);
}

public function test_conversation_ends_after_the_inactivity_timeout(): void
{
$this->start([]);
Expand Down Expand Up @@ -227,6 +295,7 @@ private function start(array $input): void
{
$this->history = [];
$this->nextSequence = 1;
$this->clock = new DateTimeImmutable('2026-11-04T02:36:05.295+00:00');
$this->closed = null;
$this->input = $input;
$this->process();
Expand All @@ -235,7 +304,29 @@ private function start(array $input): void
private function signal(string $name, mixed ...$arguments): void
{
$this->record('SignalReceived', ['signal_name' => $name, 'value' => $this->codec->envelope($arguments)]);
$this->process();
$this->process(woken: true);
}

/**
* Replays the history again with nothing new, as a second queued task
* would, and records the wait it sends as a new open.
*/
private function duplicateOpen(): void
{
$commands = $this->harness->runWorkflow(
ConversationWorkflow::TYPE,
$this->input,
$this->history,
['workflow_id' => self::WORKFLOW_ID, 'run_id' => self::RUN_ID],
)->commands;

$this->assertSame('open_condition_wait', $commands[0]['type'] ?? null);
$this->apply($commands[0]);
}

private function advance(int $seconds): void
{
$this->clock = $this->clock->modify("+{$seconds} seconds");
}

private function timeOutOpenWait(): void
Expand All @@ -248,8 +339,12 @@ private function timeOutOpenWait(): void

/**
* Runs workflow tasks until the workflow waits or closes.
*
* After a signal, a worker whose predicate is still false sends the open
* wait again. Native Server then records the old wait satisfied and opens
* a new one with the timeout the worker sent.
*/
private function process(): void
private function process(bool $woken = false): void
{
for ($task = 0; $task < 50 && $this->closed === null; $task++) {
$commands = $this->harness->runWorkflow(
Expand All @@ -266,6 +361,11 @@ private function process(): void
&& $commands[0]['condition_key'] === $wait['condition_key'];

if ($stillWaiting) {
if ($woken) {
$this->record('ConditionWaitSatisfied', ['sequence' => $wait['sequence'], 'condition_wait_id' => $wait['condition_wait_id']]);
$this->apply($commands[0]);
}

return;
}

Expand Down Expand Up @@ -333,7 +433,11 @@ private function apply(array $command): void
*/
private function record(string $type, array $payload): void
{
$this->history[] = ['event_type' => $type, 'payload' => $payload];
$this->history[] = [
'event_type' => $type,
'timestamp' => $this->clock->format('Y-m-d\\TH:i:s.uP'),
'payload' => $payload,
];
}

/**
Expand Down
Loading