Skip to content

Support rewind in the in-memory test backend - #185

Open
andystaples wants to merge 12 commits into
andystaples-orchestration-testing-designfrom
andystaples-in-memory-backend-rewind
Open

andystaples wants to merge 12 commits into
andystaples-orchestration-testing-designfrom
andystaples-in-memory-backend-rewind

Conversation

@andystaples

Copy link
Copy Markdown
Contributor

Summary

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.

Recover failed activities and sub-orchestrations using worker replacement history, including purged child recreation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@berndverst Bernd Verst (berndverst) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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.

Comment thread internal/inmemory/rewind.go Resolved
Comment thread internal/inmemory/rewind.go Resolved
Comment thread internal/inmemory/rewind.go Resolved
Comment thread internal/inmemory/rewind.go Resolved
andystaples and others added 2 commits November 23, 2026 12:44
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 19:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

2 open issues
What changed in this PR

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.
durabletasktest/​host.go Updates package documentation for rewind support.
durabletasktest/​host_test.go Adds end-to-end recovery and rejection tests.
CHANGELOG.md Records rewind support and its constraints.

Review effort: Balanced

Comment thread internal/inmemory/work.go Resolved
Comment thread internal/inmemory/rewind.go Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Medium severity 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.

Medium severity 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.

2 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 20:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Medium severity 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.

Review effort: Balanced

andystaples and others added 4 commits November 23, 2026 13:38
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 21:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Rewind work items can exceed the 4 MiB limit without validation, causing worker rejection and repeated requeuing that leaves recovery stuck.

1 open issue

Review effort: Balanced

Comment thread internal/inmemory/work.go Resolved

@berndverst Bernd Verst (berndverst) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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.

Comment thread internal/inmemory/work.go Resolved
andystaples and others added 3 commits November 23, 2026 16:59
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>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 00:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment on lines +176 to +177
func (s *Server) validateRewindChildrenLocked(inst *instance, history []*protos.HistoryEvent, seen map[*instance]bool) error {
if seen[inst] {
Comment on lines +325 to +327
if !slices.Contains(inst.children, child.id) {
inst.children = append(inst.children, child.id)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants