You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support rewind in the in-memory test backend - #185
Adds RewindInstance support to the in-memory service used by durabletasktest, building on #183. Relates to #180.
Only failed instances can be rewound. The service enqueues recovery, persists the real worker's RewindOrchestrationAction.NewHistory, renews execution identity, and recursively recovers failed sub-orchestrations without rerunning successful work. Purged unfinished children are recreated from their recorded creation data, without their previous history.
Recovery preserves the worker's existing history-safety limits: retry-policy histories and durable events following an operation failure remain unsupported. Durable entities remain unsupported in this layer, and timers still use real time.
Includes failed-activity, nested-child, purged-child, invalid-state, unsafe-history, replacement-history, and stale-result coverage, plus updated testing documentation.
The reason will be displayed to describe this comment to others. Learn more.
Reusing the worker's history rewrite is a good foundation, and it works for sequential failures. I would hold this until rewind isolates the rewrite turn and reconciles outstanding work. As written, a concurrent event can make rewind fail, a retained task or already-completed child can leave it running indefinitely, and an ID collision can attach an unrelated orchestration.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved parent-execution identity updates can discard a child's failure and leave its renewed parent waiting indefinitely, or cause a subsequent rewind to reject its own child as AlreadyExists.
Adds rewind support to the in-memory backend used by durabletasktest, extending the test host from #183 to exercise failed-orchestration recovery through the real worker.
Changes:
Adds recovery scheduling, replacement-history persistence, and execution identity renewal.
Reconciles outstanding activities, timers, and child orchestrations while preserving successful work.
Adds recovery and rejection coverage, and documents supported behavior and limitations.
File
Description
README.md
Documents rewind usage and limitations.
internal/inmemory/work.go
Handles rewind completions and retains late results.
internal/inmemory/work_test.go
Tests replacement history, stale results, and work reconciliation.
internal/inmemory/server.go
Tracks rewind state and adjusts queue eligibility.
internal/inmemory/rewind.go
Implements rewind validation, identity renewal, and recovery.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Rewind recovery can reject children because of stale parent metadata and become stuck indefinitely when retained suspension events conflict with the server’s RUNNING status.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Reconcile retained suspension events during recovery rewind
internal/inmemory/rewind.go:41
If SuspendInstance arrives while a failing orchestration turn is leased, completeLocked now retains its ExecutionSuspended event in pending. Resetting the status to RUNNING here leaves that event intact, so recovery replay suspends the worker while the server still reports RUNNING. ResumeInstance then does nothing because it only enqueues a resume for SUSPENDED instances, leaving recovery stuck indefinitely. Reconcile the server's suspension status with the retained lifecycle events, or consistently discard the old suspension intent when rewinding, and add coverage for this interleaving.
Retarget child parent metadata before enqueueing recovery
internal/inmemory/rewind.go:274
prepareRewindLocked records the renewed parent ID only in child.rewind, leaving child.parent on the old execution until the child's replacement completes. If the renewed parent fails again first, its next rewind rejects this original child as AlreadyExists because childMatchesParent checks the stale parent reference. Retarget the child's parent metadata before enqueueing recovery, as the other existing-child branches do.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
A child retains its old parent execution ID until replacement history is committed, so a late sibling failure can cause a subsequent rewind to be incorrectly rejected as AlreadyExists.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Retarget child before enqueueing its rewind
internal/inmemory/rewind.go:274
This branch leaves the child's parent execution ID unchanged until the child's replacement history is committed. If a different late child failure fails the renewed parent first (for example, with WhenAny over children), another RewindInstance rejects this still-owned child as AlreadyExists: validateRewindChildrenLocked checks child.parent, not the pending rewind marker. Retarget the child immediately here, as the other branches do, before enqueueing its rewind.
A child prepared for recursive rewind kept its old parent execution until its replacement history was committed. If the renewed parent failed again first, a later rewind rejected the still-owned child as AlreadyExists. Retarget the child's parent metadata immediately, as the other existing-child branches do.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Suspend, resume, and terminate requests that arrived while a failing turn was leased stayed in the failed instance's inbox. Rewind resets the status to running, so recovery replay could suspend the worker while the service reported running (and ResumeInstance could not release it), or immediately terminate the recovered instance. A failure supersedes these requests, as DTS drops messages to completed instances, so do not retain them for rewind.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep the rewind lease separate from new-event batching: rewind leases carry only the rewind marker, and normal leases split pending events to fit the gRPC message limit.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
The rewind isolation, outstanding work, and child ownership fixes address my first review. One retry path still needs fixing: if the worker rejects a replacement, the backend changes the original history, and a second rewind can fail even after the first rejection's cause is removed. The oversized work-item thread is separate and still applies.
A rewind work item completed with a failure instead of a replacement used to commit its OrchestratorStarted and ExecutionRewound markers after the original failure, so a later rewind was rejected as unsafe. End the attempt through failRewindLocked instead: replace only the terminal failure with the worker's failure details and notify the renewed parent. Failed rewinds no longer add an extra OrchestratorCompleted marker.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A long rewind reason could make the rewind work item exceed the in-memory backend's gRPC message limit even with streamed history. The worker rejected it, and stream cleanup requeued the same rewind indefinitely. RewindInstance now rejects such a reason with InvalidArgument, and leasing fails an oversized rewind (such as a child carrying its parent's reason) through failRewindLocked instead of delivering it.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Rewind can revive children after recursive parent termination and accept histories without a committed start, leaving instances running indefinitely through repeated failed retries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
RewindInstancesupport to the in-memory service used bydurabletasktest, building on #183. Relates to #180.Only failed instances can be rewound. The service enqueues recovery, persists the real worker's
RewindOrchestrationAction.NewHistory, renews execution identity, and recursively recovers failed sub-orchestrations without rerunning successful work. Purged unfinished children are recreated from their recorded creation data, without their previous history.Recovery preserves the worker's existing history-safety limits: retry-policy histories and durable events following an operation failure remain unsupported. Durable entities remain unsupported in this layer, and timers still use real time.
Includes failed-activity, nested-child, purged-child, invalid-state, unsafe-history, replacement-history, and stale-result coverage, plus updated testing documentation.