Skip to content

Add durable entity support to the in-memory test backend - #188

Open
andystaples wants to merge 16 commits into
andystaples-in-memory-backend-rewindfrom
andystaples-inmemory-entity-support
Open

andystaples wants to merge 16 commits into
andystaples-in-memory-backend-rewindfrom
andystaples-inmemory-entity-support

Conversation

@andystaples

@andystaples andystaples commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Part of #180. Stacked on #185 (rewind), which is stacked on #183 (in-memory test host). Resolves #180

Summary

The durabletasktest in-memory backend now supports durable entities. Before this change, entity RPCs returned Unimplemented and orchestrations that emitted entity actions failed with NotSupported.

What's supported

  • Entity work items: V2 EntityRequest dispatch over GetWorkItems, with optional entity-name filters, plus CompleteEntityTask and AbandonTaskEntityWorkItem. If a work-item stream ends, its leased entity batches are requeued.
  • Batch results:
    • Successful batches persist entity state, route call results back to callers, and apply entity actions: signals to other entities and starts of new orchestrations.
    • A failed batch fails its pending calls with EntityOperationFailed and leaves state unchanged.
  • Orchestration actions:
    • Calls, signals, and locks produce EntityOperationCalled/Signaled/Completed/Failed, EntityLockRequested/Granted, and EntityUnlockSent events.
    • The backend sets EntityParameters with a zero reorder window so the orchestrator enables entity APIs.
  • Critical sections: These follow DTS and .NET semantics.
    • A lock request moves through the sorted lock set one entity at a time.
    • While an entity is locked, it processes only messages from the lock owner, plus that owner's unlock.
    • Other signals and calls wait until the lock is released.
  • Client RPCs:
    • SignalEntity, including a scheduled time, which uses a real-time timer.
    • GetEntity.
    • QueryEntities, with an ID prefix, a time range, an option to include transient entities, page size, and continuation.
    • CleanEntityStorage, which removes empty entities and releases locks whose owning orchestration is missing or terminal.
  • Error codes: These match client/grpc_errors.go and internal/grpcerrors.
    • InvalidArgument: bad entity IDs, empty operation names, or bad continuation tokens.
    • NotFound: unknown completion tokens.
  • Rewind: Rewinding a failed orchestration keeps the entity call results already in its history.

Docs and tests

  • The durabletasktest package doc, the README section "Testing orchestrations", and the CHANGELOG entry no longer list entities as unsupported.
  • The entity case in TestUnsupportedFeatures is replaced by end-to-end entity tests in durabletasktest/entity_test.go:
    • client signals, including scheduled signals
    • orchestration calls and signals
    • operation failure
    • entity-to-entity signals and orchestration starts
    • critical sections
    • queries
    • storage cleanup
    • rewind with entity calls
  • Unit tests in internal/inmemory/entity_test.go cover lock gating, orphaned-lock cleanup, and requeueing entity work items when a stream is released.

@andystaples
andystaples added this pull request to stack #190 November 20, 2026 18:47

@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 normal client and worker makes in-memory entity tests more useful. I would hold this until two cases are fixed: a terminated orchestration can leave later entities in a lock set locked indefinitely, and a backlog of individually valid signals can produce a work item that stops the host's only worker.

Comment thread internal/inmemory/entity.go Resolved
Comment thread internal/inmemory/entity.go Resolved
Copilot AI balanced review requested due to automatic review settings November 23, 2026 19:41

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

Critical unresolved issues allow oversized batches to block shared worker intake, discard entity results after rewind, and retain stale locks after orchestration replacement, while entity queries also mishandle the exclusive timestamp upper bound.

4 open issues
What changed in this PR

Adds durable entity support to durabletasktest, extending the in-process test host to exercise entities through the real client, worker, and executor without an emulator.

Changes:

  • Adds entity dispatch, state persistence, result routing, scheduled signals, queries, and storage cleanup.
  • Integrates orchestration entity actions and critical-section locks.
  • Adds entity tests, including rewind preservation, and updates testing documentation.
File Description
README.md Documents entity testing and removes the unsupported-entity limitation.
internal/​inmemory/​work.go Integrates entity dispatch, stream-release requeueing, and orchestration actions.
internal/​inmemory/​server.go Adds entity queues, leases, lock tracking, and timer management.
internal/​inmemory/​entity.go Implements entity batching, completion, locking, and client RPCs.
internal/​inmemory/​entity_test.go Tests lock handling, cleanup, batch sizing, and lease requeueing.
durabletasktest/​host.go Updates package documentation to describe entity support.
durabletasktest/​host_test.go Removes the test asserting entities are unsupported.
durabletasktest/​entity_test.go Adds end-to-end coverage for entity operations, locks, queries, cleanup, and rewind.
CHANGELOG.md Records entity support in the test host’s feature list.

Review effort: Balanced

Comment thread internal/inmemory/entity.go Resolved
Comment thread internal/inmemory/entity.go Resolved
Comment thread internal/inmemory/entity.go Resolved
Comment thread internal/inmemory/entity.go Resolved
Copilot AI balanced review requested due to automatic review settings November 23, 2026 19:51

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

Outstanding entity-call responses are discarded after rewind, and locks can survive replacement of their owning execution, leaving orchestrations and callers blocked indefinitely.

3 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Treat empty entity filters as unrestricted intake

internal/​inmemory/​entity.go:316

