Skip to content

Prevent Dock JSON source-generation context collisions - #1110

Open
wieslawsoltes wants to merge 3 commits into
masterfrom
agent/issue-1085-json-context-collision
Open

Prevent Dock JSON source-generation context collisions#1110
wieslawsoltes wants to merge 3 commits into
masterfrom
agent/issue-1085-json-context-collision

Conversation

@wieslawsoltes

Copy link
Copy Markdown
Owner

Summary

  • restrict Dock's nested System.Text.Json generator output to DockSystemTextJsonContext.*
  • leave application-owned JsonSerializerContext artifacts to the SDK generator
  • add an integration regression with two nested application contexts matching the reported scenario

Root cause

Dock runs the System.Text.Json generator internally to materialize metadata for its generated context. That nested run sees every JsonSerializerContext in the consumer compilation, and Dock previously republished every resulting artifact. The SDK generator also publishes the application contexts during the normal build, so their partial members and generated attributes were emitted twice.

Impact

Consumers can combine [assembly: DockJsonSourceGeneration] with one or more application JsonSerializerContext classes. Dock continues to emit its own metadata context, while application contexts retain their normal SDK-generated APIs.

Generator pipeline

The semantic input remains the complete consumer compilation so Dock types resolve normally. The per-context emission boundary now filters the nested generator result by Dock's stable context hint-name prefix; shared resolver generation is unchanged. This keeps output ownership deterministic without altering discovery or runtime behavior.

Validation

  • reproduced the original failure with two nested contexts: 52 duplicate-member/attribute compilation errors before the fix
  • dotnet test tests/Dock.Serializer.SystemTextJson.SourceGenTests/Dock.Serializer.SystemTextJson.SourceGenTests.csproj --filter FullyQualifiedName~DockGenerator_CoexistsWithApplicationJsonContexts --no-restore -maxcpucount:1 (1 passed)
  • dotnet test tests/Dock.Serializer.SystemTextJson.Generators.UnitTests/Dock.Serializer.SystemTextJson.Generators.UnitTests.csproj --no-restore -maxcpucount:1 (8 passed)
  • dotnet test tests/Dock.Serializer.SystemTextJson.SourceGenTests/Dock.Serializer.SystemTextJson.SourceGenTests.csproj --no-build --no-restore -maxcpucount:1 (13 passed)
  • dotnet build samples/DockSystemTextJsonSourceGenAotSample/DockSystemTextJsonSourceGenAotSample.csproj --no-restore -maxcpucount:1 (succeeded)
  • generated-file audit: application contexts appear only under System.Text.Json.SourceGeneration; Dock output contains only DockSystemTextJsonContext.*
  • git diff --check

Fixes #1085

@wieslawsoltes
wieslawsoltes marked this pull request as ready for review July 14, 2026 21:30

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 635dee0afd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Dock.Serializer.SystemTextJson.Generators/DockJsonSourceGenerator.cs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b1ba704b3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Dock.Serializer.SystemTextJson.Generators/DockJsonSourceGenerator.cs Outdated
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot use JsonSerializerContext while DockJsonSourceGeneration is in use

1 participant