Fix AOT build failure after search NuGet refactor#3433
Conversation
…actor PR #3364 introduced DefaultJsonTypeInfoResolver for ES client serialization, which breaks native AOT publish for Elastic.Documentation.Mcp.Remote. Restore source-generated EsJsonContext for Elastic.Internal.Search document types. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
📝 WalkthroughWalkthroughThis PR introduces AOT-compatible JSON serialization infrastructure for the Elasticsearch client. It adds three new files: a custom Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…ation Wire Elastic.Internal.Search.SourceGenerationContext together with docs-builder SourceGenerationContext, and add an AOT-safe converter for the internal RuleQueryMatchCriteria type used by query rules. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Register RuleQueryMatchCriteria converter via JsonConverterFactory during DefaultSourceSerializer setup only. Do not modify options when lazily creating JsonTypeInfo after they are frozen. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
UnsafeAccessor on object resolved get_QueryString on System.Object. Read QueryString via reflection with trim annotations instead. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/services/search/Elastic.Documentation.Search/Common/RuleQueryMatchCriteriaTypeInfoResolver.cs (1)
24-30: ⚡ Quick winGuard against caching
JsonTypeInfoacrossJsonSerializerOptionsinRuleQueryMatchCriteriaTypeInfoResolver
System.Text.Jsonrequires the returnedJsonTypeInfoto match the sameJsonSerializerOptionsinstance passed toGetTypeInfo; returning aJsonTypeInfocreated for different options can throw (e.g.,InvalidOperationException).- In this repo,
ElasticsearchClientJsonResolver.Defaultis only wired intoDefaultSourceSerializerfromElasticsearchClientAccessor, which is registered as a singleton, so the current code path is unlikely to exercise multipleJsonSerializerOptionsinstances. If the resolver is ever reused with multiple clients/options, remove the memoization or cache perJsonSerializerOptions.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/services/search/Elastic.Documentation.Search/Common/RuleQueryMatchCriteriaTypeInfoResolver.cs` around lines 24 - 30, The cached field _ruleQueryMatchCriteriaTypeInfo violates System.Text.Json's requirement that a JsonTypeInfo must be tied to the JsonSerializerOptions used to create it; update GetTypeInfo so it does not return a single memoized JsonTypeInfo for different options—either remove the _ruleQueryMatchCriteriaTypeInfo memoization and always call CreateRuleQueryMatchCriteriaTypeInfo(options) for the RuleQueryMatchCriteriaType case, or implement a cache keyed by the JsonSerializerOptions instance (e.g., a Dictionary<JsonSerializerOptions, JsonTypeInfo>) so CreateRuleQueryMatchCriteriaTypeInfo is invoked with the correct options; adjust or remove the _ruleQueryMatchCriteriaTypeInfo field and ensure GetTypeInfo still compares against RuleQueryMatchCriteriaType.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@src/services/search/Elastic.Documentation.Search/Common/RuleQueryMatchCriteriaTypeInfoResolver.cs`:
- Around line 24-30: The cached field _ruleQueryMatchCriteriaTypeInfo violates
System.Text.Json's requirement that a JsonTypeInfo must be tied to the
JsonSerializerOptions used to create it; update GetTypeInfo so it does not
return a single memoized JsonTypeInfo for different options—either remove the
_ruleQueryMatchCriteriaTypeInfo memoization and always call
CreateRuleQueryMatchCriteriaTypeInfo(options) for the RuleQueryMatchCriteriaType
case, or implement a cache keyed by the JsonSerializerOptions instance (e.g., a
Dictionary<JsonSerializerOptions, JsonTypeInfo>) so
CreateRuleQueryMatchCriteriaTypeInfo is invoked with the correct options; adjust
or remove the _ruleQueryMatchCriteriaTypeInfo field and ensure GetTypeInfo still
compares against RuleQueryMatchCriteriaType.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 6e88c9b5-46a1-4e27-a796-9ffdbda7e6a2
📒 Files selected for processing (5)
src/services/search/Elastic.Documentation.Search/Common/ElasticsearchClientAccessor.cssrc/services/search/Elastic.Documentation.Search/Common/ElasticsearchClientJsonResolver.cssrc/services/search/Elastic.Documentation.Search/Common/RuleQueryMatchCriteriaJsonConverter.cssrc/services/search/Elastic.Documentation.Search/Common/RuleQueryMatchCriteriaTypeInfoResolver.cssrc/services/search/Elastic.Documentation.Search/Elastic.Documentation.Search.csproj
✅ Files skipped from review due to trivial changes (1)
- src/services/search/Elastic.Documentation.Search/Elastic.Documentation.Search.csproj
Why
After #3364, main CI fails when publishing the native AOT
Elastic.Documentation.Mcp.Remotecontainer.ElasticsearchClientAccessorusedDefaultJsonTypeInfoResolver(), which is not compatible with trimming/native AOT (IL2026/IL3050).What
Restore source-generated JSON serialization for the Elasticsearch client by reintroducing
EsJsonContextforElastic.Internal.Searchdocument types (DocumentationDocument,ParentDocument) and wiring it back intoDefaultSourceSerializer, matching the pre-refactor approach without reflection-based resolvers.Made with Cursor