Make HostedFileDownloadStream explicitly read-only#7394
Merged
Conversation
Co-authored-by: stephentoub <[email protected]>
Co-authored-by: stephentoub <[email protected]>
Copilot created this pull request from a session on behalf of
stephentoub
March 14, 2026 02:24
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes HostedFileDownloadStream explicitly read-only at the base Stream contract level, so all download-stream implementations consistently advertise and enforce non-writability.
Changes:
- Override
CanWriteto always returnfalseonHostedFileDownloadStreamand make all write entry points throwNotSupportedException. - Remove redundant write-related overrides from
OpenAIFileDownloadStreamso it inherits the base read-only behavior. - Add unit tests verifying
CanWrite == falseand that write APIs throwNotSupportedException.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Files/HostedFileDownloadStreamTests.cs | Adds coverage asserting the base stream is read-only and write APIs throw. |
| src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIFileDownloadStream.cs | Removes duplicated write-path overrides to rely on the base read-only contract. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Files/HostedFileDownloadStream.cs | Centralizes read-only enforcement in the abstraction by overriding write members to throw. |
You can also share your feedback on Copilot code review. Take the survey.
stephentoub
approved these changes
Mar 15, 2026
jozkee
approved these changes
Mar 16, 2026
jeffhandley
pushed a commit
to jeffhandley/extensions
that referenced
this pull request
Mar 17, 2026
* Initial plan * Make HostedFileDownloadStream read-only by default Co-authored-by: stephentoub <[email protected]> * Fix HostedFileDownloadStream write overload ordering Co-authored-by: stephentoub <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: stephentoub <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HostedFileDownloadStreamdid not consistently advertise or enforce its read-only contract at the base type. This change makes the abstraction explicitly non-writable so all implementations inherit the same behavior by default.Base stream contract
CanWriteinHostedFileDownloadStreamto always returnfalseNotSupportedExceptionat the base class:SetLengthBeginWrite/EndWriteWriteByteWrite(byte[], ...)WriteAsync(byte[], ...)Write(ReadOnlySpan<byte>)WriteAsync(ReadOnlyMemory<byte>)Implementation cleanup
OpenAIFileDownloadStreamCoverage
CanWrite == falseNotSupportedExceptionMicrosoft Reviewers: Open in CodeFlow