Skip to content

Keep the sticky cache on empty continuation tails and renew its TTL - #503

Merged
rmcdaniel merged 1 commit into
mainfrom
general/sdk-php-500-tail-followups
Nov 26, 2026
Merged

rmcdaniel merged 1 commit into
mainfrom
general/sdk-php-500-tail-followups

Conversation

@rmcdaniel

Copy link
Copy Markdown
Member

Part of #500. This follows up the two non-blocking findings from the independent review of #501 (comment). Both change only StickyWorkflowCache::appendTail, which is on the opt-in continuation v2 path. They would otherwise cost the server#1181 benchmark cold replays.

What

  • Empty tail. A workflow task completion that records no events answers last_sequence == after_sequence with no events. That empty tail at the cached boundary now keeps the entry. Before, continues([]) was false, so the entry was evicted and the run's next workflow task needed a cold replay. An empty tail that claims a different last_sequence, or that arrives at another boundary, still evicts.
  • TTL renewal. appendTail now refreshes expires_at as remember() does. An accepted v2 answer is the run's workflow task, so a chain of accepted steps longer than the TTL now keeps its cache. Before, the entry expired a TTL after the last remember(), and the next workflow task was a forced cold replay.

The worker guide and the [Unreleased] CHANGELOG entry mention both.

Tests

  • WorkerActivityContinuationV2Test adds three tests:

    • testAnEmptyTailAtTheCachedBoundaryKeepsTheEntry;
    • testAnAppendedTailRenewsTheEntrysTtl, which uses an injected clock;
    • an "empty tail at the boundary" case for the workflow-completion tail through the Worker.

    All three fail on main and pass here.

  • Replay corpus: continuation-empty-tail-keeps-cache.json runs the new golden.continuation-empty-tail scenario (tests/Support/ContinuationEmptyTailScenario.php). It also has a branch in the official runner and in ReplayRegressionFixture. The worker's first workflow task gets an empty tail, and its second task replays the cache plus its suffix with no authoritative history read. On main the entry is evicted and history is refetched. The trusted runner rejects the new workflow type at both source revisions. validate-regression-corpus.py --base-ref origin/main passes locally.

  • I ran these locally on PHP 8.3: WorkerActivityContinuationV2Test (70), WorkerActivityContinuationTest, StickyHistorySuffixTest and ReplayRegressionCorpusTest all pass, and PHPStan is clean. CI runs the full matrix.

🤖 Generated with Claude Code

Two follow-ups from the independent review of #501, both in
StickyWorkflowCache::appendTail, both affecting only the opt-in
continuation v2 path:

- An empty tail at the cached boundary (last_sequence == after_sequence,
  no events), as a completion that records no events answers, now keeps
  the entry instead of evicting it. The run's next workflow task stays a
  sticky hit instead of a cold replay.
- An appended tail now renews expires_at, as remember() does. A chain of
  accepted continuations longer than the TTL no longer loses its cache.

Unit tests fail without each fix. A new replay corpus scenario shows an
empty tail keeping the cache, so the next workflow task replays the cache
plus its suffix with no authoritative history read; the base revision
evicts and refetches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@rmcdaniel

Copy link
Copy Markdown
Member Author

Independent review: PASS at head c832276

This addresses both non-blocking findings from the #501 review. The only source change is to StickyWorkflowCache::appendTail, which is reached only on the opt-in continuation v2 path.

What I verified:

  • Empty tail. The entry is kept only for an empty tail at the cached boundary: last_sequence == after_sequence, no events, a cached last sequence equal to after_sequence, and a cache that starts with WorkflowStarted. An empty tail that claims events, or that arrives at another boundary, still evicts. This matches the server's continuation_tail, which returns Events { events: [], last_sequence: after_sequence } for a completion that recorded nothing.
  • TTL. appendTail now sets expires_at to now + ttl in the same way remember() does. An entry still expires one TTL after its last append, and the new test asserts that.
  • Tests. I ran WorkerActivityContinuationV2Test, WorkerActivityContinuationTest, StickyHistorySuffixTest and ReplayRegressionCorpusTest locally on PHP 8.3: 98 tests, all OK. With src/Worker/StickyWorkflowCache.php reverted to main, three new tests fail: the empty-tail-at-the-boundary data case, testAnEmptyTailAtTheCachedBoundaryKeepsTheEntry and testAnAppendedTailRenewsTheEntrysTtl. The corpus policy test also errors on the new fixture. So the tests depend on the fix.
  • Docs. The worker guide and the [Unreleased] CHANGELOG entry describe both behaviours.
  • CI. At this head, 33 checks pass and 1 is skipped (Connected cooperative cancellation, which is conditional). The branch is up to date with main at c9cc155.

One minor note, which needs no change: the corpus scenario answers an empty tail to a completion that schedules an activity. A real Server would record an ActivityScheduled in that case. The scenario still tests what it is meant to, which is that the cache keeps its entry and replays the next suffix without an authoritative read.

@rmcdaniel
rmcdaniel merged commit c6bce64 into main Nov 26, 2026
37 checks passed
@rmcdaniel
rmcdaniel deleted the general/sdk-php-500-tail-followups branch November 26, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant