test(daemon): de-flake sidecar stop test on the pid-liveness check#2349
Merged
Conversation
test_connection_stopped_after_running_raises_again used a fake manager that reports a hardcoded pid (4321) but owns no real OS process, so its shutdown() can't make that pid disappear. registry.stop() then verifies the pid is gone via psutil.pid_exists against the real process table — which spuriously raises StopFailedError whenever pid 4321 happens to be a live process on the runner (observed on macOS CI). Patch pid_exists to False for the fake so the liveness check reflects the double's intent (the fake sidecar is terminated) rather than the host's process table. Production behavior is unchanged — a real manager tree-kills its real pid, so the check stays meaningful there.
Contributor
|
Verdict: Approve ✅ This de-flakes 🔍 Technical detailsVerified
No concern, noting for the record
Strengths
|
itomek
approved these changes
Jul 21, 2026
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.
Why this matters
test_connection_stopped_after_running_raises_againfails intermittently on CI (seen on the macOS smoke runner:StopFailedError: agent 'toy' sidecar pid 4321 survived the tree-kill). It's a false failure that blocks unrelated PRs and erodes trust in the suite — the production code is fine.Root cause: the test's fake manager reports a hardcoded pid (
4321) but owns no real OS process, so itsshutdown()can't make that pid disappear.registry.stop()then verifies the pid is gone viapsutil.pid_exists(pid)against the real process table. On most runners pid 4321 is dead → passes; when it collides with a live process on the runner → spuriousStopFailedError. Test-double fidelity bug, not a product bug: a real manager tree-kills its own real pid, so the liveness check stays meaningful in production.Fix: patch
pid_existstoFalsefor the fake so the check reflects the double's intent (the fake sidecar is terminated) instead of the host's process table. One line + a comment; production behavior untouched.Test plan
pytest tests/unit/test_daemon_relay.py— 36 passpid_exists → True(simulating pid 4321 alive on the runner) reproduces theStopFailedError; the fix'spid_exists → Falsepatch neutralizes it whilestop()still succeedsblack/isortclean