User task persistence providers
User task persistence keeps a human task and its workflow links, participant rules, audit history, operations, invitations, and guest access state available to the user-task services. The shared repository contract lets those services use in-memory storage, relational EF Core storage, or the experimental VNext document path without changing their task behavior. See the user-task workflow capabilities page for the wider task life cycle.
Persistence boundary
The IUserTaskRepository is the main boundary between user-task behavior and storage. It supports task reads, filtered queries, bookmark and materialization lookups, invitation-token lookup, projection, revision-safe saves, append-only audit events, and compare-and-swap mutations. Providers also translate their native concurrency errors into UserTaskRevisionConflictException, so callers receive one conflict meaning across storage choices (src/…/UserTaskContracts.cs• L36-72).
A task projection is the durable view of a user-task activity waiting on a workflow bookmark. The repository keeps the task data and the relationships needed to decide visibility together, while the task services remain responsible for authorization and workflow action rules.
The common persistence flow is:
flowchart LR
A[User-task service] --> B[IUserTaskRepository]
B --> C{Storage provider}
C --> D[In-memory task store]
C --> E[EF Core relational store]
C --> F[VNext document store]
D --> G[Task state and audit]
E --> G
F --> G
References: src/…/UserTaskContracts.cs• L48-72 src/…/UserTaskModels.cs• L225-282
Repository contract
The repository contract treats a user task as a tenant-owned aggregate with a revision. A save must name the revision the caller read. A successful save advances that revision, while a stale save reports a conflict instead of replacing newer work (src/…/UserTaskContracts.cs• L41-72).
Queries apply tenant and visibility scope before totals, cursors, and page limits. This order matters because an unauthorized task must not affect a count or consume a page slot. Materialization uses a tenant-scoped key so a repeated bookmark commit creates one task rather than duplicate task rows (src/…/InMemoryUserTaskRepository.cs• L23-55, src/…/InMemoryUserTaskRepository.cs• L102-113).
Audit events have a separate rule from task changes. They append to history without advancing the task revision, so recording a read or field reveal does not invalidate a command that a caller already holds (src/…/UserTaskContracts.cs• L65-72). Invitation-token lookup uses only the stored token hash and does not trust a tenant or task supplied by an anonymous caller (src/…/UserTaskContracts.cs• L55-60).
References: src/…/UserTaskContracts.cs• L36-72 src/…/InMemoryUserTaskRepository.cs• L23-113 src/…/InMemoryUserTaskRepository.cs• L116-143
Tenant and participant scope
Every normal task lookup and query is tenant-scoped. Participant references carry a tenant, provider, type, and ID. Available-task visibility can use live candidates or a membership snapshot, and exclusions remove a participant from eligibility. These relationships are part of persistence because the repository must return enough state for the policy layer to calculate the same result for every provider (src/…/UserTaskModels.cs• L84-95, src/…/UserTaskModels.cs• L243-250).
Manager-wide views and attention views remain constrained by the task's tenant. A scope from another tenant matches nothing even when the query names the current tenant. This prevents storage-level filtering from becoming a way to bypass the policy layer (src/…/InMemoryUserTaskRepository.cs• L145-180, src/…/EFCoreUserTaskRepository.cs• L277-344).
References: src/…/UserTaskModels.cs• L448-480 src/…/InMemoryUserTaskRepository.cs• L145-180 src/…/EFCoreUserTaskRepository.cs• L277-344
In-memory provider
The InMemoryUserTaskRepository is a deterministic reference provider for the core module and development hosts. It uses one synchronized store and returns cloned task objects, so callers cannot change stored state without a repository operation (src/…/InMemoryUserTaskRepository.cs• L8-20, src/…/InMemoryUserTaskRepository.cs• L312-366).
The provider models the durable contract rather than acting as a loose test double. It performs revision compare-and-swap for saves and mutations, ignores a duplicate materialization key, keeps audit writes outside the revision, and supports tenant-safe filtering and cursor paging. Its data is process-local, so it is suitable for tests and development but not for restart or failover durability.
References: src/…/InMemoryUserTaskRepository.cs• L8-12 src/…/InMemoryUserTaskRepository.cs• L86-143 test/…/InMemoryUserTaskStoreFixture.cs• L8-30
EF Core providers
The EF Core provider family gives user tasks a shared relational model and a shared repository. The base feature registers EFCoreUserTaskRepository for both the public task contract and the low-level persistence adapter. It also replaces the core guest-session and invitation-outbox defaults with durable stores (src/…/EFCoreUserTasksPersistenceFeature.cs• L12-32).
The provider stores the task's main state in UserTasks. It keeps candidates, membership snapshots, exclusions, events, operations, invitations, invitation deliveries, and guest sessions in related storage units. Rich task values remain portable through serialized fields, while participant and query relationships stay available as relational data. The repository rebuilds one task aggregate from these parts when it reads a task (src/…/UserTasksElsaDbContext.cs• L17-25, src/…/PersistenceModels.cs• L17-218, src/…/EFCoreUserTaskRepository.cs• L422-466).
Relational task behavior
EF Core performs query filtering in the database before it loads the page's related participant, history, operation, and invitation data. This keeps counts and cursors aligned with the visible set while still giving the policy layer the relationships it needs (src/…/EFCoreUserTaskRepository.cs• L31-46).
Task saves and compare-and-swap mutations use a transaction and the revision as the optimistic-concurrency token. A projection is idempotent on the tenant and materialization key, and a concurrent duplicate projection is treated as an existing task rather than as a failed workflow commit (src/…/EFCoreUserTaskRepository.cs• L80-132, src/…/UserTaskEntityConfiguration.cs• L9-55).
Participant identities are stored as provider, participant type, and participant ID values. The user-task persistence layer does not require an identity table or a foreign key to an identity provider. This keeps task storage usable with different host identity systems while preserving tenant and participant matching (src/…/EFCoreUserTaskRepository.cs• L11-14, src/…/UserTaskEntityConfiguration.cs• L57-107).
References: src/…/EFCoreUserTaskRepository.cs• L24-174 src/…/EFCoreUserTaskRepository.cs• L422-478 src/…/UserTaskEntityConfiguration.cs• L9-107
Guest sessions and invitation outbox
The EF Core package persists two supporting parts of the guest workflow. Guest sessions store only a hash of the bearer credential and check expiry and revocation on every resolve. Revocation can target one invitation or all sessions for a task, so a closed task or withdrawn invitation cannot leave a live guest credential (src/…/EFCoreUserTaskGuestStores.cs• L16-93).
The invitation outbox holds the only delivery copy of an invitation secret between issuance and successful dispatch. It protects that secret before storage, removes expired deliveries instead of sending them late, preserves routing metadata, and stops retrying after the configured retry schedule ends (src/…/EFCoreUserTaskGuestStores.cs• L96-214).
The in-memory core provides matching session and outbox services for local use. EF Core replaces them because guest credentials and undelivered invitation secrets must survive process restart and failover (src/…/EFCoreUserTasksPersistenceFeature.cs• L28-31, test/…/InMemoryUserTaskStoreFixture.cs• L18-24).
References: src/…/EFCoreUserTaskGuestStores.cs• L23-93 src/…/EFCoreUserTaskGuestStores.cs• L96-214 src/…/UserTaskContracts.cs• L129-170
Database-specific packages
Each EF Core database package supplies the same user-task feature through one database-specific connection setup and migration assembly. The shared shell feature registers the task repository, guest-session store, and invitation outbox. The database-specific shell then selects SQLite, SQL Server, PostgreSQL, MySQL, or Oracle (src/…/EFCoreUserTasksPersistenceShellFeatureBase.cs• L9-26).
| Database | Programmatic provider entry point | Shell feature |
|---|---|---|
| SQLite | UseSqlite | SqliteUserTasksPersistenceShellFeature |
| SQL Server | UseSqlServer | SqlServerUserTasksPersistenceShellFeature |
| PostgreSQL | UsePostgreSql | PostgreSqlUserTasksPersistenceShellFeature |
| MySQL | UseMySql | MySqlUserTasksPersistenceShellFeature |
| Oracle | UseOracle | OracleUserTasksPersistenceShellFeature |
The product behavior is shared. The package boundary exists to select the database driver, connection settings, provider model hooks, and matching migration history (src/…/SqliteUserTasksPersistenceFeatureExtensions.cs• L9-29, src/…/SqlServerUserTasksPersistenceFeatureExtensions.cs• L9-15, src/…/PostgreSqlUserTasksPersistenceFeatureExtensions.cs• L9-13, src/…/MySqlUserTasksPersistenceFeatureExtensions.cs• L9-13, src/…/OracleUserTasksPersistenceFeatureExtensions.cs• L9-13).
References: src/…/EFCoreUserTasksPersistenceShellFeatureBase.cs• L12-26 src/…/SqliteUserTasksPersistenceShellFeature.cs• L14-32 src/…/SqlServerUserTasksPersistenceShellFeature.cs• L13-20 src/…/PostgreSqlUserTasksPersistenceShellFeature.cs• L14-26 src/…/MySqlUserTasksPersistenceShellFeature.cs• L14-26 src/…/OracleUserTasksPersistenceShellFeature.cs• L14-20
VNext integration
The VNext provider adapts the same IUserTaskRepository contract to a versioned document store. It stores the full user-task aggregate as one UserTasks document and publishes the index values needed for tenant, status, task identity, workflow links, assignment, health, priority, and date-based access (src/…/VNextUserTaskRepository.cs• L9-18, src/…/VNextUserTaskRepository.cs• L186-211).
VNext registration adds the user-task schema provider and replaces the repository service. The module contributes its schema to the shared VNext schema catalog, while the selected document store materializes the declared storage units and indexes (src/…/ServiceCollectionExtensions.cs• L8-15, src/…/ModuleExtensions.cs• L5-11).
Document query boundary
VNext queries first use the document store's indexed filters and then apply the full task query, visibility scope, ordering, and cursor rules to the loaded documents. Invitation-token lookup is intentionally tenant-agnostic, but it scans the user-task storage unit because this provider has no cross-tenant invitation-hash index (src/…/VNextUserTaskRepository.cs• L27-65).
The schema provider declares the fields and indexes that make this behavior portable. It includes separate logical units for participant relationships, audit events, operations, invitations, invitation deliveries, and guest sessions even though the current repository uses one aggregate document for the public task repository. This preserves a common logical schema for future or supporting providers (src/…/UserTaskPersistenceSchemaProvider.cs• L7-95).
VNext limits
VNext provides the task repository only. Its conformance fixture does not provide durable guest-session or invitation-outbox stores, so those supporting suites do not run for VNext (test/…/UserTaskStoreFixture.cs• L42-50, test/…/VNextUserTaskStoreFixture.cs• L10-30).
VNext uses document version checks to implement the repository revision contract. A stale save becomes UserTaskRevisionConflictException, a failed compare-and-swap returns false, and an append-only audit write does not change the task revision. A concurrent audit write can be lost because audit is advisory in this document path; the task revision remains available for the caller's command (src/…/VNextUserTaskRepository.cs• L68-143).
References: src/…/VNextUserTaskRepository.cs• L21-143 src/…/UserTaskPersistenceSchemaProvider.cs• L7-95 src/…/ServiceCollectionExtensions.cs• L8-15 test/…/VNextUserTaskStoreFixture.cs• L10-38
Schema migration
The EF Core user-task schema has one provider-neutral migration helper. Each database package calls that helper from its own Initial migration, so the logical tables and indexes stay aligned while EF Core selects the target database types and migration history (src/…/UserTasksSchemaMigration.cs• L5-22, src/…/20260817120000_Initial.cs• L9-22).
The relational schema covers the task aggregate and its supporting durable state:
| Logical data | Relational units | Main reason |
|---|---|---|
| Task and workflow link | UserTasks | State, task identity, bookmark identity, workflow identity, status, scheduling, and revision |
| Eligibility | UserTaskCandidates, UserTaskSnapshotMembers, UserTaskExclusions | Candidate lookup, membership snapshots, and exclusions |
| History and commands | UserTaskEvents, UserTaskOperations | Append-only audit and operation tracking |
| Guest access | UserTaskInvitations, UserTaskInvitationDeliveries, UserTaskGuestSessions | Invitation state, protected delivery secrets, and revocable guest sessions |
The migration gives tenant and materialization keys unique scope, keeps bookmark lookup tenant-scoped, and adds indexes for status, assignee, priority, due date, workflow links, history, operations, invitations, delivery work, and guest-session revocation. Token and session hashes are unique so anonymous lookup can resolve one stored secret without trusting caller-supplied task context (src/…/UserTasksSchemaMigration.cs• L218-250).
VNext uses schema description and materialization rather than EF Core migrations. UserTaskPersistenceSchemaProvider declares schema version 1 and the same logical task support areas. The VNext document store rejects queries or saves that do not match the declared indexed contract, so repository index values and schema declarations must change together (src/…/UserTaskPersistenceSchemaProvider.cs• L7-78, src/…/VNextUserTaskRepository.cs• L186-211).
References: src/…/UserTasksSchemaMigration.cs• L9-264 src/…/UserTaskEntityConfiguration.cs• L9-190 src/…/UserTaskPersistenceSchemaProvider.cs• L7-95
Conformance expectations
The conformance suite runs the same repository expectations against the in-memory provider, SQLite EF Core, optional container-backed relational providers, and VNext. It uses a separate tenant for each test because the live fixtures can share a store. This checks provider behavior rather than only checking one implementation's code paths (test/…/UserTaskConformanceTestBase.cs• L7-29, test/…/EFCoreUserTaskStoreFixture.cs• L10-77).
The core repository expectations are:
- Stale saves throw
UserTaskRevisionConflictExceptionwith the task ID and expected revision. - Separate writers leave one winner and one conflict.
TryMutateAsyncreturnsfalsefor a stale revision or a declined mutation and commits nothing in either case.- Audit appends do not advance the task revision and ignore unknown tasks.
- Projection is idempotent on the materialization key.
- Tenant-safe lookups and visibility scope apply before counts, cursors, and page limits.
- Supported sort directions have stable cursors, due-date nulls stay last, and invalid cursors do not fail the request.
- Invitation lookup uses only the token hash.
The durable guest stores add their own expectations:
| Contract | Required behavior |
|---|---|
| Guest sessions | Resolve only live credentials, store no raw credential, honor expiry, and revoke by task or invitation without affecting unrelated sessions |
| Invitation outbox | Round-trip the secret and routing data, defer until due, remove completed or expired deliveries, bound batches, and stop after retry exhaustion |
| Fault handling | Leave failed saves and mutations unchanged so a retry can converge; keep invitation revocation safe on both sides of its aggregate commit |
These tests define the behavior that a new provider must preserve. A provider is not conforming if it works only for the happy path or if it leaks a store-specific concurrency error through the public contract (test/…/UserTaskRepositoryConformanceTests.cs• L8-34, test/…/UserTaskRepositoryConformanceTests.cs• L36-299, test/…/UserTaskInvitationOutboxConformanceTests.cs• L8-131, test/…/UserTaskGuestSessionConformanceTests.cs• L8-147, test/…/UserTaskFaultInjectionConformanceTests.cs• L13-229).
References: test/…/UserTaskRepositoryConformanceTests.cs• L8-299 test/…/UserTaskInvitationOutboxConformanceTests.cs• L8-131 test/…/UserTaskGuestSessionConformanceTests.cs• L8-147 test/…/UserTaskFaultInjectionConformanceTests.cs• L13-229
Change checklist
When these files or sections are changed, remember to consider these:
- When
IUserTaskRepositorychanges, update the in-memory repository, EF Core repository, VNext repository, and the shared conformance expectations together. - When a task field affects visibility or query order, align the in-memory predicates, EF Core SQL predicates, VNext index values, cursor rules, and schema indexes.
- When a participant, invitation, operation, or audit field changes, update both the EF Core aggregate mapping and its related storage unit or the VNext document schema.
- When revision behavior changes, preserve one public conflict type and the no-write guarantees for stale, declined, and failed mutations.
- When a new EF Core database provider is added, provide its connection setup, shell registration, migration assembly, and provider model hooks against the shared migration helper.
- When guest access behavior changes, keep credential hashing, expiry, task and invitation revocation, protected outbox storage, and retry exhaustion aligned across durable and in-memory services.
- When VNext adds an index or changes a query filter, update
CreateRequestand the schema provider at the same time because the document store requires declared index values. - When VNext gains or lacks a supporting store, update the provider fixture and the coverage boundary so missing guest-session or outbox behavior is explicit.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A provider saves a task without checking the expected revision | A stale caller can overwrite a newer task change | Use revision compare-and-swap and translate native errors to UserTaskRevisionConflictException. |
| A query applies visibility after count or paging | Unauthorized tasks leak through totals or displace visible tasks | Apply tenant, scope, and exclusion rules before counting, cursoring, and taking a page. |
| A projection ignores the materialization key | A redelivered bookmark creates duplicate user tasks | Enforce a tenant-scoped unique materialization key. |
| An audit append advances the task revision | A harmless read or reveal causes the next held command to conflict | Keep audit append-only and outside the task concurrency token. |
| An anonymous invitation lookup trusts a caller-supplied tenant or task ID | An attacker can probe or redirect lookup across task boundaries | Resolve from the token hash alone and keep the hash lookup tenant-agnostic. |
| A guest store keeps a raw session credential | A store read or dump can replay guest access | Store only a hash and check expiry and revocation on every resolve. |
| An invitation delivery remains after expiry or retry exhaustion | A secret can be delivered late or retried without end | Delete expired deliveries and abandon them after the configured retry schedule. |
| A VNext repository omits a declared index value | The document store rejects the write | Keep CreateRequest fields aligned with UserTaskPersistenceSchemaProvider. |
| An EF Core provider migration differs from the shared schema helper | Startup migration or later task reads fail for that database | Keep all provider migration assemblies functionally aligned with UserTasksSchemaMigration. |
| VNext is used for guest access without durable guest and outbox stores | Restart or failover can lose credentials or delivery secrets | Use the EF Core supporting stores or treat the VNext coverage boundary as unsupported. |
Key files
| File | Why to read it |
|---|---|
| src/…/UserTaskContracts.cs | Defines the public repository contract and the shared revision-conflict behavior. |
| src/…/UserTaskModels.cs | Defines the task aggregate, participant scope, revision, audit, operation, invitation, and query concepts. |
| src/…/InMemoryUserTaskRepository.cs | Shows the reference behavior for scope filtering, idempotent projection, revisions, audit, and cursors. |
| src/…/EFCoreUserTasksPersistenceFeature.cs | Shows how the relational repository and durable guest stores replace the core defaults. |
| src/…/EFCoreUserTaskRepository.cs | Shows the shared relational task read, query, projection, save, and concurrency boundary. |
| src/…/EFCoreUserTaskGuestStores.cs | Shows durable guest-session and invitation-delivery behavior. |
| src/…/UserTaskEntityConfiguration.cs | Shows the relational task units, tenant indexes, uniqueness rules, and concurrency token. |
| src/…/UserTasksSchemaMigration.cs | Defines the provider-neutral relational schema and migration shape. |
| src/…/EFCoreUserTasksPersistenceShellFeatureBase.cs | Shows the common configuration-driven registration for all EF Core database packages. |
| src/…/UserTaskPersistenceSchemaProvider.cs | Declares the VNext logical storage units and indexes. |
| src/…/VNextUserTaskRepository.cs | Shows how the public repository contract maps to versioned documents. |
| src/…/ServiceCollectionExtensions.cs | Shows VNext schema registration and repository replacement. |
| test/…/UserTaskRepositoryConformanceTests.cs | Defines the cross-provider repository contract. |
| test/…/UserTaskFaultInjectionConformanceTests.cs | Defines retry, failure, and cross-service consistency expectations. |