fix(search): unwedge RunSearchAsync + propagate worker exceptions#35
Closed
OptimusPi wants to merge 1 commit into
Closed
fix(search): unwedge RunSearchAsync + propagate worker exceptions#35OptimusPi wants to merge 1 commit into
OptimusPi wants to merge 1 commit into
Conversation
Two HIGH-severity items from ISSUES.md, fixed together with regression tests. 1. Single-thread RunSearchAsync used to run the worker body synchronously on the caller. The returned Task only completed *after* the search drained on the same thread, so `await search.RunSearchAsync()` on a sync context deadlocked. StartSearchThreads now off-threads every worker (single-thread path uses a dedicated background thread instead of inlining), so the Task yields before the SIMD loop runs. 2. Multi-thread workers used to call RunWorkerBody with no try/catch. A worker throwing died silently, `_completionSource` never moved, and the caller hung forever. A WorkerCoordinator now wraps every worker: first exception is captured, the last worker out fires TrySetException, and OperationCanceled under a requested cancel is treated as a clean exit. RunSearchUntilCompletion gets the same treatment so its sync surface rethrows instead of pretending the search finished clean. Tests in Motely.Tests/MotelySearchReliabilityTests.cs cover both surfaces and all of (1) single-thread no-deadlock, (2) single-thread exception propagation, (3) multi-thread async exception propagation, (4) multi-thread sync exception propagation. All 424 Motely.Tests pass. https://claude.ai/code/session_01MGxcd6zZLNvNMWVFRAQ6oU
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.
Two HIGH-severity items from
ISSUES.mdfixed together, both regressions covered.1.
RunSearchAsyncno longer deadlocks on the single-thread pathMotelySearch.cs:1205-1217— when_threadCount == 1the worker body ran synchronously insideStart(). The returnedTaskonly completed after the search had already drained on the caller's thread, soawait search.RunSearchAsync()on a sync context deadlocked.StartSearchThreadsnow off-threads every worker (single-thread path uses a dedicated backgroundThreadinstead of inlining), so the Task yields before the SIMD loop runs.2. Worker exceptions are no longer swallowed
MotelySearch.cs:1224-1234— multi-thread workers calledRunWorkerBodywith no try/catch. A worker throwing died silently,_completionSourcenever moved, and the caller hung forever. AWorkerCoordinatorwraps every worker:Interlocked.CompareExchange._completionSource.TrySetException.OperationCanceledExceptionunder a requested cancel is treated as a clean exit.The sync surface
RunSearchUntilCompletiongot the same treatment so it rethrows instead of pretending the search finished cleanly.Tests
New
Motely.Tests/MotelySearchReliabilityTests.cs:RunSearchAsync_SingleThread_DoesNotDeadlockAwaitOnSameContextRunSearchAsync_SingleThread_SurfacesWorkerExceptionRunSearchAsync_MultiThread_SurfacesWorkerExceptionRunSearchUntilCompletion_MultiThread_SurfacesWorkerExceptionAll 424 tests pass (
dotnet test Motely.Tests/Motely.Tests.csproj).Test plan
dotnet build Motely.slnx -c Release— cleandotnet test Motely.Tests— 424/424 greenwasm-toolsworkload)https://claude.ai/code/session_01MGxcd6zZLNvNMWVFRAQ6oU
Generated by Claude Code