Skip to content

kokosda/dtf-determinism-analyzer

Repository files navigation

DTF Determinism Analyzer

A production-ready Roslyn analyzer that validates Durable Task Framework (DTF) orchestration code for determinism constraints. Ensures your orchestrator functions follow replay-safe patterns required by Azure Durable Functions and Durable Task Framework.

NuGet Version NuGet Downloads Build Status License

πŸš€ Quick Start

Installation

<PackageReference Include="DtfDeterminismAnalyzer" PrivateAssets="all" />

or

dotnet add package DtfDeterminismAnalyzer

Automatic Detection

The analyzer automatically detects determinism violations in orchestrator functions:

Azure Durable Functions:

[FunctionName("MyOrchestrator")]
public static async Task<string> RunOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context)
{
    var time = DateTime.Now; // ⚠️ DFA0001: Use context.CurrentUtcDateTime instead
    var id = Guid.NewGuid(); // ⚠️ DFA0002: Use context.NewGuid() instead
    
    // βœ… Corrected automatically with code fixes
    var safeTime = context.CurrentUtcDateTime;
    var safeId = context.NewGuid();
}

Durable Task Framework:

public static async Task<string> RunOrchestrationAsync(TaskOrchestrationContext context, string input)
{
    var time = DateTime.Now; // ⚠️ DFA0001: Use context.CurrentUtcDateTime instead
    var id = Guid.NewGuid(); // ⚠️ DFA0002: Use context.NewGuid() instead
    
    // βœ… Corrected automatically with code fixes
    var safeTime = context.CurrentUtcDateTime;
    var safeId = context.NewGuid();
}

Code Fixes

Press Ctrl+. (Windows) or Cmd+. (macOS) to apply automatic fixes for common violations.

πŸ“– Documentation

Topic Link
πŸ“¦ Installation & Setup Installation Guide
πŸ“‹ All Rules & Examples Complete Rules Documentation
βš™οΈ Configuration Configuration Guide
πŸ”§ Troubleshooting Troubleshooting Guide
οΏ½ Code Fixes Code Fixes Guide
οΏ½πŸ’‘ Code Examples Complete Examples
πŸ› οΈ Local Development Local Development Guide

βœ… Supported Rules

Rule Description Auto-Fix
DFA0001 DateTime.Now, DateTime.UtcNow, Stopwatch βœ…
DFA0002 Guid.NewGuid() calls βœ…
DFA0003 Random without deterministic seed ❌
DFA0004 Direct I/O operations ❌
DFA0005 Environment variable access ❌
DFA0006 Static mutable state access ❌
DFA0007 Thread.Sleep and blocking operations βœ…
DFA0008 Non-durable async operations ❌
DFA0009 Threading APIs (Task.Run, Thread) ❌
DFA0010 Non-durable input bindings ❌

🎯 Supported Frameworks

Azure Durable Functions (.NET 6+)

[FunctionName("Orchestrator")]
public static async Task<string> Run([OrchestrationTrigger] IDurableOrchestrationContext context)

Durable Task Framework (.NET Framework 4.6.1+, .NET Core 2.1+)

public class MyOrchestration : TaskOrchestration<string, string>
{
    public override async Task<string> RunTask(OrchestrationContext context, string input)
}

πŸ› οΈ IDE Support

  • Visual Studio 2019+ (16.3+) and 2022
  • VS Code with C# extension
  • JetBrains Rider 2020.3+

βš™οΈ Quick Configuration

Create or update .editorconfig:

[*.cs]
# Critical determinism violations
dotnet_diagnostic.DFA0001.severity = error
dotnet_diagnostic.DFA0002.severity = error
dotnet_diagnostic.DFA0006.severity = error

# Important but non-breaking
dotnet_diagnostic.DFA0004.severity = warning
dotnet_diagnostic.DFA0007.severity = warning

πŸ“¦ Sample Projects

Explore working examples in the repository:

🀝 Contributing

We welcome contributions! See our Contributing Guidelines for details.

Development Setup:

git clone https://github.com/kokosda/dtf-determinism-analyzer.git
cd dtf-determinism-analyzer

Quick start with automated script (cross-platform):

.\scripts\test-codefixes.ps1

Manual setup:

dotnet build
dotnet test

For comprehensive development workflows, code fix testing, and cross-platform setup instructions, see the Local Development Guide.

πŸ“‹ Project Status

  • βœ… 200+ Unit Tests covering all analyzer rules and code fixes
  • βœ… Automated CI/CD pipeline with GitHub Actions
  • βœ… NuGet Package published and maintained
  • βœ… Security Scanning with Dependabot and CodeQL

πŸ“š Learn More

πŸ“„ License

This project is licensed under the MIT License.


Made with ❀️ for the DTF community

About

Production-ready Roslyn analyzer for Durable Task Framework determinism validation

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages