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
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ project follows [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Added

- `enableActivityContinuation` consumes activity workflow continuation v2
(#500, server#1181) when a native Server advertises it. Version 2 is
preferred over version 1, and version 1 stays the fallback. The worker seeds
its sticky cache from the `continuation_tail` a workflow task completion
returns. It then speculates the next workflow task from the cache plus its
own activity result, with no history request. Each accepted answer's tail
keeps the cache exact. The answer can carry the next activity, which runs in
the same tick. A tail that does not continue the cache evicts the entry. An
omitted tail keeps the old boundary, and the leased activity completes the
ordinary way. Declines process the carried workflow poll, and refusals send
the ordinary completion with the same poll. An unknown outcome resends the
identical v2 request. A malformed `v2` member disables version 2 only. The
option stays off by default. Continuations are unqualified and may cost
throughput until the server#1181 benchmark passes. See the
[worker guide](docs/portal/build/workers.md#activity-continuation-version-2).

## [3.32.0] - 2026-11-26

### Fixed
Expand Down
69 changes: 69 additions & 0 deletions docs/portal/build/workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,75 @@ completion outcomes follow completion error/recovery rules. They do not become
eligibility declines. Drain or disable opted-in workers before downgrading a
producer or introducing older serving nodes. No speedup is promised.

**Continuations are unqualified.** Enabling them may cost throughput. The
[server#1078](https://github.com/durable-workflow/server/issues/1078) A/B
measured version 1 as slower than the ordinary path under load. Version 2 must
pass the [server#1181](https://github.com/durable-workflow/server/issues/1181)
benchmark before the option can become a default. Until then it stays off.

### Activity continuation version 2

A native Server that implements version 2 advertises it inside the same
capability, as `supported_versions` containing `2` and a `v2` member. The
worker uses version 2 when all of these hold:

- `enableActivityContinuation` is on;
- the `v2` member is well formed, with `version` exactly `2` and the expected
`complete_endpoint`;
- the registration negotiated sticky history suffixes;
- no worker interceptors are configured.

A malformed `v2` member turns off version 2 only. Version 1 stays the fallback
when version 2 is not advertised, or after a Server refuses it with
`unsupported_continuation_version`. That refusal holds until the worker
registers again.

Version 2 speculates from the worker's sticky cache and never asks the Server
for history:

1. A workflow task completion with a cached boundary asks for
`continuation_tail`. The Server answers with the events it wrote after that
boundary. With a tail requested, the carried activity poll leases only an
activity this completion created.
2. The worker appends the tail only when it continues the cache exactly. A tail
that does not continue the cache evicts the run's entry. An omitted tail
(over a Server budget, or `tail_unavailable` on a retry) keeps the old
boundary.
3. After an activity succeeds, the worker sends version 2 only when the cache
starts with `WorkflowStarted`, is contiguous, and ends in this attempt's
`ActivityStarted`. It also needs a reserved workflow poll slot, and the
replay with the result must pass the version 1 checks. Otherwise it sends
the ordinary completion, which costs nothing extra.
4. An accepted answer returns the next tail and may carry the next activity,
which the worker runs in the same tick. After 16 such activities in one
tick, the request carries no activity poll, so the tick ends and query and
workflow polls get a turn.

Answers follow the
[contract](https://github.com/durable-workflow/server/blob/main/docs/contracts/activity-workflow-continuation-v2.md):

- **Decline.** The result is recorded. The worker processes the carried
workflow poll answer. It evicts the cache entry for
`cache_identity_mismatch` and `run_not_open`, and keeps it for every other
reason.
- **Refusal** (a 4xx, or 500 `invalid_continuation_receipt` or
`history_invariant_violated`). Nothing was written, so the worker sends the
ordinary activity completion with the same carried workflow poll. The two
500 reasons also evict the cache entry and log an error. 409 `stale_attempt`
and `conflicting_completion` keep the ordinary stale-attempt and duplicate
handling and are not retried.
- **Unknown outcome** (another 5xx, or a transport failure). The worker resends
the identical request on the completion retry schedule, never an ordinary
completion. A retry that outlasts its attempts is logged as
`worker.outcome_unpublished`, and the Server re-delivers the attempt when
its lease ends.

Diagnostics: `worker.activity_continuation` (with `version`, `outcome`,
`reason` and `tail`), `worker.activity_continuation_skipped`,
`worker.activity_continuation_refused`,
`worker.activity_continuation_tail_rejected` and
`worker.activity_continuation_tail_refused`.

### Poll timeouts and early disconnects

When the Server advertises `task_delivery`, the managed worker negotiates
Expand Down
12 changes: 12 additions & 0 deletions scripts/ci/run-replay-regression-fixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,18 @@ private static function execute(array $fixture): void
return;
}

if ($workflowType === 'golden.activity-continuation-v2') {
require_once __DIR__.'/../../tests/Support/FakeTransport.php';
require_once __DIR__.'/../../tests/Support/ActivityContinuationV2Scenario.php';
$observed = \DurableWorkflow\Tests\Support\ActivityContinuationV2Scenario::run();
self::assertMatches($fixture['command_sequence'], $observed['commands'], $identity.self::COMMAND_SEQUENCE_CONTEXT);
$commands = $observed['commands'];
unset($observed['commands']);
self::assertMatches($fixture['expected'], ($commands[0] ?? []) + $observed, $identity.self::EXPECTED_CONTEXT);

return;
}

if ($workflowType === 'golden.worker-interceptor') {
require_once __DIR__.'/../../tests/Support/FakeTransport.php';
require_once __DIR__.'/../../tests/Support/WorkerInterceptorScenario.php';
Expand Down
25 changes: 20 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2841,11 +2841,14 @@ public function deliverWorkflowCancellation(
* run_id: string,
* build_id: string,
* ttl_seconds: int,
* metrics: array{hit: int, miss: int, eviction: int, forced_cold_replay: int}
* metrics: array{hit: int, miss: int, eviction: int, forced_cold_replay: int},
* history_last_sequence?: int
* }|null $stickyCache
* @param array{worker_id: string, task_queue: string, poll_request_id: string, timeout_seconds: int}|null $activityPoll
* @param array{worker_id: string, task_queue: string, poll_request_id: string, timeout_seconds: int, history_page_size: int, task_kinds: list<string>}|null $workflowPoll
* @param array<string, int|string>|null $selectionChildAwait
* @param array{version: int}|null $continuationTail Server #1181: ask for the history after the
* sticky_cache boundary, read after this completion's writes. Requires history_last_sequence.
* @return array<string, mixed>
*/
public function completeWorkflowTask(
Expand All @@ -2859,6 +2862,7 @@ public function completeWorkflowTask(
?array $activityPoll = null,
?array $workflowPoll = null,
?array $selectionChildAwait = null,
?array $continuationTail = null,
): array {
if (($messageStreamCursors !== [] || $messageStreamWaits !== []) && !Version::supportsMessageStreams()) {
throw new InvalidArgumentException('Message stream completion metadata requires worker protocol 1.15 or newer.');
Expand Down Expand Up @@ -2916,6 +2920,7 @@ public function completeWorkflowTask(
'activity_poll' => $activityPoll,
'workflow_poll' => $workflowPoll,
'selection_handle' => $selectionChildAwait,
'continuation_tail' => $continuationTail,
], static fn (mixed $value): bool => $value !== [] && $value !== null));
}

Expand Down Expand Up @@ -3029,9 +3034,12 @@ public function activityContinuationHistory(string $taskId, string $activityAtte

/**
* Server #1078: complete an activity and propose the run's next workflow task commands.
* A version 2 continuation (Server #1181) also names the sticky cache it was speculated
* from and may carry an activity poll for the activity its commands schedule.
*
* @param array{worker_id: string, task_queue: string, poll_request_id: string, timeout_seconds: int, history_page_size: int, task_kinds: list<string>} $workflowPoll
* @param array{version: int, history_through_sequence: int, history_last_event_id: string, commands: list<array<string, mixed>>} $continuation
* @param array{version: int, history_through_sequence: int, history_last_event_id: string, commands: list<array<string, mixed>>, sticky_cache?: array<string, mixed>} $continuation
* @param array{worker_id: string, task_queue: string, poll_request_id: string, timeout_seconds: int}|null $activityPoll
* @return array<string, mixed>
*/
public function completeActivityTaskWithContinuation(
Expand All @@ -3041,6 +3049,7 @@ public function completeActivityTaskWithContinuation(
mixed $result,
array $workflowPoll,
array $continuation,
?array $activityPoll = null,
): array {
foreach ($continuation['commands'] as $command) {
if (array_key_exists('target_build', $command)) {
Expand All @@ -3049,14 +3058,20 @@ public function completeActivityTaskWithContinuation(
}

$this->taskDelivery->carried('/worker/workflow-tasks/poll', $workflowPoll);
$this->taskDelivery->carried('/worker/activity-tasks/poll', $activityPoll);

return $this->worker('POST', self::ACTIVITY_TASK_PATH.$this->segment($taskId).'/continuation/complete', [
$body = [
'activity_attempt_id' => $activityAttemptId,
'lease_owner' => $leaseOwner,
'result' => $this->codec->envelope($result),
'workflow_poll' => $workflowPoll,
'continuation' => $continuation,
]);
];
if ($activityPoll !== null) {
$body['activity_poll'] = $activityPoll;
}
$body['continuation'] = $continuation;

return $this->worker('POST', self::ACTIVITY_TASK_PATH.$this->segment($taskId).'/continuation/complete', $body);
}

/**
Expand Down
Loading