.Net: fix: address three static analysis issues (audio format, text search, KernelProcess)#13925
.Net: fix: address three static analysis issues (audio format, text search, KernelProcess)#13925octo-patch wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…ernelProcess - Replace duplicate ChatOutputAudioFormat.Wav check with Aac in GetAudioOutputMimeType; update error message to include 'aac' - Remove dead LINQ variable in TextSearchStore.GetTextSearchResultsAsync and reuse it in the return statement to avoid duplicate expression - Assign the threads constructor parameter to KernelProcess.Threads property so it is not silently discarded (fixes microsoft#13922) Co-Authored-By: Octopus <liyuan851277048@icloud.com>
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 93%
✓ Correctness
Three clean bug fixes: (1) A duplicate dead-code Wav format check is replaced with a new Aac format handler, correctly adding AAC support while the original Wav handler at line 985 remains untouched. The error message is updated accordingly. (2) The KernelProcess constructor was silently ignoring the
threadsparameter; the fix assigns it tothis.Threadswhen non-null, which is correct since the property (line 23) has aninitaccessor with a default empty dictionary. (3) TextSearchStore.GetTextSearchResultsAsync had a computedresultsvariable that was never used, with the return statement redundantly re-projecting fromsearchResult; the fix correctly uses the already-computedresultsvariable.
✓ Security Reliability
Three straightforward bug fixes with no security or reliability concerns. (1) Audio format: replaces a duplicate/dead WAV check with new AAC format support — WAV is still handled at line 985. (2) KernelProcess: fixes a data-loss bug where the
threadsconstructor parameter was silently ignored. (3) TextSearchStore: removes a redundant duplicate LINQ projection, using the already-computedresultsvariable instead.
✓ Test Coverage
All three changes are correct bug fixes, but none of them include tests. The AAC audio format MIME type mapping is new behavior with no test coverage. The KernelProcess threads constructor fix resolves a silent data-loss bug (threads parameter was accepted but discarded) with no regression test. The TextSearchStore fix is a safe cleanup of dead code with functionally equivalent behavior. While the code changes themselves are sound, the first two fixes especially warrant corresponding tests to prevent regressions.
✗ Design Approach
The audio and text-search changes look directionally fine, but the
KernelProcessupdate is too narrow for the persistence problem it appears to target. It now honors the optionalthreadsconstructor argument for direct callers, yet the main round-trip paths that serialize and reconstructKernelProcessstill do not carryThreads, so thread-backed processes will continue to lose that state when they flow through Dapr or persisted metadata.
Flagged Issues
-
KernelProcessnow copies the optionalthreadsargument, but the Dapr and state-metadata round-trip paths still drop thread definitions entirely (Experimental/Process.Runtime.Dapr/DaprProcessInfo.cs:21,57andInternalUtilities/process/Abstractions/KernelProcessStateMetadataFactory.cs:16-27). This is a symptom-level fix for one caller, not a complete fix for process thread persistence.
Suggestions
- Add a unit test for the KernelProcess constructor verifying that when threads are passed, they are stored in the Threads property. Currently no test exercises this code path —
LocalProcess.ToKernelProcessAsync()(LocalProcess.cs:611) passes threads via the constructor and would have silently lost them before this fix.
Automated review by octo-patch's agents
| if (threads is not null) | ||
| { | ||
| this.Threads = threads; | ||
| } |
There was a problem hiding this comment.
Incomplete fix / test gap: This only addresses the direct-constructor path. LocalProcess.ToKernelProcessAsync already passes this._process.Threads (LocalProcess.cs:611), but Dapr round-trips still serialize only Steps (DaprProcessInfo.cs:21) and rebuild KernelProcess without threads (DaprProcessInfo.cs:57); ProcessStateMetadataFactory likewise persists only StepsState. If the goal is to preserve threads across snapshots/resume, Threads should be added to the persisted/transport models. At minimum, add a regression test that constructs a KernelProcess with a non-null threads argument and asserts process.Threads matches.
Fixes #13922
Problem
Three static analysis issues identified by PVS-Studio in the .NET codebase:
ClientCore.ChatCompletion.cs—GetAudioOutputMimeTypecontained a duplicateChatOutputAudioFormat.Wavcheck (lines 985 and 1000) making the second branch unreachable. TheAacaudio format supported by the OpenAI SDK was silently unhandled, causing aNotSupportedExceptionat runtime.TextSearchStore.cs—GetTextSearchResultsAsyncassigned a LINQ expression to aresultsvariable (deferred execution) that was never iterated. The return statement duplicated the projection. The unused variable was dead code.KernelProcess.cs— The constructor accepted athreadsparameter but never assigned it to theThreadsproperty, silently discarding all threads passed by callers.Solution
Wavbranch with anAacbranch and update the error message to list'aac'as a supported format.resultsvariable in thereturnstatement instead of duplicating theSelectprojection.threadsparameter tothis.Threadswhen it is not null.Testing
OpenAIChatCompletionServiceandTextSearchStorecontinue to apply.Wavfix (it was already handled earlier in the method);Aacnow maps to"audio/aac"as expected.