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
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,41 @@ project follows [Semantic Versioning](https://semver.org/).
activity retry policy is unchanged, because retrying a non-idempotent
activity by default could repeat its side effects.

### Changed

- The default transport asks for gzip on every request when it owns a Guzzle
client with cURL and zlib, and decodes a gzip body a custom client left
encoded. Servers that compress (PHP Server, and native Server with its
response compression) then send several times fewer bytes.
- Worker requests send `X-Durable-Workflow-Server-Capabilities-Digest`. A
Server that supports it replaces repeated `server_capabilities` objects
(about 17 KB on native, sent on every worker answer and again inside
carried polls) with their digest, and the transport restores the held object
before any caller sees the answer. Older Servers ignore the header. An
answer naming a digest the transport does not hold is recovered without
repeating any request that may have changed state: that answer is kept as
received (a completion's answer can carry the next leased task), the
capabilities are read from `GET /api/cluster/info`, and the held pair is
forgotten. Only a task poll is sent again without the header. A digest in
an error body never replaces the HTTP error.
- A gzip response is inflated by the transport within a decoded-size limit
(`Psr18Transport` `maxDecodedResponseBytes`; by default 32 MiB, or a quarter
of `memory_limit` when that is lower). A larger body fails with
`DurableWorkflow\Exception\ResponseTooLarge`, which reaches callers as
itself.
- A `409 stale_attempt` that proves this Worker's own activity completion was
already committed (`recorded: false`, its owner and attempt, every status
`completed`) is accepted as committed on any answer: the first, after a
transient failure, or a resend by the HTTP client.
- `result()` of a completed run reads the output from the terminal status
read instead of downloading the run's whole history again. Failed,
cancelled, terminated and timed-out runs, and Servers that omit
`output_envelope`, still read the history.

In a lab DW Standard Workflow v1 run (native Server with compression and the
digest, 1 workflow/second), response bytes per workflow went from about
385 KB to about 18 KB.

## [3.22.0] - 2026-11-19

Signal-with-start and durable signal-external need native Server 3.15.0 or
Expand Down
28 changes: 21 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use DurableWorkflow\Exception\QueryFailed;
use DurableWorkflow\Exception\ScheduleAlreadyExists;
use DurableWorkflow\Exception\ServerCapabilityUnavailable;
use DurableWorkflow\Exception\ResponseTooLarge;
use DurableWorkflow\Exception\ServerException;
use DurableWorkflow\Exception\SignalFailed;
use DurableWorkflow\Exception\SignalWithStartFailed;
Expand Down Expand Up @@ -3495,7 +3496,8 @@ private function performRequest(
return $this->resolveResponsePayloads($response, $path, $worker, $body, $headers,
$budget, $callerBudget, $poll, $payloadPaths);
} catch (TransportException $exception) {
if ($exception instanceof FailureReportRefused) {
if ($exception instanceof FailureReportRefused || $exception instanceof ResponseTooLarge) {
// Typed transport outcomes reach the caller as themselves.
throw $exception;
}
$details = $exception->response;
Expand Down Expand Up @@ -3573,7 +3575,8 @@ private function carriedPollResponse(array $answer, array $request, string $path
$this->requestHeaders(true), $this->boundedWorkerRequests ? new RequestBudget(5) : null,
null, true, null);
} catch (TransportException $exception) {
if ($exception instanceof FailureReportRefused) {
if ($exception instanceof FailureReportRefused || $exception instanceof ResponseTooLarge) {
// Typed transport outcomes reach the caller as themselves.
throw $exception;
}
$details = $exception->response;
Expand Down Expand Up @@ -3634,6 +3637,12 @@ private function terminalResult(
string $status,
WorkflowExecution $execution,
): mixed {
if ($status === 'completed' && is_array($execution->raw['output_envelope'] ?? null)
&& ($execution->raw['run_id'] ?? null) === $runId) {
// The terminal read already names the run's output; reading the
// whole history again only repeats it.
return $this->completedRunOutput($workflowId, $runId, $execution);
}
$history = $this->request(
'GET', '/workflows/'.$this->segment($workflowId).'/runs/'.$this->segment($runId).'/history', false,
payloadPaths: self::terminalHistoryPayloadPaths(...),
Expand Down Expand Up @@ -3673,18 +3682,23 @@ private function terminalResult(
}

return match ($status) {
'completed' => $this->decodedResponsePayload(
(new RuntimePayloads($this->transport, $this->baseUri, $this->requestHeaders(false), $this->maxExternalPayloadBytes))
->response($execution->raw, '/workflows/'.$this->segment($workflowId).'/runs/'.$this->segment($runId), false, [['output_envelope']]),
'output',
),
'completed' => $this->completedRunOutput($workflowId, $runId, $execution),
'cancelled', 'canceled' => throw new WorkflowCancelled('Workflow was cancelled.'),
'terminated' => throw new WorkflowTerminated('Workflow was terminated.'),
'timed_out', 'timeout' => throw new WorkflowTimedOut('Workflow execution timed out.'),
default => throw new WorkflowFailed('Workflow failed.'),
};
}

private function completedRunOutput(string $workflowId, string $runId, WorkflowExecution $execution): mixed
{
return $this->decodedResponsePayload(
(new RuntimePayloads($this->transport, $this->baseUri, $this->requestHeaders(false), $this->maxExternalPayloadBytes))
->response($execution->raw, '/workflows/'.$this->segment($workflowId).'/runs/'.$this->segment($runId), false, [['output_envelope']]),
'output',
);
}

/** @param array<string, mixed> $response
* @return list<list<int|string>>
*/
Expand Down
15 changes: 15 additions & 0 deletions src/Exception/ResponseTooLarge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace DurableWorkflow\Exception;

/** A compressed response decoded to more bytes than the transport accepts. */
final class ResponseTooLarge extends TransportException
{
public function __construct(public readonly int $limitBytes)
{
parent::__construct("The server response decodes to more than {$limitBytes} bytes.",
response: ['reason' => 'response_too_large', 'limit_bytes' => $limitBytes]);
}
}
Loading