An empty entity-filter list means unrestricted intake, not reject-all: workItemFiltersFromRegistry produces it for an entity registered as "*", and workItemFiltersToProto uses a separate sentinel for reject-all. With a wildcard registration the filters object is still non-nil, so this check rejects every entity and signals/calls never execute. Treat an empty entity list as unrestricted, matching client/grpc_worker_processor.go:820-830.

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 23, 2026 20:04
@andystaples
andystaples force-pushed the andystaples-inmemory-entity-support branch from ccd4853 to 477dbd0 Compare November 23, 2026 20:04

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

Critical entity-handling defects discard results needed for replay and block entity dispatch when only other work-item filters are configured, causing calls to wait indefinitely.

2 open issues
3 resolved since last review

Review effort: Balanced

Comment thread internal/inmemory/entity.go Resolved
Comment thread internal/inmemory/entity.go Resolved
@andystaples
andystaples force-pushed the andystaples-inmemory-entity-support branch from 477dbd0 to 0707078 Compare November 23, 2026 20:13
Copilot AI balanced review requested due to automatic review settings November 23, 2026 20:13

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

Empty entity filters incorrectly block all entity work, and entity results lost during caller failure can leave rewound orchestrations waiting indefinitely.

2 open issues

Review effort: Balanced

andystaples and others added 5 commits November 23, 2026 13:20
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Drop lock acquisitions whose requesting execution has ended so a terminated
waiter can't lock entities after its unlocks have passed them. Select entity
operations in one pass and stop before a work item exceeds the worker's gRPC
receive limit, leaving the remaining operations queued.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Enforce the work item size limit for the first operation in a batch too.
Operations that can't fit even alone are removed so they can't stall the
entity; calls fail with EntityOperationTooLarge and signals are dropped.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Locks record the owning execution, so cleanup releases locks left by a
replaced instance and only that execution's calls run under them. Rewind
rebinds outstanding calls, lock requests, and locks to the renewed
execution. Entity queries treat LastModifiedTo as exclusive.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@andystaples
andystaples force-pushed the andystaples-inmemory-entity-support branch from 0707078 to 9c1f128 Compare November 23, 2026 20:23
Copilot AI balanced review requested due to automatic review settings November 23, 2026 20:23

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

Malformed request IDs are accepted, causing workers to repeatedly requeue undispatchable batches and block subsequent operations on the affected entity.

3 open issues
2 resolved since last review

Review effort: Balanced

Comment thread internal/inmemory/entity.go Resolved
Comment thread internal/inmemory/entity.go Resolved
Comment thread internal/inmemory/entity.go Resolved
andystaples and others added 5 commits November 23, 2026 13:38
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Realign the NewServer field initializers that the entity fields left unformatted.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A failed signal-only batch can leave its entity with nothing to dispatch, so pumping the entity doesn't notify waiting streams. Notify them as the success path does so another queued entity can use the freed concurrency slot without waiting for the next event or health ping.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
QueryEntities continuation tokens were offsets into a result set rebuilt for each page, so entities added or removed between pages caused later pages to skip or repeat entities. Encode the last returned instance ID instead and resume at greater IDs, as instance queries do. Malformed tokens still return InvalidArgument.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Workers refuse entity work items whose signal or call request IDs aren't UUIDs, so an accepted malformed ID made the worker abandon the batch repeatedly and blocked the entity. SignalEntity now returns InvalidArgument for a supplied request ID that isn't a UUID and still generates one when it's omitted. Orchestration entity messages with a malformed request ID or entity instance ID now fail the orchestration instead of being delivered undispatchable or dropped.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
andystaples and others added 2 commits November 23, 2026 14:12
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 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

An oversized combined batch result can exceed the receive limit and trigger indefinite re-execution while callers wait, requiring bounded failure handling and regression coverage.

1 open issue
3 resolved since last review

Review effort: Balanced

Comment thread internal/inmemory/entity.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 terminated lock acquisition and oversized incoming batch cases are fixed. I would hold this until oversized completions stop re-running the same operations and the host reports signals it cannot dispatch instead of acknowledging and silently dropping them.

Comment thread internal/inmemory/entity.go Resolved
andystaples and others added 4 commits November 23, 2026 17:01
SignalEntity now returns InvalidArgument when a signal's input and the
entity's current state can't fit together in an entity work item, using
the same sizing as dispatch. Signals rejected at dispatch time, such as
scheduled signals or signals from orchestrations and entities, are no
longer dropped silently: the in-memory service logs a warning with the
entity ID, operation, and sizes through the durabletasktest host logger.
Document the combined state and input limit.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The worker abandons an entity completion that the service rejects for
size, so the service rebuilt and re-ran the same batch indefinitely.
CompleteEntityTask now checks the batch result size itself: a result over
4 MiB isn't applied, the entity's state is unchanged, each call in the
batch fails with the non-retriable error type EntityResultTooLarge, and
each signal is logged as dropped. The operations run once.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A host created with durabletasktest.New now also reports each entity
signal that the in-memory service drops with testing.TB.Log, so drops
show up when a test fails or runs with -v even if the test doesn't set
WithLogger.

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

Entity query pages are not bounded by serialized response size, so valid large states can exceed the client’s 64 MiB receive limit and cause ResourceExhausted failures.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment on lines +752 to +759
resp := &protos.QueryEntitiesResponse{}
if len(matches) > pageSize {
matches = matches[:pageSize]
resp.ContinuationToken = wrapperspb.String(encodeEntityCursor(matches[pageSize-1].id))
}
for _, e := range matches {
resp.Entities = append(resp.Entities, e.metadata(query.GetIncludeState()))
}
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.

Provide an in-process orchestration tester with mocks and virtual time

3 participants