Skip to content

Add AWSLambda0145 diagnostic for unregistered durable envelope types#2464

Draft
GarrettBeatty wants to merge 1 commit into
devfrom
feature/durable-serializer-context-diagnostic
Draft

Add AWSLambda0145 diagnostic for unregistered durable envelope types#2464
GarrettBeatty wants to merge 1 commit into
devfrom
feature/durable-serializer-context-diagnostic

Conversation

@GarrettBeatty

@GarrettBeatty GarrettBeatty commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a new build-time diagnostic AWSLambda0145 (Warning) to the Annotations source generator.

Motivation

With the Annotations model, a [DurableExecution] function's generated handler has the signature:

Task<DurableExecutionInvocationOutput> Handler(DurableExecutionInvocationInput input, ILambdaContext context)

Users never see DurableExecutionInvocationInput / DurableExecutionInvocationOutput in their own code — the generator introduces them. If the function registers the source-generator serializer (SourceGeneratorLambdaJsonSerializer<TContext>), the durable runtime (de)serializes that envelope through the user's JsonSerializerContext. Unlike the reflection-based DefaultLambdaJsonSerializer, a source-gen context only handles types explicitly registered via [JsonSerializable]. If the envelope types aren't registered, the function fails at invocation time with no build-time signal.

This diagnostic surfaces the problem at build time, consistent with the other durable diagnostics (AWSLambda0142–0144).

Behavior

Emitted (Warning) only when all hold:

  • the method has [DurableExecution], and
  • the registered serializer (method-level attribute, else assembly-level) is SourceGeneratorLambdaJsonSerializer<TContext>, and
  • TContext (walking its base contexts) does not register a given envelope type via [JsonSerializable(typeof(...))].

One warning per missing envelope type. Silent for DefaultLambdaJsonSerializer / any non-source-gen serializer, and skipped if the durable types can't be resolved (package not referenced — other diagnostics cover that).

Changes

  • TypeFullNames.cs: add SourceGeneratorLambdaJsonSerializer1andJsonSerializableAttribute` constants.
  • DiagnosticDescriptors.cs: add DurableExecutionMissingSerializableEnvelope (AWSLambda0145, Warning).
  • AnalyzerReleases.Unshipped.md: register the new rule.
  • LambdaFunctionValidator.cs: add ValidateDurableExecutionSerializerContext, called from ValidateDurableExecution.
  • Tests: DurableExecutionSerializerContextDiagnosticsTests — both registered (no diagnostic), one missing, both missing, and DefaultLambdaJsonSerializer (no diagnostic).
  • Added AutoVer changefile (Amazon.Lambda.Annotations, Minor).

Testing

  • dotnet build -c Release on the generator: clean.
  • All 50 DurableExecution* generator tests pass (net10.0), including the 4 new ones.

When a [DurableExecution] function registers the source-generator serializer
(SourceGeneratorLambdaJsonSerializer<TContext>), the durable invocation envelope
types DurableExecutionInvocationInput and DurableExecutionInvocationOutput must
be registered on the JsonSerializerContext with [JsonSerializable]. Unlike the
reflection-based DefaultLambdaJsonSerializer, the context only serializes types
explicitly registered, so a missing registration fails only at invocation time.
The generator now emits AWSLambda0145 (Warning) at build time when either
envelope type is missing.
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.

1 participant