Honor declared activity return type during GRPC serialization#3301
Draft
Copilot wants to merge 3 commits into
Draft
Honor declared activity return type during GRPC serialization#3301Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix gRPC serializer to respect Activity return type with JsonPolymorphic
Honor declared activity return type during GRPC serialization
Dec 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
What changed?
ObjectConverterShimto unwrap declared-type hints and serialize using the declared type, avoiding runtime-type polymorphism drift.Why is this change needed?
[JsonPolymorphic]scenarios; declared activity return types now flow into serialization.Issues / work items
Project checklist
pending_docs.mdrelease_notes.mdWebJobs.Extensions.DurableTaskpackage/src/Worker.Extensions.DurableTask/AssemblyInfo.csEventSourcelogsv2.xbranchWebJobs.Extensions.DurableTaskv3.x and will be retained only in thedevandmainbranchesAI-assisted code disclosure (required)
Was an AI tool used? (select one)
If AI was used:
ObjectConverterShim.cs,TypeHintingDurableTaskFactory.cs,ObjectConverterShimTests.csAI verification (required if AI was used):
Testing
Automated tests
dotnet test test/Worker.Extensions.DurableTask.TestsManual validation (only if runtime/behavior changed)
1.
2.
3.
Notes for reviewers
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
azfunc.pkgs.visualstudio.com/opt/hostedtoolcache/CodeQL/2.23.8/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.23.8/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>[out-of-proc] GRPC serializer does not respect Activity return type when
[JsonPolymorphic]is used</issue_title><issue_description>### Description
If activity is defined to return a base type of some hierarchy that supports polymorphic (de-)serialization, the actual serialization of activity output happens according to its runtime type rather than declared type, which breaks polymorphic feature of
System.Text.Json.We were able to trace it to
Microsoft.Azure.Functions.Worker.Rpc.RpcExtensions.ToRpcDefault, which callsserializer.Serialize(value)?.ToString();(hereserializerisJsonObjectSerializer). This overload has the following signature:When called with one parameter,
inputTypeis null. The implementation itself callsthus resolving runtime type of the return value, and serializing accordingly, instead of decalred type of activity.
Expected behavior
GRPC serializer passes return type as
inputType, performing correct JSON serialization of the result.Actual behavior
Serialization happens according to runtime type, which breaks polymorphic serialization of
System.Text.JsonRelevant source code snippets
Program.cs
.csproj
Known workarounds
There is no reliable workaround because
ObjectSerializerdoes not get type information or any other required information. If there are multiple functions that retu...[JsonPolymorphic]is used #3013✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.