mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3590] [CLOSED] [Engine] stabilise the serve test job: lifeline identity by start time, sampler that survives a bad source #4701
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4701
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3590
Author: @justindressler
Created: 10/21/2026
Status: ❌ Closed
Base:
main← Head:fix/flaky-serve-tests📝 Commits (5)
b535d7c[Engine] lifeline: identify a child by start time, not its ps state1876554[Engine] telemetry: keep sampling when one sample fails02db1cftests: pin the watcher identity to the start time, not to the child's state1625e97fix(serve): close the review findings on the lifeline identity change0010a90serve: fold in kingdonb's two flake fixes (from kingdonb/Strata a32edec8)📊 Changes
5 files changed (+107 additions, -15 deletions)
View changed files
📝
serve/lifeline.py(+42 -4)📝
serve/telemetry.py(+18 -2)📝
serve/test_lifeline.py(+39 -0)📝
serve/test_responses.py(+7 -8)📝
strata_control/procs.py(+1 -1)📄 Description
Problem and result
The Minimal serving runtime job fails intermittently on changes that do not touch
serve/at all,which makes every PR's check look broken for reasons that have nothing to do with the PR. Two different
failures were observed on this account's fork, on the same 929-test run:
test_responses.NoLeakedSampler.test_server_close_ends_the_sampler—AssertionError: 1 != 2, twicein a row on one branch and green on the next run of the same commit.
test_lifeline.Lifeline.test_the_portable_watcher_ends_the_child_when_the_server_is_killed—AssertionError: False is not true : the child outlived a killed server (watcher), onmainwith nolocal changes, and on
v0.2.2's own run.Result: both are fixed at the cause, not by loosening the assertion.
The lifeline one was a real bug, and it reproduced here 6 times out of 8.
serve/lifeline.pybuilt thechild's identity with
ps -o lstart=,stat=and kept the whole line, so the token changed whenever theprocess changed state — measured on one live child:
... Ronce,... Seleven times inside 150 ms.The portable watcher compares its own reading against the token taken at start, concluded "that is not my
child any more", and exited without ending it. Identity is now the start time alone: field 22 of
/proc/<pid>/staton Linux (the same rulestrata_control/procs.py::start_tokenalready used), andps -o lstart=elsewhere; a zombie has no identity, so an already-dead child is skipped rather thansignalled. After the change the same test passed 8 out of 8.
The sampler one turned out not to be a race in the test. The count-based assertion was ambiguous
(
1 != 2), so it was rewritten to compare thread identities and say which half failed — and the next CI runon that rewritten test reported
0 != 1 : the server did not start its hardware sampler. The thread wasbeing started and killed immediately:
Telemetry._loophad no exception handling, so the first failingsample()on a machine whose GPU/psutil source is not readable ended the sampler for good.GET /metricsthen silently stops updating.
_loopnow catches a failing sample, prints one line, and keeps sampling oncea second (
"a monitor must outlive its source"), and the test asserts on thread identity so it can onlyfail for the real reason.
Related discussion
changes (test_lifeline fails 5/5 on Linux) — the same root cause, reported independently a day earlier
with the same
ps -o lstart=,stat=diagnosis. That report proposes dropping the state column from thepsoutput; this PR takes the equivalent idea further and removes thepscall: on Linux the identity isfield 22 of
/proc/<pid>/stat, which is whatstrata_control/procs.py::start_tokenalready uses, so nosubprocess and no locale-dependent date parsing. The sampler half has no existing thread.
CONTRIBUTING.md allows straight to a PR.
Approach
Three small changes, no behaviour change beyond the watcher and the sampler doing what they were meant to
do:
serve/lifeline.py:_start_token()and the inlinestart_of()inside_WATCHERuse the process starttime as identity instead of a
psline that includes the volatile state column. Linux reads/proc/<pid>/statdirectly (nosubprocesscall, which also removes apsdependency from the watcheron that path); other POSIX uses
ps -o lstart=only. Zombies return no identity.serve/test_responses.py:NoLeakedSampleruses a set ofthreading.enumerate()idents instead of acount, and asserts on the difference, with a message that names which half failed.
serve/telemetry.py:Telemetry._loopsurvives a failingsample()instead of dying on the first one,and complains once rather than once a second.
Both fixes are additive to the existing behaviour: the
pdeathsigand Windows job-object paths areuntouched, and
release()/end_children()are unchanged.Validation
Revision:
mainat011c9e60(0.2.2). Environment: WSL2 on x86-64, Python 3.12, no GPU (none needed).Passed:
python -m unittest serve.test_lifeline.Lifeline.test_the_portable_watcher_ends_the_child_when_the_server_is_killed— 8/8 runs green after the change; the same command was 6 failures out of 8 before it, so the
repro and the fix are both measured, not argued.
python -m unittest serve.test_lifeline— 6 tests, OK.python -m unittest serve.test_responses.NoLeakedSampler— 6/6 runs green (and green again after thetelemetry change).
sample()always raises: thread still alive after 2.4 s, 3 sample attempts, one complaintline, and it still stops cleanly.
python -m unittest discover -s serve -p 'test_*.py'(the job's own command) — 929 tests, OK (skipped=14) in 307 s, 0 failures — the first fully green run ofthis suite in this campaign; the same command failed one or both of the tests above on every previous
attempt..
Failed:
Not run:
ps -o lstart=fallback): no hardware here. The Linux path isexercised on every run of these tests; the other two are reasoned about, not measured.
compiles.
Limits
ps -o lstart=, which is second-granular. A PID recycled withinthe same second could alias — the same limitation this code had before, and the Linux path (where the
watcher runs in practice) is exact.
is unchanged in behaviour.
Update 2026-10-23 — rebased, and the lifeline half now has a test for its cause
Rebased onto
main7ddc17a3(was011c9e60); clean, 3 commits, 4 files, +87 -9.Added
test_the_watcher_token_does_not_change_with_the_child_state, which samples the identity token twice on one live child (while it spins asR, then while it sleeps asS). The existing behavioural test cannot catch this class of regression on its own: it passes whenever the spawn is sampled after the child settles, which is exactly the shape of the flake.Validation at
02db1cf4, Debian 13 container, Python 3.11.15, no GPU (none needed):python -m unittest discover -s serve -p 'test_*.py'— 975 tests, OK (skipped=14)python -m unittest serve.test_lifeline— 7 tests, OK; the watcher case 5/5 consecutive runspython -m unittest serve.test_responses.NoLeakedSampler— 3/3 consecutive runs7ddc17a3— fails, so it pins the defect rather than restating the fixNot run: Windows job-object path, macOS, and any CUDA/HIP/SYCL build — Python only, no compiled path touched.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.