fix(tui): synchronize reset-progress ReactiveProperties to stop flaky host crash#1525
Merged
Aaronontheweb merged 1 commit intoJun 30, 2026
Conversation
… host crash netclaw-dev#1494/netclaw-dev#1514 moved the install reset onto a background Task.Run thread that publishes progress by writing four ReactiveProperty instances (StatusMessage, CurrentProgressStep, ProgressMessage, CanQuitProgress). In production those writes marshal onto the single Termina render-loop thread, but an unbound view model (unit tests) runs them inline on the background thread while the test thread subscribes/disposes the same property. R3's ReactiveProperty is not thread-safe: its value-set walks the observer linked list lock-free while Subscribe/Dispose mutate that list under a lock, so the two race and can corrupt the list into a cycle -> infinite loop -> the reset Task never completes and the xunit host is killed by the watchdog (flaky 'Test host process crashed', no stack trace, Ubuntu-only; the same commit was seen both green and red). R3's documented remedy for shared state written from multiple threads is SynchronizedReactiveProperty, which serializes set/subscribe/dispose on one monitor (uncontended in production). The declared type stays ReactiveProperty<T> so the page and all readers are unchanged. Fixes flaky InitExistingInstallViewModelTests.ResetFailure_ShowsErrorAndDoesNotNavigate.
This was referenced Jun 30, 2026
Merged
Aaronontheweb
added a commit
that referenced
this pull request
Jul 3, 2026
…p 3 (#1573) RunResetAsync publishes CurrentProgressStep = 3 ("Purge complete") and then evaluates the Task.Delay(CompletionPause, _timeProvider, ct) that registers the completion-pause timer. Because RunResetAsync runs off the loop, step 3 is the signal observers gate on to know deletion finished — but it fired BEFORE the timer it vouches for existed. On a virtualized clock (FakeTimeProvider in tests, and any consumer advancing the injected TimeProvider) this is a lost wakeup: an Advance that lands between "step 3 published" and "timer registered" is dropped, the delay never fires, and the reset hangs forever awaiting a wakeup that will never come. Fix: create the completion-pause timer before publishing step 3, then await the captured task. This makes "step 3 observed" a happens-before guarantee that the pause timer already exists, so a single clock advance always fires it deterministically. On the real clock this shifts timer registration a few microseconds earlier; the visible "Purge complete" dwell is unchanged. Evidence: hang-dump forensics of CI run 28676578217 (PR #1568, Netclaw.Cli.Tests blame-hang after 300s). Test FullReset_AfterBothConfirmations_DeletesEverything was parked at `await vm.ResetTask!.WaitAsync(ct)`; its CompleteResetAsync helper had exhausted its advance loop (counter i == 10, all virtual-clock advances spent) and FakeTimeProvider was left holding exactly one orphaned waiter — the delay registered after the final Advance. Prior commits 850cf8c (#1525) and eb01b49 (#1536) band-aided the symptom with advance/yield retry loops; this removes the race at the source. The test helper CompleteResetAsync is shared by all three sibling tests (FullReset_AfterBothConfirmations_DeletesEverything, SetupOnlyReset_DeletesConfigButKeepsMemoryAndSessions, DaemonStopFailureResult_ShowsStatusAndContinuesReset); it now waits for step 3 then does exactly one advance, deleting the retry loop that only ever masked the lost wakeup on loaded runners.
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.
Summary
Fixes the flaky
InitExistingInstallViewModelTests.ResetFailure_ShowsErrorAndDoesNotNavigatetest-host crash introduced by #1514 ("#1494 stop daemon before reset").Root cause
#1494 moved the install reset onto a background
Task.Runthread that publishes progress by writing fourReactivePropertyinstances —StatusMessage,CurrentProgressStep,ProgressMessage,CanQuitProgress.PublishOnLoopmarshals every write onto the single loop thread — single-threaded, safe.ReactiveViewModel's defaultInvokeAsyncruns the write inline on the background thread, while the test thread concurrentlySubscribes/disposes the same property in theWaitFor*helpers.R3's
ReactiveProperty<T>is not thread-safe: its value-set path walks the observer linked list lock-free, whileSubscribe/Disposemutate that list underlock(this). The two race and can corrupt the list into a cycle → the value-set walk never terminates → the resetTasknever completes → the xunit host is killed by the watchdog. That matches every symptom: flaky, Ubuntu-only on a given run, no managed stack trace, and the same commit observed both green and red. (ThrowUnobservedTaskExceptionsis off, confirming it's the hang-cycle, not an unobserved fault.)Diagnosed against the
dotnet-skills:r3-reactive-extensionsconcurrency contract: "OnNextmust not be called concurrently/re-entrantly from multiple threads … or useSynchronizedReactiveProperty."Fix
Make the four properties written from the background thread
SynchronizedReactiveProperty<T>(R3's built-in lock-based variant — serializes set/subscribe/dispose on one monitor; uncontended in production). The declared type staysReactiveProperty<T>, soInitExistingInstallPageand every reader is unchanged.CurrentPhase/SelectedIndexare input-thread-only and left as plainReactiveProperty.Verification
InitExistingInstalltests pass, including the formerly-flakyResetFailurecase across repeated runs.