string ActivityId { get; }
Source
Gets the immutable activity identity.
Separates immutable provider-operation identity from retry and lease generations.
The provider key is derived from ActivityId
, never from an attempt or lease. A new attempt or lease therefore cannot silently create a second logical provider operation.
DurableWorkerExecutionIdentity CreateInitial(string activityId, long leaseGeneration, long scopeGeneration, string runtimeEpoch)
Creates the first fenced execution identity for one logical provider operation.
activityId
leaseGeneration
scopeGeneration
runtimeEpoch
An identity whose attempt number is one.
ArgumentException
ArgumentOutOfRangeException
DurableWorkerExecutionIdentity Create(string activityId, int attemptNumber, long leaseGeneration, long scopeGeneration, string runtimeEpoch)
Creates a fenced identity from provider-authoritative attempt and generation values.
activityId
attemptNumber
leaseGeneration
scopeGeneration
runtimeEpoch
A validated execution identity.
ArgumentException
ArgumentOutOfRangeException
DurableWorkerExecutionIdentity Advance(int attemptNumber, long leaseGeneration, long scopeGeneration, string runtimeEpoch)
Advances retry and fencing generations while retaining the immutable provider-operation identity.
attemptNumber
leaseGeneration
scopeGeneration
runtimeEpoch
A new identity that preserves ActivityId
and ProviderKey
.
ArgumentException
ArgumentOutOfRangeException
string ActivityId { get; }
Source
Gets the immutable activity identity.
int AttemptNumber { get; }
Source
Gets the monotonically increasing execution attempt number.
long LeaseGeneration { get; }
Source
Gets the exact lease generation that authorized execution.
long ScopeGeneration { get; }
Source
Gets the owning scope lifecycle generation.
string RuntimeEpoch { get; }
Source
Gets the out-of-band runtime recovery epoch.
string ProviderKey { get; }
Source
Gets the immutable activity-derived provider idempotency key.
Validates the privacy-safe metadata and diagnostic text contract used by durable worker envelopes and diagnostics.
The validator intentionally uses conservative name and value checks for the metadata channel. Store raw business payloads in app-owned data stores, not in worker metadata. Metadata should contain opaque ids, reason codes, bounded counts, and classified safe labels that can appear in logs or repair dashboards.
IReadOnlyDictionary<string, string> CopySafe(IReadOnlyDictionary<string, string>? metadata, string paramName = "metadata")
Validates a metadata dictionary and returns a copied read-only dictionary.
metadata
paramName
A read-only copy of the supplied safe metadata.
ArgumentException
DurableWorkerUnsafeMetadataException
void EnsureSafe(IReadOnlyDictionary<string, string>? metadata, string paramName = "metadata")
Validates that metadata is safe for diagnostics, logs, durable facts, and projection repair reports.
metadata
paramName
ArgumentException
DurableWorkerUnsafeMetadataException
string CopySafeDiagnosticText(string value, string label, string paramName)
Validates diagnostic text and returns a trimmed safe value.
value
label
paramName
The trimmed diagnostic text.
ArgumentException
value
is null, empty, or whitespace.DurableWorkerUnsafeMetadataException
value
appears unsafe.Records durable worker execution facts and repairs visible projections from those facts.
TWork
TResult
TProjection
Implementations are app-owned and persistence-specific. The contract separates side-effect execution from projection repair: TryClaimAsync
decides whether executor activity may run, CompleteAsync
records a terminal fact, and reconciliation methods update projections without re-running executor activity.
ValueTask<DurableWorkerEnvelope<TWork>> TryClaimAsync(TWork work, DurableWorkerCorrelation correlation, CancellationToken cancellationToken = default)
Attempts to claim a work item before executor activity is scheduled.
work
correlation
cancellationToken
A claim envelope. DurableWorkerProjectionOutcome.Claimed
means executor activity may be scheduled; duplicate, stale, conflict, and unrecoverable outcomes must not schedule executor activity.
ValueTask<DurableWorkerEnvelope<TResult>> CompleteAsync(TWork work, TResult result, DurableWorkerCorrelation correlation, CancellationToken cancellationToken = default)
Records a terminal execution fact after executor activity completes.
work
result
correlation
cancellationToken
A completion envelope. Successful completion should lead to projection repair; duplicate completions must not trigger projection repair.
ValueTask<DurableWorkerEnvelope<TProjection>> ReconcileProjectionAsync(TWork work, TResult result, DurableWorkerCorrelation correlation, CancellationToken cancellationToken = default)
Repairs the visible projection for one terminal execution fact.
work
result
correlation
cancellationToken
A projection envelope describing repaired, noop, stale, conflict, or unrecoverable repair behavior.
IAsyncEnumerable<DurableWorkerEnvelope<TProjection>> ReconcilePendingProjectionsAsync(DurableWorkerProjectionRepairRequest request, CancellationToken cancellationToken = default)
Repairs a bounded batch of stale or missing projections from durable terminal facts.
request
cancellationToken
Projection repair envelopes for the bounded repair pass.
Describes a bounded projection repair pass over durable worker completion facts.
Repair requests are intentionally bounded. Hosts should use small batches and repeatable cursors rather than unbounded background scans. The contract repairs projections only; it must not re-run executor side effects.
DateTimeOffset Now { get; }
Source
Gets the clock value used to evaluate stale projections.
TimeSpan MaxStaleness { get; }
Source
Gets the maximum acceptable projection staleness before repair is attempted.
int MaxItems { get; }
Source
Gets the maximum number of pending projection repairs to inspect or return.
Registers the passive AppSurface durable worker contract surface.
The module intentionally does not register queues, storage providers, background services, Durable Task workers, EF Core contexts, Postgres connections, endpoints, or authentication handlers. Host applications own runtime infrastructure and persistence; this package provides the shared worker contracts.
Correlates one durable worker operation across claims, executor activity, completion facts, and projection repair.
Correlation values should be stable safe identifiers. Do not use provider URLs, raw payload ids that expose private content, credentials, email bodies, prompts, or model output as correlation values.
string RequireText(string value, string paramName)
Validates and trims a durable worker identifier.
value
paramName
The trimmed identifier value.
ArgumentException
value
is null, empty, or whitespace.string WorkerName { get; }
Source
Gets the stable worker or chain name.
string WorkId { get; }
Source
Gets the stable app-owned work identifier.
string InstanceId { get; }
Source
Gets the durable runtime instance identifier.
string AttemptId { get; }
Source
Gets the attempt, fence, or generation identifier.
Carries a durable worker outcome, correlation identifiers, optional typed payload, and privacy-safe metadata.
TPayload
Envelopes are the stable boundary between app-owned worker contracts and host/runtime adapters. They describe what happened; they do not execute side effects, persist data, or schedule runtime work by themselves.
DurableWorkerEnvelope<TPayload> CreateNative(DurableWorkerProjectionOutcome outcome, string reasonCode, DurableWorkerRetryability retryability, DurableWorkerCorrelation correlation, DurableWorkerExecutionIdentity executionIdentity, TPayload? payload = default, IReadOnlyDictionary<string, string>? metadata = null, DurableWorkerDiagnostic? diagnostic = null)
Creates a native-runtime envelope with required execution and fencing identity.
outcome
reasonCode
retryability
correlation
executionIdentity
payload
metadata
diagnostic
A validated native-runtime envelope.
ArgumentException
ArgumentNullException
correlation
or executionIdentity
is null.ArgumentOutOfRangeException
outcome
or retryability
is not defined.DurableWorkerUnsafeMetadataException
DurableWorkerProjectionOutcome Outcome { get; }
Source
Gets the observable worker outcome.
string ReasonCode { get; }
Source
Gets the stable machine-readable reason code.
DurableWorkerRetryability Retryability { get; }
Source
Gets the retry classification for this outcome.
DurableWorkerCorrelation Correlation { get; }
Source
Gets correlation identifiers for the operation.
TPayload? Payload { get; }
Source
Gets the optional typed payload associated with the outcome.
IReadOnlyDictionary<string, string> Metadata { get; }
Source
Gets sanitized metadata for logs, durable facts, and projection repair reports.
DurableWorkerDiagnostic? Diagnostic { get; }
Source
Gets optional sanitized diagnostic details.
DurableWorkerExecutionIdentity? ExecutionIdentity { get; }
Source
Gets the native durable execution identity when the envelope was created by a fencing-aware runtime.
Legacy adapters may leave this value null
. Native runtimes must populate it before invoking a provider executor; projection repair must not use it as authority to repeat an external effect.
Thrown when durable worker diagnostics or metadata contain values that are unsafe to persist or publish.
AppSurface worker metadata is designed for logs, projections, and repair reports. It must use stable identifiers, reason codes, and sanitized values rather than raw source payloads, credentials, OAuth tokens, provider URLs, model output, prompts, message bodies, attachments, or unclassified sensitive text.
Privacy-safe diagnostic details for a durable worker outcome.
Diagnostics are suitable for logs, repair dashboards, and durable records. Keep them explanatory but sanitized: include stable codes, cause and fix guidance, safe counts, and opaque ids. Do not include raw provider payloads, tokens, credentials, prompts, model output, email bodies, attachments, or unclassified sensitive values.
string Code { get; }
Source
Gets the stable machine-readable diagnostic code.
string Problem { get; }
Source
Gets the safe problem description.
string Cause { get; }
Source
Gets the safe cause description.
string Fix { get; }
Source
Gets the safe fix guidance.
DurableWorkerRetryability Retryability { get; }
Source
Gets the retry classification for this diagnostic.
IReadOnlyDictionary<string, string> Metadata { get; }
Source
Gets sanitized diagnostic metadata.
Executes the side-effecting portion of a durable worker chain.
TWork
TResult
Executors are expected to run inside host-owned durable activities, queue handlers, or equivalent runtime work. They should not be invoked by projection repair paths. Projection repair uses durable completion facts through IDurableWorkerProjectionContract{TWork,TResult,TProjection}
instead.
ValueTask<TResult> ExecuteAsync(DurableWorkerEnvelope<TWork> work, CancellationToken cancellationToken = default)
Runs the side-effecting worker activity for a claimed work item.
work
cancellationToken
The terminal result that should be recorded with the projection contract.
Describes whether a durable worker outcome should be retried automatically.
These values are intended for workflow decisions and diagnostics. They do not execute retries directly; host adapters translate the value into the chosen runtime's retry, timer, or operator-alert behavior.
Identifies the observable result of durable worker claim, completion, or projection repair work.
The numeric values are part of the public worker contract. Do not reorder, remove, renumber, or reuse values. Additive values must be appended with explicit numbers and documented migration behavior.