Skip to content

Mitigation for mono/wasm/etc. explicit interface covariance issue#138

Merged
trrwilson merged 12 commits intomainfrom
user/travisw/mono-content-speculation
Jun 14, 2024
Merged

Mitigation for mono/wasm/etc. explicit interface covariance issue#138
trrwilson merged 12 commits intomainfrom
user/travisw/mono-content-speculation

Conversation

@trrwilson
Copy link
Copy Markdown
Collaborator

@trrwilson trrwilson commented May 30, 2024

See: dotnet/runtime#103365

The implication is that any of our types with an abstract base (e.g. ChatMessage : IJsonModel<ChatMessage>) and derived instance types (e.g. SystemChatMessage : ChatMessage, IJsonModel<SystemChatMessage>) currently have the base explicit interface implementation invoked in impacted environments (e.g. IJsonModel<ChatMessage>.Write()).

The mitigation approach:

  • In impacted request models, define a protected abstract void WriteCore(Utf8JsonWriter, ModelReaderOptions)
  • Move all serialization logic for affected derived types into overrides of WriteCore
  • Customize the behavior of IJsonModel<T>.Write() to invoke WriteCore() for all (base+derived) affected types, ensuring that the instance type's serialization logic is used independently of the explicit interface covariance applied

This change addresses the behavior of Assistants.MessageContent, Assistants.ToolDefinition, and Chat.ChatMessage. Several more abstract types exist in the Assistants namespace, but these are response models -- given moving code to the custom layer comes at the cost of maintainability, leaving direct manual MRW serialization of e.g. RunStepDetails impacted feels like the right initial tradeoff for a mitigation while the runtime fix is awaited.

@trrwilson trrwilson changed the title [Not for merge] speculative changes to diagnose mono serialization differences Mitigation for mono/wasm/etc. explicit interface covariance issue Jun 13, 2024
@trrwilson trrwilson merged commit f9947a3 into main Jun 14, 2024
joseharriaga added a commit that referenced this pull request Sep 3, 2024
…238)

This is the same issue that we saw previously with `ChatMessage`'s serialization in unity/mono/etc.

See: dotnet/runtime#103365

See: #138
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