Skip to content

End a signal wait where cancellation was delivered - #1316

Merged
rmcdaniel merged 5 commits into
mainfrom
general/workflow-1315-late-signal-attribution
Nov 26, 2026
Merged

rmcdaniel merged 5 commits into
mainfrom
general/workflow-1315-late-signal-attribution

Conversation

@rmcdaniel

Copy link
Copy Markdown
Member

Fixes #1315.

A cooperative cancellation delivered at a signal wait (timeout cleanup or ordinary cancellation) records no SignalWaitCancelled, so SignalWaits kept the wait open. A signal accepted later was attributed to it, and the wait showed as received although the signal never applied. WorkflowTimedOut also left open waits open.

Change (derived views only, no new history)

  • SignalWaits::forRun closes the wait at a CooperativeCancellationDelivered with call_kind: signal, and the member waits of a parallel (selection) delivery, as cancelled / cancellation_delivered. Deliveries at a durable handle await or a started-child await close nothing, because the operation stays awaitable. WorkflowTimedOut closes open waits (closed) like the other terminal events. Run detail gets a summary line for the new source status.
  • A late signal finds no open wait, so it's buffered under signal-command:<command id>. That's the identity any signal accepted with no open wait already gets. Its SignalReceived and SignalRejected no longer carry the interrupted wait's id, and it no longer schedules a workflow task that couldn't apply it.
  • Replay safety: the executor's step cursor (visibleSequenceForCurrent) and durable-handle cancellation (executor and bridge) read forRun(..., replayCompatible: true), which keeps the old states. Recorded histories replay unchanged. Pre-fix histories that already attributed a late signal now show the wait as interrupted.

Tests

  • V2TimeoutCleanupTest: the Prove embedded timeout cleanup at signal/selection waits, under worker loss, and on the deadline turn #1312 signal-wait test, and the selection test, assert the wait is cancelled / cancellation_delivered in SignalWaits and run detail, and that the late SignalReceived and SignalRejected carry the buffered id.
  • DurableWaitProjectionTest: closure for signal and group deliveries, no closure for a handle delivery, WorkflowTimedOut, and the replay-compatible view.
  • Replay fixture cooperative-delivery-ends-signal-wait-attribution: ordinary cancellation. A pre-fix history replays and its view is corrected, and a live run buffers the late signal. validate-regression-corpus.py passed locally with the counterfactual: the fixture fails on base and passes here.

Native Server has the same attribution. That's reported separately and not changed here.

🤖 Generated with Claude Code

A cooperative cancellation delivered at a signal wait, including timeout
cleanup's interruption, records no SignalWaitCancelled, so the derived
signal-wait view kept the wait open. A signal accepted afterwards was
attributed to it: its SignalReceived and SignalRejected carried the
interrupted wait's signal_wait_id, and SignalWaits showed the wait as
received although the signal never applied. WorkflowTimedOut also left
open waits open.

SignalWaits now closes the wait at a signal delivery, and the member
waits of a delivered group, as cancelled with source status
cancellation_delivered, and closes open waits on WorkflowTimedOut. A
later signal finds no open wait and is buffered under its own command
identity. No history is added. The replay cursor and durable handle
cancellation read the view with replayCompatible, which keeps the
earlier states, so recorded histories replay unchanged.

Fixes #1315.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rmcdaniel rmcdaniel added the agent:general Work owned by General label Nov 26, 2026
rmcdaniel and others added 4 commits November 26, 2026 20:53
forRun grew past the cognitive-complexity and length limits with the
delivery and timeout closures. Each event type now has its own handler,
with the same state transitions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The step cursor reads SignalWaits with replayCompatible so that a wait
closed by cancellation delivery still counts as it always did. A new
feature test catches the delivery at a signal wait, waits for the same
signal again, and checks that an update applied at the first wait sees
the same step cursor when the last task replays it. Without the flag
the replay sees 1 instead of 2.

The CHANGELOG notes the bridge-worker upgrade edge case for a late
signal an earlier engine attributed to the interrupted wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ECS on CI rewrote the chained call differently from a local fix.

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 ffbd258

Verification summary

  • Head SHA confirmed: ffbd258e163567f994bfa7db9a0c18aae286bf21 (all required CI checks green, including regression-corpus, quality, pr-unit, pr-unit-contracts, pr-feature-mysql, all 17 feature-postgresql shards, CodeQL, and SonarCloud).
  • Issue Do not attribute a late signal to a wait interrupted by timeout-cleanup delivery #1315 requirements met:
    • SignalWaits::forRun() closes open signal waits on CooperativeCancellationDelivered for call_kind: 'signal' (span 1) and call_kind: 'parallel' (using sequence_span ?? 1, with overflow-safe bounds $sequence - $baseSequence >= $span), marking them status: 'cancelled' / source_status: 'cancellation_delivered' and removing them from $openWaitIdsByName.
    • Durable handle awaits (selection_handle) and started-child awaits (started_child_await) are intentionally ignored so underlying awaitable operations remain open.
    • WorkflowTimedOut now closes open waits via closeOpenWaits() (status: 'cancelled', source_status: 'closed'), matching other terminal events and existing RunWaitView 'closed' copy.
    • RunWaitView::signalWaits() adds a clear summary string for cancellation_delivered.
    • Late signals accepted after delivery find no open wait via SignalWaits::openWaitIdForName(), so they buffer under signal-command:<command_id> in SignalReceived/SignalRejected and no longer schedule a wasted workflow task.
  • Replay safety & caller audit:
    • All SignalWaits callers across src/ were checked. Execution/replay paths (WorkflowExecutor::visibleSequenceForCurrent, WorkflowExecutor::cancelDurableLeaf, DefaultWorkflowTaskBridge::cancelSelectionLeaf) pass replayCompatible: true, preserving historical replay cursors and cancellation-decision behavior.
    • Pre-fix histories that already attributed a late SignalReceived to an interrupted wait are safely corrected on projection because applySignalEvent() refuses to transition a 'cancelled' wait, while replayCompatible: true preserves the legacy view.
    • The single external-worker in-flight upgrade edge case is accurately documented in CHANGELOG.md.
  • Tests:
    • Deterministic coverage across V2TimeoutCleanupTest, V2FinallyCleanupTest, DurableWaitProjectionTest, and the new replay-regression corpus fixture cooperative-delivery-ends-signal-wait-attribution.json.

Non-blocking notes

  • None blocking.

@rmcdaniel
rmcdaniel merged commit e86a807 into main Nov 26, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:general Work owned by General

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not attribute a late signal to a wait interrupted by timeout-cleanup delivery

1 participant