Skip to content

Make predictive C# sessions Native AOT-safe - #1314

Merged
Akshay Sonawane (apsonawane) merged 3 commits into
mainfrom
asonawane/predictive-json-aot
Nov 10, 2026
Merged

Akshay Sonawane (apsonawane) merged 3 commits into
mainfrom
asonawane/predictive-json-aot

Conversation

@apsonawane

@apsonawane Akshay Sonawane (apsonawane) commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make the C# RankingSession.RankAsync and DecisionSession.DecideAsync helpers safe to consume from Native AOT applications.

Problem

Predictive DTOs were registered in the SDK's shared JsonSerializationContext, which also contains Betalgo OpenAI types. Referencing the typed predictive helpers rooted that full context and caused Native AOT consumers to fail with Betalgo MessageConverter IL2026/IL3050 diagnostics.

This blocks direct typed-session use in microsoft/foundry-local-cli#73.

Changes

  • Move ranking and decision DTO registrations into a dedicated source-generated NonGenerativeJsonSerializationContext.
  • Point RankingSession and DecisionSession at the isolated context.
  • Keep existing OpenAI serialization behavior unchanged.
  • Reduce ranking result validation allocations by replacing per-response hash sets and index-string allocations.
  • Store decision snapshots as value types and validate answer keys in one pass.

Validation

  • C# SDK builds for net8.0, net9.0, and netstandard2.0.
  • Predictive session tests pass.
  • A local ranking/decision Native AOT consumer publish completes without IL2026, IL3050, Betalgo IL2104, or IL3053 warnings.

Copilot AI balanced review requested due to automatic review settings November 10, 2026 07:05
@vercel

vercel Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
foundry-local Ready Ready Preview Nov 10, 2026 7:32am UTC

Request Review

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.

🟡 Changes recommended

The sample publish overwrites the net8.0 SDK assembly without the required version properties, causing the subsequent pack step to include incorrect version metadata despite the earlier version check.

1 open issue
What changed in this PR

This PR isolates predictive-session JSON serialization from OpenAI types so C# applications can use typed ranking and decision helpers with Native AOT.

Changes:

  • Move predictive DTO registrations into a dedicated source-generated context and update both session helpers.
  • Replace reflection-based JSON creation in the example and enable Native AOT with selected diagnostics treated as errors.
  • Add a CI Native AOT publish check for the example.
File Description
sdk_v2/​cs/​src/​RankingSession.cs Use the isolated predictive serialization context.
sdk_v2/​cs/​src/​Detail/​NonGenerativeJsonSerializationContext.cs Define source-generated metadata for predictive DTOs.
sdk_v2/​cs/​src/​Detail/​JsonSerializationContext.cs Remove predictive registrations from the shared context.
sdk_v2/​cs/​src/​DecisionSession.cs Use the isolated predictive serialization context.
sdk_v2/​cs/​examples/​RankingAndDecision/​RankingAndDecision.csproj Enable Native AOT and diagnostic enforcement.
sdk_v2/​cs/​examples/​RankingAndDecision/​Program.cs Create JSON values without reflection-based serialization.
.pipelines/​templates/​steps-build-cs.yml Publish the predictive example with Native AOT in CI.

Review effort: Balanced

Comment thread .pipelines/templates/steps-build-cs.yml Resolved

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 are reported for the predictive-session serialization isolation and validation changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@apsonawane
Akshay Sonawane (apsonawane) merged commit cd4b0ce into main Nov 10, 2026
79 checks passed
@apsonawane
Akshay Sonawane (apsonawane) deleted the asonawane/predictive-json-aot branch November 10, 2026 09:13

This branch was successfully deployed

1 active deployment
Preview — b08fb92a Deployed Nov 10, 2026 by vercel[bot]
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.

3 participants