fix(test-runner): make runs cancellable, deadlock-free, and bounded - #735
Open
beruro wants to merge 3 commits into
Open
fix(test-runner): make runs cancellable, deadlock-free, and bounded#735beruro wants to merge 3 commits into
beruro wants to merge 3 commits into
Conversation
beruro
marked this pull request as ready for review
August 7, 2026 14:23
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.
Problem
Test runs in the WorkStation Testing tab could not actually be stopped, could deadlock while draining child output, and could grow memory without bound. The frontend stop action cleared UI state without signalling the backend, command and runner layers generated different run ids, cancellation was not observed by the child lifecycle, stdout and stderr were drained sequentially, and both streams accumulated into unbounded strings.
The test event wire shape also emitted snake_case variant fields while the frontend expects camelCase, so run_started could arrive without a usable runId.
Solution
The branch now uses one canonical run id from command registration through every event and summary, with a drop guard that always deregisters the run. Cancellation is backed by CancellationToken and terminates the process tree: Unix uses a dedicated process group with TERM, a bounded grace period, then KILL; Windows uses taskkill tree termination plus start_kill.
Stdout and stderr are drained concurrently in chunk-based tasks with a 16 MiB tail bound per stream and explicit truncation state. Cancelled runs emit run_cancelled and resolve with a partial summary marked cancelled. Per-variant camelCase serialization pins the frontend wire contract.
The frontend stop action now resolves the active run, invokes stop_tests, and updates state only after backend confirmation. Pure lifecycle transitions cover stale parallel-run events and no-op stop attempts.
The CI follow-up formats the new lifecycle test, defaults the optional reusable FieldRow isActive prop to false for compatibility with the boolean-only pill-state helper on current develop, and merges current develop into the branch.
Potential risks
Rollback is a normal revert of this PR. It changes no persistence schema and requires no data recovery.
Verification
cargo test -p test_runner(this worktree): 28/28 passed — including new regression tests: stderr-flood no-deadlock, process-group kill (grandchild verified dead viakill(pid, 0)), pre-cancelled token, canonical-id event ordering, wire-format pinning, registry lifecycle/RunGuard.cargo clippy -p test_runner --all-targets(this worktree): finished clean, no warnings.pnpm vitest run src/services/test/__tests__/testRunLifecycle.test.ts(this worktree): 11/11 passed.Effects: none added or modified (React
useEffectsurface untouched;useTestRunneronly re-typesstopTests).