Skip to content

Check .Message for null #387#389

Merged
awaescher merged 1 commit into
mainfrom
fix-chatsendasync-null-guard
Jul 15, 2026
Merged

Check .Message for null #387#389
awaescher merged 1 commit into
mainfrom
fix-chatsendasync-null-guard

Conversation

@awaescher

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings July 15, 2026 06:18

Copilot AI 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.

Pull request overview

Addresses #387 by hardening streaming chat response handling so that response chunks with a null Message are ignored, preventing null dereferences while preserving the final assembled assistant message in chat history.

Changes:

  • Update Chat.SendAsAsync(...) to skip streamed chunks where answer is null or answer.Message is null, and to use a non-null answerMessageChunk for Thinking/Content access.
  • Add a unit test ensuring streaming ignores response chunks that do not contain a message.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
test/ChatTests.cs Adds coverage to ensure streamed chunks with Message = null are ignored and do not break streaming/output.
src/OllamaSharp/Chat.cs Prevents null dereferences by skipping chunks without a Message and reading Thinking/Content via a non-null pattern match.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@awaescher
awaescher merged commit d22b822 into main Jul 15, 2026
2 checks passed
@awaescher
awaescher deleted the fix-chatsendasync-null-guard branch July 15, 2026 06:35
This was referenced Jul 15, 2026
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.

2 participants