Skip to content

Persist activity invocation start times in history - #1439

Open
wangbill (YunchuWang) wants to merge 1 commit into
mainfrom
yunchuwang-activity-start-time-history
Open

wangbill (YunchuWang) wants to merge 1 commit into
mainfrom
yunchuwang-activity-start-time-history

Conversation

@YunchuWang

Copy link
Copy Markdown
Member

Summary

Related to Azure/azure-functions-durable-extension#2132. This is a Core prerequisite, not a complete resolution of the Functions feature request.

Add nullable StartedTime metadata to TaskCompletedEvent and TaskFailedEvent, sampled in UTC immediately before TaskActivity.RunAsync. This lets history consumers distinguish time spent queued from the activity invocation without using sampled telemetry or changing existing timestamps, constructors, event types, or replay behavior.

Semantics and compatibility

  • Record the invocation associated with the final response's TaskScheduledId, including normal and unexpected activity failures and middleware-replaced responses for that same task.
  • Keep the value unknown for legacy history, skipped invocations, middleware-only failures, mismatched response IDs, and synthesized default completions. Unknown values are omitted from JSON.
  • Keep timing local to each dispatch. Redelivery captures a new start; abandoned invocations do not become history entries. This does not expose in-flight starts or a complete attempt log.
  • Measure the RunAsync boundary, including conversion and host work inside it, rather than claiming the exact entry into a user function. Cross-worker clock skew still applies.

Azure Storage preserves the field through response serialization, History-table persistence, and history JSON. The existing Functions JSON status-history projection can retain it once a released Core package containing this change is adopted. Functions protobuf history mappings require a separate update; other providers/protocols and an actual Functions host have not been validated here. No dependency versions are changed and the related extension issue is intentionally not closed.

Validation

  • Core dispatcher/serialization and related regressions: 33 passed on .NET 8; 18 passed on .NET Framework 4.8.
  • Azure Storage response serializers, table/history JSON persistence against isolated local Azurite, and related serialization regressions: 15 passed on each framework.
  • 81 targeted test cases passed, none skipped. New tests use deterministic fixtures and direct dispatcher execution without sleeps or elapsed-time thresholds.
  • A separate disposable .NET 8 harness ran a real Core/Azure Storage orchestration with one completed and one failed activity, then exercised the released Functions 3.18.1 DurableClient.GetStatusAsync against that stored history in all four input/output projection combinations. All four retained StartedTime, ScheduledTime, and Timestamp. This exercised the real status client, not a Functions host. The worker, task hub, and local emulator state were cleaned up.

AI disclosure

The implementation, tests, documentation, and PR description were generated by GitHub Copilot. Human review is still required; no human-review attestation is made.

Related to Azure/azure-functions-durable-extension#2132.

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

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.

🟢 Approval recommended

No active review issues remain for the activity invocation start-time metadata change.

No open issues 🎉

What changed in this PR

Adds activity invocation start times to Core history so consumers can distinguish queueing from invocation time. This is a prerequisite for Durable Functions support, not a complete implementation of the requested feature.

Changes:

  • Adds nullable StartedTime metadata to activity completion and failure events, captured immediately before RunAsync.
  • Preserves existing timestamps and replay behavior, leaving start times unknown when no matching invocation was observed.
  • Adds dispatcher, serialization, and Azure Storage persistence tests, plus documentation of timing semantics and provider limitations.
File Description
test/​DurableTask.Core.Tests/​ActivityStartedTimeTests.cs Tests invocation timing, middleware handling, redelivery, and serialization.
test/​DurableTask.AzureStorage.Tests/​MessageManagerTests.cs Tests start-time preservation in response message serialization.
test/​DurableTask.AzureStorage.Tests/​AzureTableTrackingStoreTest.cs Tests History-table and history JSON persistence.
src/​DurableTask.Core/​TaskActivityDispatcher.cs Captures invocation start time and attaches it to matching responses.
src/​DurableTask.Core/​History/​TaskFailedEvent.cs Adds optional start-time metadata to failed activity events.
src/​DurableTask.Core/​History/​TaskCompletedEvent.cs Adds optional start-time metadata to completed activity events.
docs/​concepts/​activities.md Documents timing semantics, compatibility, and provider support.

Review effort: Balanced

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.

2 participants