Skip to content

studio: use safe process checks for stale snapshots and downloads - #17694

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
DimitriChrysafis:fix/studio-stale-process-owners
Nov 18, 2026
Merged

danielhanchen merged 3 commits into
unslothai:mainfrom
DimitriChrysafis:fix/studio-stale-process-owners

Conversation

@DimitriChrysafis

Copy link
Copy Markdown
Contributor

Snapshot cleanup and the download-worker reaper treat exited, unreaped children as running. A real zombie still passes os.kill(pid, 0), so its snapshots remain on disk and the reaper cannot confirm that it stopped. The snapshot check is also unsafe on Windows, where signal 0 is not a harmless existence probe. The registry's separate Windows check only opens a process handle, without checking whether the process exited.

Use the existing pid_is_running helper in both places. It checks for zombies and uses the established Windows wait-based probe. Keep the private wrappers so existing callers and tests can still override them. Snapshot owners labelled PID 1 stay protected without issuing a probe.

Adds eight tests, including real live children, real unreaped children, and a filesystem check that removes dead owners' snapshots while preserving live and current owners' weights. Six fail without the fix.

Local macOS verification: 155 passed, 13 skipped across the new tests, process lifetime, orphan cleanup, and text-encoder release suites. Pinned lint, formatting, and git diff --check pass. Native Windows was not available locally.

Two existing installer process-group tests fail on unchanged main on macOS as well. They create isolated process groups, while the installer intentionally uses them only on Linux. Those two are excluded here; the installer is not changed.

python -m pytest \
  studio/backend/tests/test_stale_artifact_process_owners.py \
  studio/backend/tests/test_orphaned_children.py \
  studio/backend/tests/test_process_lifetime.py \
  studio/backend/tests/test_diffusion_te_release.py -q \
  -k 'not test_the_installer_waits_for_its_validation_group_not_the_leader and not test_a_validation_group_that_will_not_die_is_not_announced_as_stopped'

danielhanchen added a commit that referenced this pull request Nov 14, 2026
## Summary

The Backend CI `(Python 3.13, a-f)` shard is now running into its
`timeout --signal=INT --kill-after=60 1500` backstop. On #17694 (a
Studio download-registry change) the parallel step was killed with exit
124 after `30296 passed ... in 1509.42s`, before it finished. Its other
recent runs took 1000 to 1340 s, so any slower runner tips it over.

This is the same situation as a-k on 2026-10-23 and g-r on 2026-11-09,
and it gets the same fix: split the shard, leave the timeout alone (it
is a hang backstop, not a budget).

## How the split point was chosen

Same method as #17187: the `-q` progress lines carry timestamps, and
xdist hands out tests roughly in collection order, so I mapped the
progress percentage onto the per-file collection order of a-f. Across
five a-f logs (four complete, one killed):

| boundary | share of a-f time |
| --- | --- |
| through `test_c*` | 0.26 to 0.29 |
| `test_diffusion*` starts | 0.32 to 0.38 |
| `test_diffusion*` ends | 0.93 to 0.94 |

`test_d*` alone is about 65% of the shard and nearly all of it is
`test_diffusion*` (about 60%). No first letter split comes close to
even, so `test_diffusion*` gets its own shard: roughly 40% stays in a-f
and 60% moves.

## Changes

- `.github/workflows/studio-backend-ci.yml`:
  - `a-f` also ignores `tests/test_diffusion*.py`.
- New `diffusion` shard, rooted at `tests/` like the others (so the
shared `--ignore=` list still applies). It excludes everything but
`test_diffusion*` one letter at a time, so `test_diffusers*` (and any
other `test_d*` file) stays in `a-f`.
  - `rest` is unchanged and still the remainder.
- The serial and decision-training steps stay pinned to `a-f`. The
`(Python 3.13, a-f)` check keeps its name.
- `tests/test_ci_backend_pytest_shards.py`: new-file examples for the
boundary (`test_dog`, `test_diffusers_new`, `test_diffuse` land in
`a-f`; `test_diffusion_new`, `test_diffusion` land in `diffusion`).

## Testing

- `pytest tests/test_ci_backend_pytest_shards.py`: 59 passed.
- Sabotage: without the `test_diffusion*` ignore on `a-f`, 3 tests fail
(files run twice). Without the `test_diffus[!i]*` step, the same 3 fail
(`test_diffusers*` would run in both shards).
- `pytest --collect-only` with the CI selection and shared ignores: old
a-f collects 38267 tests, new a-f 16230 and diffusion 22037. The two are
disjoint and their union is identical to the old a-f node IDs.
@danielhanchen danielhanchen self-assigned this Nov 18, 2026
danielhanchen added a commit that referenced this pull request Nov 18, 2026
## Name the encoding on the sd.cpp nvidia-smi probe


`studio/backend/tests/test_text_io_encoding.py::test_text_io_names_its_encoding[sd_cpp_backend.py]`
fails on `main` since #18210. On staging it shows up as `(Python 3.13,
rest)` failing on unrelated PRs, for example #17694 and #18275:

```
E       sd_cpp_backend.py:3146: subprocess(text = True) without encoding
E   assert not ['sd_cpp_backend.py:3146: subprocess(text = True) without encoding']
```

### Cause

#18210 added `_sole_nvidia_card_mib()`, which reads nvidia-smi's output
with `subprocess.run(..., text = True)` but no `encoding`. That falls
back to `locale.getencoding()`, the ANSI codepage on Windows, which is
exactly what this lint exists to catch.

The other three `subprocess.run(text = True)` calls in
`sd_cpp_backend.py` already pass `encoding = "utf-8", errors =
"replace"`. The new probe just missed it.

### Fix

The probe now passes `encoding = "utf-8", errors = "replace"` like its
neighbours. nvidia-smi's CSV output is ASCII, so what the probe parses
does not change. A stray byte can no longer raise inside the probe.

### Verification

- `tests/test_text_io_encoding.py`: fails on `main` on this line and
passes with this change.
- `tests/test_sd_cpp_backend.py` also passes: 1289 passed across both
files.
- ruff is clean.
@danielhanchen
danielhanchen marked this pull request as ready for review November 18, 2026 10:45
@danielhanchen
danielhanchen self-requested a review as a code owner November 18, 2026 10:45
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T10:49:13.409944Z 79cf8a5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 79cf8a52b8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@danielhanchen
danielhanchen merged commit 35184f9 into unslothai:main Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants