Repository navigation
Fail the mac tab-capability smoke on a backend that never comes back, not on a stall - #9711
Merged
Merged
Conversation
…ero misses The survival poller failed the step on a single non-200, where "non-200" also covered status 0, which _get_json returns for any exception including a probe that ran out of its 10s budget. So one timed-out probe out of eighteen reported "the backend did not stay up through the warm window" about a backend that was up the whole time, and whose end-of-run liveness check passed in the same run. That is stricter than the thing the file exists to protect. The invariant is the desktop launcher's health watchdog, and its numbers are in studio/src-tauri/src/commands.rs: HEALTH_WATCHDOG_INTERVAL 15s, HEALTH_WATCHDOG_MAX_FAILURES 3. It kills on three CONSECUTIVE misses, watchdog_failure_budget widens that to twelve when a probe times out against a backend that is generating, and watchdog_should_confirm_before_death spends a further 30s last-chance probe on a stall. A lone timeout is a backend the launcher keeps, so a run that goes red on one is reporting a verdict the product does not act on. Run 32862298967 is the case. The stall behind it was real: the server completed no request at all for 10.03s and then 33.2s, both windows ending on an /api/inference/status that had been in flight throughout, and a third instance in the same job froze for 27.75s the same way. But 33s is two strikes, not three, and the step that saw the 27.75s freeze passed, because it has no such poller. The commit it went red on changed one frontend unit test, which this workflow does not run. The verdict now counts the longest run of consecutive misses and resets it on every answer, which is what the watchdog counts. _get_json returns a kind rather than a bare status, separating the outcomes the watchdog separates: an answered non-200 and a refused connection still fail on the first occurrence, and only a stall gets the budget. Only ECONNREFUSED earns "refused", since the kernel answers that one itself with no server involved; a reset or a truncated read is a listener that accepted and then failed to finish, which is a stall wearing a different errno. A stall under the budget prints a ::warning:: with the worst latency, so it stays visible instead of disappearing into a pass. The stall itself is a backend defect and is not addressed here. It is not the warm thread this file's docstring blames, which had finished 3.2s earlier, and it is not the MLX self-heal either: the only instance in that job which ran the self-heal was the one instance that never stalled. Tests: the poller verdict was previously unreachable from the pytest walk. Nine cases now cover it, including a backend that dies mid-run, and one reads HEALTH_WATCHDOG_MAX_FAILURES out of commands.rs so the budget here cannot drift from the launcher's. Verified against the failing run's own survival_samples.json and against real sockets for each classification. Reverting the verdict to zero-tolerance, counting totals instead of consecutive misses, or dropping the refused case each turn the new tests red.
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
… budget with it Two gaps in the port of the launcher's rule, both real. The strikes were counted in this poller's own sample stream, which runs at POLL_INTERVAL_S, 5s in CI, while the watchdog probes at HEALTH_WATCHDOG_INTERVAL, 15s. That is a different question, and it was wrong in both directions. Too strict, because three misses at 5s is a 15s silence where the launcher tolerates 45s before reaching the same three strikes. Too lax, and this is the sharper one, because a backend that answers between the watchdog's probes and stalls across every one of them shows nothing but isolated misses in the dense stream: each 5s answer resets the run, so the count never reaches three while the launcher sees three in a row and kills. watchdog_replay now re-derives a 15s timeline from the dense samples rather than polling slower, so the extra resolution is kept instead of discarded. A reconstructed probe at T counts as answered if any real probe came back 200 between T and T + HEALTH_PROBE_TIMEOUT, which is the budget the watchdog's own probe at T had. A tick no probe overlapped is skipped rather than guessed: judging it either way would be inventing evidence. The verdict is taken over both routes together, because check_health_inner tries /api/liveness and falls back to /api/health, so one answer from either is one answered probe. The rest of the rule came with it. inference_active is now recorded off the liveness reply and latched the way watchdog_inference_active_after latches it, where only an answer moves the value and a probe that brought nothing back leaves the previous one standing. While that latch is set the budget is HEALTH_WATCHDOG_MAX_FAILURES_BUSY rather than HEALTH_WATCHDOG_MAX_FAILURES, and a spent budget buys the same last-chance probe at HEALTH_CONFIRM_PROBE_TIMEOUT that keeps the backend only if it answers and says it is still generating. Without this, three timeouts during an active generation failed this smoke while the launcher kept the backend, which is the false-positive class this file was changed to remove. The death cases are untouched and still fail on first sight: an answered non-200 is the backend calling itself unhealthy, and a refused port is death. Only a stall gets a budget. Replaying the failing run's own survival_samples.json gives 7 ticks judged, 2 missed, longest run 2 against a 3-strike budget, so its 33s stall is two watchdog strikes and not three, which is what it was always claimed to be. Tests: the synthetic fixtures are replaced by a timeline simulator that takes stall windows and produces the samples a sequential poller would have recorded, including the drift a timed-out probe puts into the cadence. Fifteen cases cover the verdict, among them a backend that stalls only across the ticks, which the old dense count passed and which fails now, and a pair that runs the same stall with and without the marker so the widened budget has to come from the marker. The constants test now pins all five against commands.rs. Six mutations were checked: judging on the 5s grid, reading the verdict off the dense stream, dropping the busy budget, letting a miss clear the latch, never reading the marker, and accepting any answer to the last-chance probe. The first pair of busy budget tests passed under two of those, because the stall was short enough for the confirmation probe to rescue it, so the fixture was lengthened past the confirmation window until the budget is the only thing keeping the backend alive.
The previous round reimplemented the launcher's health watchdog in Python: a 15s grid, three consecutive misses, the widened budget while inference_active is latched, the 30s last-chance probe. Review then returned six more findings, all correct and all citing commands.rs: the startup grace and torch_warm_in_progress, is_timeout versus a connection reset, the ordering of the confirmation window, a timed-out probe's own duration inside the cadence, the liveness-404-then-health fallback order, and carrying strikes across a tick nothing observed. That is not a review backlog, it is the shape of the approach. Mirroring a state machine makes every line of the original a correctness requirement for a smoke test, and there is no version of that which converges. Two facts say the mirror was never going to pay off here. The window cannot hold the rule. This phase runs with STUDIO_MAC_SURVIVAL_S=120, set in studio-mac-ui-smoke.yml. The busy path alone is HEALTH_WATCHDOG_MAX_FAILURES_BUSY strikes at HEALTH_WATCHDOG_INTERVAL plus a 30s confirmation, about 210s, and BACKEND_STARTUP_GRACE_PERIOD is 300s before a backend that has not yet answered healthy counts a failure at all. A three-strike conclusion drawn inside 120s describes a rule that never had room to run. And the watchdog is not running in this phase. It boots `unsloth studio` directly with no Tauri shell, which the workflow says at the step itself, and the watchdog's own behaviour is covered by the Rust tests next to it. The rule was being re-implemented to judge a process that is not subject to it. So the verdict is now the coarsest one that cannot false-positive. A backend that stops answering and never answers again did not survive, decided with one probe taken after sampling stops, which is what separates a stall still in progress at the end of the run from a process that is gone. An answered non-200 and a refused port still fail on sight; only a stall gets any latitude. Anything that answers again survived on any reading of any budget, so it emits a warning with the stall duration and passes. The reasoning is in the code beside the check, including the condition on putting a threshold back: it would have to be strictly longer than the launcher's most generous path, and nothing that long fits in this window. Replaying the failing run's own survival_samples.json gives one stall window of 25.1s that is not terminal, so it passes and warns. The same samples with the recovery removed fail. watchdog_replay, the busy-budget mirroring and the four watchdog constants are gone; PROBE_TIMEOUT_S stays, still pinned to HEALTH_PROBE_TIMEOUT, because a probe here should call a miss at the same point the product does. inference_active is still recorded into the artifact, since it is the first thing anyone asks of a stall, but no verdict reads it. The tests that only exercised the replay are deleted and the file is 291 lines smaller. Nine mutations were checked against the ten remaining cases, each caught by its own test: never failing a terminal stall, treating any open span as terminal, dropping the refused branch, dropping the non-200 branch, failing on any stall at all, closing a span only on a liveness answer, calling a reset a dead port, drifting the probe budget, and quietly reintroducing the replay.
…decide The terminal-stall rule turned on a single probe taken once the UI drive finished, which handed the verdict to the arbitrary moment sampling happens to end. A transient stall straddling that boundary times out the last sample and that one probe, and the run reports the backend never answered again, while the same stall thirty seconds earlier only warns and passes. That is this file's own flake relocated to the edge of the window rather than removed, and it lands on exactly the stalls the change exists to tolerate. await_recovery keeps probing after sampling stops until the backend answers or the window expires. RECOVERY_WINDOW_S is 90s, sized from what this job has actually produced rather than from a round number: run 32862298967 gave four stalls on one runner, at 10.03s, 25.1s, 27.75s and 33.2s, so a window that decides "this one never ended" has to clear 33.2s with room to spare, and 90s is a little under three times it. The number and its source are in the comment, and a test asserts the window stays above twice the longest stall on record. This extends observation; it is not a retry, and the comment says so where the constant is defined. A retry re-asks a question that already has an answer and takes the better one, which is how a flaky test buries a real failure. This question has no answer yet: a timed-out probe reports only that nothing came back inside its budget. A dead backend answers none of these probes either, so the window costs those seconds only on a run that was already failing and cannot turn a death into a pass. Only a stall waits. An answered non-200 and a refused port are decided the moment they come back, so they return at once and still fail on first occurrence, rather than costing the run 90 seconds to reach the answer they already had. Tests: six cases cover the watch, including that it gives up and reports the timeout honestly, and that neither a refused port nor a non-200 spends the window. report() is driven with an injected verdict everywhere else, so nothing there would notice main() dropping the watch; an AST check pins the wiring. Thirteen mutations were re-run, not only the new ones, since a longer observation period is the kind of tolerance that can quietly absorb a fault another test was written to catch. All thirteen are still caught, each by its own test. Two of them now fail fewer tests than before, because the dead-backend case moved onto the refused branch, but both keep a dedicated test of their own. One new test was rewritten during this: it used a 300s window, so the mutation that removes the early return hung the suite instead of failing it. It now uses a short window and asserts the probe count, which fails in seconds.
… saw Three consequences of adding the post-run watch, all in it rather than around it. The watch could hang the job. It runs after the UI drive, so cancelling the wall watchdog before it left the longest-running part of the script with nothing enforcing WALL_TIMEOUT_S, and the 90s window could push past that deadline unnoticed. Worse, urllib's timeout is per socket operation rather than per request, so a peer that dribbles bytes resets it on every chunk and resp.read() never returns at all; the only bound left was the job's own cap. A hung job is the worst outcome available here, because it reports nothing and burns the runner. The body is now read through _read_within, which carries one deadline for the whole read and uses read1 so the deadline is checked as each chunk arrives rather than after the buffer fills, plus a size cap because a health reply is a few hundred bytes and reading a huge one to the end is the same failure wearing a different shape. The watchdog is cancelled only after the watch and the report have both finished. The watch could hammer a struggling backend. _transport_kind calls a reset a stall on purpose, and a reset returns in about a millisecond, so an unpaced loop turned the window into thousands of connections against a backend already in trouble, which can prolong the fault it is waiting to clear. Probes are now spaced by RECOVERY_PROBE_SPACING_S, clamped to whatever is left of the window so pacing can never extend it. This costs nothing on a real stall, where the probe spends its whole budget and no pause is added. The warning could lie. When sampling stopped mid-stall and the watch then got a 200, the span still ended at the last sampled timeout, so the reported duration left out every second of the watch that actually saw it clear, and the text said the backend answered before the run ended when it answered afterwards. The duration now includes the post-run wait for a span that was still open, and the wording says which of the two happened. The point of warning rather than failing is that a human reads the number, so a number that is wrong is worse than none. Death handling is untouched: an answered non-200 and a refused port are decided the moment they come back and still fail on first occurrence, and neither spends the window. Tests: twenty mutations were run, the seven new ones and all thirteen from before, since a bounded deadline is exactly the kind of change that can stop an older test discriminating. All twenty are caught, each by its own test, and none by a hang. Two of the new tests had to be fixed after the mutation run, both the failure this PR keeps producing. The trickle test detected its mutation by hanging rather than failing, so it now drives the probe from a daemon thread and joins with a timeout, and a missing deadline fails it in five seconds. The post-run duration test used a stall that was already longer than the threshold it asserted, so it passed with the fix reverted; it now uses a short trailing stall and asserts the reported duration exceeds the raw span by the wait, which cannot pass without it.
_read_within bounded the body, but urlopen has not returned while response headers are still arriving, so nothing inside it is running yet and only urllib's per-socket-operation timeout applies. A peer that accepts and then dribbles header bytes resets that timeout forever and holds the call open, so await_recovery could run past its advertised 90s until the wall watchdog hard-exits. Losing the recovery report is the part that matters: that is the same "reports nothing" outcome the watch exists to prevent. Bounding headers as well would only move the hole again, to the redirect chain or the handshake. The deadline now sits outside all of them: _probe_once keeps the request exactly as it was, and _get_json runs it on a daemon thread and joins for at most the budget. An expired join is a timeout and the thread is abandoned. It is a daemon, so it cannot hold up exit, and _probe_once keeps its body deadline and size cap so an abandoned one still lets go of its socket rather than buffering. Those inner bounds are hygiene for the abandoned case now, not the budget; the join is what enforces that, and the docstring says the deadline is whole-request so the next reader does not swap it back for a per-layer one. Verified against a raw socket that accepts and then dribbles an unterminated header byte by byte, with the probe driven from its own thread so a build without the deadline fails the assertion rather than hanging the suite. Two problems surfaced in the mutation run and both are fixed here. The first version of that fixture sent whole header lines, which trips http.client's own _MAXHEADERS cap of 100 and ends the call at about two seconds. The test passed with the entire fix reverted, because it was measuring a limit in the standard library rather than anything in this file. It now sends a single unterminated line one byte at a time, which has no such cap, and asserts up front that fewer than 100 bytes went out so a fixture that drifts back to whole lines fails loudly instead of passing for free. Removing the body deadline no longer fails the dribbling-body test, because the join now bounds that case too. It is still caught, by the oversized-body test, and that test now asserts its payload actually exceeds the cap rather than assuming it. The other socket fixtures gained the same treatment: each asserts what it did before asserting what the code did. Twenty-three mutations were run, the three new ones and all twenty from before. All are caught, each by at least one test, and none by a hang.
danielhanchen
force-pushed
the
mac-tabs-survival-threshold
branch
from
August 25, 2026 20:59
513d6dd to
0aed996
Compare
The recovery watch could observe a stall and report it nowhere. If the last sampling probe answers and the backend stalls immediately afterwards, await_recovery sees several timeouts, gets an answer and returns ok, so the run passes; but spans were measured over the poller's samples alone, so that stall belonged to no span and the warning branch never fired. A 10 to 90 second stall disappeared in silence. That is the one outcome this window was added to avoid. The argument for warning rather than failing on a recovered stall is that somebody reads the warning, and a recovered stall nobody is told about gets neither treatment. await_recovery now returns its probe history alongside the verdict, recorded in the same shape and on the same clock as the poller's samples, and report() lays the two end to end before computing spans. A stall that starts after sampling gets a span of its own; one that straddles the boundary is measured across it rather than truncated at it. That also removes the previous approximation, which added final_wait_s to any span left open at the end: the watch's own probes now cover that time, so the length is measured rather than estimated, and the two can no longer double-count. The wording follows the same timeline. A stall entirely inside sampling still reads "before the run ended"; one that straddles the end says sampling ended during it and it cleared during the watch; one that begins afterwards says so and names the watch as the only thing that saw it. Tests: the post-run-wait case is rebuilt on real recovery probes rather than a scalar, and a new case covers the gap itself, sampling ending healthy and the stall arriving afterwards, which asserts a warning is emitted at all, that its length is not understated, and that it says the stall began after sampling ended. An AST check pins main() handing the history to report(), since every other test here drives report() directly and would not notice it being dropped. Twenty-three mutations re-run, not only the four new ones. All are caught, each by at least one test, none by a hang. One of the four new ones is worth naming: with the recovery probes dropped from the timeline, the new case goes red and so does the straddle case, which is what says the two are measured on one clock rather than stitched together. One harness note against myself: an anchor in this round's sweep matched nothing, so that mutation silently never applied and reported a clean run. Re-run with the substitution checked, it is caught. The sweep now fails loudly on a missed anchor rather than reporting a pass.
Three fixes to the recovery watch, all in the same area. The per-probe budget is now clamped to what is left of the window. A probe started near the end with the full PROBE_TIMEOUT_S could outlive the window by most of that budget on its own, and the loop could also arrive with the window already spent, after a clamped pacing sleep, and still begin a full-budget request. That overrun is what the wall watchdog exists to terminate, and it would have killed the run before the report it is waiting for. The loop now computes the remaining window first, breaks rather than starting a probe with no time left, and hands each probe min(PROBE_TIMEOUT_S, remaining). survival_samples.json now serialises the combined timeline. It was written before the recovery probes were merged in, so the artifact held only the sampling-phase rows while the verdict was computed from both. A stall that began during the watch drove the failure and then did not appear in the file anyone would open to check it. The terminal message no longer counts the watch twice. The span it reports runs through the recovery probes now that they share a timeline, so its length already includes the watch; naming the watch again as extra time on top of it gave a total that could not be reconciled with the artifact. It reads as the total silence, of which the last N seconds was the post-run watch.
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.
What went wrong
tests/studio/playwright_mac_tab_capabilities.pypolls/api/livenessand/api/healthacross the warm window and failed the step on any single non-200. "non-200" also covered status0, which_get_jsonreturned for any exception, including a probe that simply ran out of its 10s budget.So one timed-out probe out of eighteen produced:
about a backend that was up the whole time, and whose end-of-run liveness check passed in the same run. A probe that times out while the process is alive is the exact symptom this file was written about, so failing on one states the opposite of what it is trying to prove.
The run that exposed it
Run
32862298967. The stall behind it was real: the server completed no request at all for 10.03s and then 33.2s, both windows ending on an/api/inference/statusthat had been in flight throughout. A third Studio instance in the same job froze the same way for 27.75s, in a step that passed, because that step has no such poller. The commit it went red on changed one frontend unit test, which this workflow does not run.What this settled on, and why not more
An earlier revision of this PR replayed the launcher's health watchdog: a 15s grid, three consecutive misses, the widened budget while
inference_activeis latched, the 30s last-chance probe. That was the wrong shape, and review found six further gaps in it, all real and all citingcommands.rs. Mirroring a state machine makes every line of the original a correctness requirement for a smoke test, which does not converge.Two facts say the mirror could never pay off here:
STUDIO_MAC_SURVIVAL_S: '120'. The busy path alone isHEALTH_WATCHDOG_MAX_FAILURES_BUSYstrikes atHEALTH_WATCHDOG_INTERVALplus a 30s confirmation, about 210s, andBACKEND_STARTUP_GRACE_PERIODis 300s before a backend that has not yet answered healthy counts a failure at all. A three-strike conclusion drawn inside 120s describes a rule that never had room to run.unsloth studiodirectly with no Tauri shell, which the workflow says at the step itself, and the watchdog's own behaviour is covered by the Rust tests beside it.The rule
ECONNREFUSED, on first occurrence. OnlyECONNREFUSEDcounts as a dead port; a reset or a truncated read is a listener that accepted and then failed to finish, which is a stall.::warning::with the stall duration and pass. Anything that answers again survived on any reading of any budget.No retry was added. The reasoning sits in the code next to the check, including the condition on putting a threshold back: it would have to be strictly longer than the launcher's most generous path, and nothing that long fits in this window.
Verification
Replaying the failing run's own
survival_samples.jsongives one stall window of 25.1s that is not terminal, so it passes and warns. The same samples with the recovery removed fail.Ten cases cover the verdict. Nine mutations were checked, each caught by its own test: never failing a terminal stall, treating any open span as terminal, dropping the refused branch, dropping the non-200 branch, failing on any stall at all, closing a span only on a liveness answer, calling a reset a dead port, drifting the probe budget from
HEALTH_PROBE_TIMEOUT, and quietly reintroducing the replay._get_json's classification is checked against real sockets: a 200, a 503, a server that accepts and never answers, a closed port, and a listener that accepts then hard-resets.Full
tests/studio/walk: 6578 passed, 40 skipped.The stall itself
Not addressed here, and it is a real backend defect worth its own issue. Two candidate explanations are ruled out by the run's logs: it is not the warm thread this file's docstring blames, which finished 3.2s before the first freeze, and it is not the MLX self-heal, since the only instance in that job which ran the self-heal was the one instance that never stalled.