[GH-ISSUE #1997] before_load failure/busy-refusal is ignored ("loading anyway") - two engines co-load, one dies (exit code 1) #797

Closed
opened 2026-11-04 01:45:57 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @NerdyShawn on GitHub (Oct 11, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1997

Summary: Two Strata servers sharing one GPU via reciprocal before_load unload hooks: /unload answers {"status":"busy"} mid-turn instead of preempting, but ensure_loaded ignores the hook's exit code and loads anyway — both engines co-load onto a full card and one dies (exit code 1).

Setup. One RTX 5090 (32 GB), two Strata servers, each a 24 GiB quant (coder :8080, chat :8081). VRAM-exclusive by design: each server's before_load runs POST /unload against the peer before loading.

What happens. A request arrives for the idle lane while the busy lane is mid-turn. The hook fires /unload, which politely answers {"status":"busy"} — refusal, not preemption. ensure_loaded then logs loading anyway (return code of the hook is not honored) and loads the second 24 GiB quant onto a card that still holds the first. The engine dies with exit code 1 and the server restarts it "a minute or two" later. In a 15-minute replay of realistic concurrent traffic, 17/65 consumer requests got HTTP 503 and the coder engine crash-looped 4x.

Log signature (verbatim, engine log):

[strata] before loading: curl -s -m 5 -X POST -H "Content-Type: application/json" http://<peer>/unload
{"status": "busy"}[strata] loading the model again (it was unloaded) ...
[strata] the engine had stopped (exit code 1); starting it again (a minute or two) ...

Workaround we shipped. The hook polls /unload until the peer reports truly unloaded/not loaded. Two structural limits remain:

  1. before_load runs under a hardcoded ~120 s subprocess timeout, so the poll budget is ~100 s — a 190 s peer turn outlives any sane wait, and when the poll gives up the load attempt fails as a graceful min_free_vram 503 (better than the crash, but still a consumer-visible cliff that scales with turn length).
  2. The advisory-busy + ignored-exit-code combination means the default hook shape everyone will write (single curl /unload) produces silent co-load crashes. The dangerous failure is the one that looks successful.

Asks.

  1. Honor before_load failure: if the hook exits nonzero (or the refusal is still in effect when ensure_loaded proceeds), refuse the request with 503 + Retry-After instead of loading anyway. A temporary refusal beats a wedged engine; today the inverse is true.
  2. A blocking unload variant (POST /unload with ?wait=true, or an accepted/busy progress contract) so orchestration can wait on the server's terms instead of racing a hardcoded subprocess timeout.
  3. Papercut: POST /unload with an empty body and no Content-Type header returns 415 — a success-shaped endpoint that silently fails the most common one-liner call; an empty-body POST arguably deserves none, or the docs should call out the header.

Happy to contribute the contention-soak replay harness as a regression test. Related context: #1519 reports the same exit code 1 symptom in a single-server setup (unverified overlap, but our data shows any VRAM squeeze at load time ends in the same crash); #1853/#1034 show the orchestration patterns users are converging on. Measured swap numbers if useful: first cold swap 29.8–30.6 s, preempt-mid-28k-prefill 50.7 s, warm swap-back 13.4 s.

Originally created by @NerdyShawn on GitHub (Oct 11, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1997 **Summary:** Two Strata servers sharing one GPU via reciprocal `before_load` unload hooks: `/unload` answers `{"status":"busy"}` mid-turn instead of preempting, but `ensure_loaded` ignores the hook's exit code and loads anyway — both engines co-load onto a full card and one dies (exit code 1). **Setup.** One RTX 5090 (32 GB), two Strata servers, each a 24 GiB quant (coder `:8080`, chat `:8081`). VRAM-exclusive by design: each server's `before_load` runs `POST /unload` against the peer before loading. **What happens.** A request arrives for the idle lane while the busy lane is mid-turn. The hook fires `/unload`, which politely answers `{"status":"busy"}` — refusal, not preemption. `ensure_loaded` then logs `loading anyway` (return code of the hook is not honored) and loads the second 24 GiB quant onto a card that still holds the first. The engine dies with exit code 1 and the server restarts it "a minute or two" later. In a 15-minute replay of realistic concurrent traffic, **17/65 consumer requests got HTTP 503** and the coder engine crash-looped 4x. Log signature (verbatim, engine log): ``` [strata] before loading: curl -s -m 5 -X POST -H "Content-Type: application/json" http://<peer>/unload {"status": "busy"}[strata] loading the model again (it was unloaded) ... [strata] the engine had stopped (exit code 1); starting it again (a minute or two) ... ``` **Workaround we shipped.** The hook polls `/unload` until the peer reports truly `unloaded`/`not loaded`. Two structural limits remain: 1. `before_load` runs under a hardcoded ~120 s subprocess timeout, so the poll budget is ~100 s — a 190 s peer turn outlives any sane wait, and when the poll gives up the load attempt fails as a *graceful* `min_free_vram` 503 (better than the crash, but still a consumer-visible cliff that scales with turn length). 2. The advisory-`busy` + ignored-exit-code combination means the **default hook shape everyone will write** (single `curl /unload`) produces silent co-load crashes. The dangerous failure is the one that looks successful. **Asks.** 1. Honor `before_load` failure: if the hook exits nonzero (or the refusal is still in effect when `ensure_loaded` proceeds), **refuse the request with 503 + `Retry-After` instead of loading anyway.** A temporary refusal beats a wedged engine; today the inverse is true. 2. A blocking unload variant (`POST /unload` with `?wait=true`, or an `accepted/busy` progress contract) so orchestration can wait on the server's terms instead of racing a hardcoded subprocess timeout. 3. Papercut: `POST /unload` with an empty body and no `Content-Type` header returns **415** — a success-shaped endpoint that silently fails the most common one-liner call; an empty-body POST arguably deserves none, or the docs should call out the header. Happy to contribute the contention-soak replay harness as a regression test. Related context: #1519 reports the same `exit code 1` symptom in a single-server setup (unverified overlap, but our data shows *any* VRAM squeeze at load time ends in the same crash); #1853/#1034 show the orchestration patterns users are converging on. Measured swap numbers if useful: first cold swap 29.8–30.6 s, preempt-mid-28k-prefill 50.7 s, warm swap-back 13.4 s.
Author
Owner

@Niko1221 commented on GitHub (Oct 12, 2026):

Thank you, this is a clear report and the log signature made it easy to find. You are right: ensure_loaded ignored the hook's result and loaded anyway.

The fix (0.1.43.1, out now): when a before_load command exits non-zero or times out, the server now checks the card's free VRAM (the existing min_free_vram_mib check). If there is not enough room for the model it does not load: 503 with Retry-After, with the reason in the log and the message. If there is room it loads, with a warning naming the exit code (so a peer that is simply not running, where curl exits 7, does not block loading). Set "min_free_vram_mib" to your model's size for this. "before_load_strict": true always refuses on a failure, "before_load_ignore_failure": true always loads. The 120 s limit is now "before_load_timeout_s" in the config (default unchanged). For your ask 2: POST /unload?wait=1 (or ?wait=, also on /v1/unload) waits for the running turn and then unloads, so the peer can free the card on the server's terms; without wait the answer stays 409/busy as before. Tests cover failure with free and full VRAM, strict, ignore, the timeout and both wait cases.

Ask 3 (415 on an empty body without Content-Type): that is on purpose, it is the guard that stops a web page elsewhere from unloading the model with a plain form POST, so we kept it; the docs now say the header is needed (curl -X POST -H "Content-Type: application/json" ... /unload).

Meanwhile: have the hook poll /unload until the peer says unloaded/not loaded and exit non-zero otherwise, as you did; with the new version a failing hook is then a clean 503 instead of a crash. An offer to share the contention replay as a regression test is welcome.

<!-- gh-comment-id:6129315140 --> @Niko1221 commented on GitHub (Oct 12, 2026): Thank you, this is a clear report and the log signature made it easy to find. You are right: ensure_loaded ignored the hook's result and loaded anyway. The fix (0.1.43.1, out now): when a before_load command exits non-zero or times out, the server now checks the card's free VRAM (the existing min_free_vram_mib check). If there is not enough room for the model it does not load: 503 with Retry-After, with the reason in the log and the message. If there is room it loads, with a warning naming the exit code (so a peer that is simply not running, where curl exits 7, does not block loading). Set "min_free_vram_mib" to your model's size for this. "before_load_strict": true always refuses on a failure, "before_load_ignore_failure": true always loads. The 120 s limit is now "before_load_timeout_s" in the config (default unchanged). For your ask 2: POST /unload?wait=1 (or ?wait=<seconds>, also on /v1/unload) waits for the running turn and then unloads, so the peer can free the card on the server's terms; without wait the answer stays 409/busy as before. Tests cover failure with free and full VRAM, strict, ignore, the timeout and both wait cases. Ask 3 (415 on an empty body without Content-Type): that is on purpose, it is the guard that stops a web page elsewhere from unloading the model with a plain form POST, so we kept it; the docs now say the header is needed (curl -X POST -H "Content-Type: application/json" ... /unload). Meanwhile: have the hook poll /unload until the peer says unloaded/not loaded and exit non-zero otherwise, as you did; with the new version a failing hook is then a clean 503 instead of a crash. An offer to share the contention replay as a regression test is welcome.
Author
Owner

@NerdyShawn commented on GitHub (Oct 12, 2026):

Confirmed fixed in v0.1.43.1, and covered by a GPU-free regression replay.

Upgraded to v0.1.43.1 (engine rebuilt from source, CUDA arch 120). With before_load_strict: true the two-server setup now behaves as the issue describes:

  • a busy peer answers POST /unload with 409 {"status":"busy"};
  • the failing hook is a refusal, not a co-load — the request gets a clean 503 + Retry-After, the engine is never started, and the coder is untouched (no more 4x crash-loop);
  • POST /unload?wait=1 waits for the running turn and then unloads, so the waiting lane no longer races the hook's timeout.

I reproduced the 0.1.42 behaviour to confirm what changed: with strict off, the hook fails ("loading anyway"), the free-VRAM check passes because both lanes trust the peer's /unload to give the card back, and the second server loads onto the full card and dies — exactly the crash walk.

Regression test — serve/test_server.py, BeforeLoadContention (GPU-free, no hardware needed): two mock servers share one simulated 32 GiB card through the same reciprocal before_load hooks as the report, with a guard on each engine's restart() that records any "started onto a card the peer did not give back". Three cases: the reported core (coder mid-turn → 503 + Retry-After, engine never started); the 15-minute replay reduced (5 concurrent requests while the coder is busy all 503, next one loads after the coder frees the card); and /unload?wait=1 waiting for the running turn before unloading so the waiting lane loads.

Run: .venv/bin/python -m unittest serve.test_server.BeforeLoadContention -v — full serve.test_server is 311 tests, all green. I validated it by running the identical bytes against the 0.1.42 tree: all 3 fail with the old signatures; on 0.1.43.1 they pass consistently. Happy to open a PR with just the test class if wanted.

<!-- gh-comment-id:6132505619 --> @NerdyShawn commented on GitHub (Oct 12, 2026): **Confirmed fixed in v0.1.43.1, and covered by a GPU-free regression replay.** Upgraded to v0.1.43.1 (engine rebuilt from source, CUDA arch 120). With `before_load_strict: true` the two-server setup now behaves as the issue describes: - a busy peer answers `POST /unload` with `409 {"status":"busy"}`; - the failing hook is a refusal, not a co-load — the request gets a clean `503` + `Retry-After`, the engine is never started, and the coder is untouched (no more 4x crash-loop); - `POST /unload?wait=1` waits for the running turn and then unloads, so the waiting lane no longer races the hook's timeout. I reproduced the 0.1.42 behaviour to confirm what changed: with strict off, the hook fails ("loading anyway"), the free-VRAM check passes because both lanes trust the peer's `/unload` to give the card back, and the second server loads onto the full card and dies — exactly the crash walk. **Regression test** — `serve/test_server.py`, `BeforeLoadContention` (GPU-free, no hardware needed): two mock servers share one simulated 32 GiB card through the same reciprocal `before_load` hooks as the report, with a guard on each engine's `restart()` that records any "started onto a card the peer did not give back". Three cases: the reported core (coder mid-turn → `503` + `Retry-After`, engine never started); the 15-minute replay reduced (5 concurrent requests while the coder is busy all `503`, next one loads after the coder frees the card); and `/unload?wait=1` waiting for the running turn before unloading so the waiting lane loads. Run: `.venv/bin/python -m unittest serve.test_server.BeforeLoadContention -v` — full `serve.test_server` is 311 tests, all green. I validated it by running the identical bytes against the 0.1.42 tree: all 3 fail with the old signatures; on 0.1.43.1 they pass consistently. Happy to open a PR with just the test class if wanted.
Author
Owner

@NerdyShawn commented on GitHub (Oct 31, 2026):

Fixed for us by 0.2.9 — commenting to close the loop.

Context: dual-lane RTX 5090 host, two Strata servers swapping one card via reciprocal before_load hooks (unload the peer, then load). Per this issue, before the fix the sequence "peer answers /unload with {status: busy}, ensure_loaded ignores the hook's failure, loads anyway" crash-looped the engine under contention (17/65 503s, 4 crashes in our 2026-10-11 soak).

On v0.2.9 we can see the native handling in serve/server.py: before_load_timeout_s (with a 503 + Retry-After: 15 refusal path), before_load_ignore_failure, before_load_strict, and the matching test coverage (test_failing_before_load_with_full_vram_refuses_with_503_and_retry_after, strict-mode and timeout tests) — all tagged #1997. Combined with our polling hook (waits until the peer genuinely unloads so the browser consumer never sees the 503), the co-load failure mode is gone; our re-run of the 2026-10-11 soak scenarios passes and our three regression tests for it pass 3/3 against v0.2.9.

We'll keep the inline-polling hook for swap transparency (a 503 to open-webui users, even a polite one, is worse UX than a 30 s slow first request), but the refuse-and-retry-after semantics is the right upstream default. Thanks — feel free to consider this resolved from our side.

<!-- gh-comment-id:6549355223 --> @NerdyShawn commented on GitHub (Oct 31, 2026): Fixed for us by 0.2.9 — commenting to close the loop. Context: dual-lane RTX 5090 host, two Strata servers swapping one card via reciprocal `before_load` hooks (unload the peer, then load). Per this issue, before the fix the sequence "peer answers /unload with {status: busy}, ensure_loaded ignores the hook's failure, loads anyway" crash-looped the engine under contention (17/65 503s, 4 crashes in our 2026-10-11 soak). On v0.2.9 we can see the native handling in `serve/server.py`: `before_load_timeout_s` (with a 503 + `Retry-After: 15` refusal path), `before_load_ignore_failure`, `before_load_strict`, and the matching test coverage (`test_failing_before_load_with_full_vram_refuses_with_503_and_retry_after`, strict-mode and timeout tests) — all tagged #1997. Combined with our polling hook (waits until the peer genuinely unloads so the *browser* consumer never sees the 503), the co-load failure mode is gone; our re-run of the 2026-10-11 soak scenarios passes and our three regression tests for it pass 3/3 against v0.2.9. We'll keep the inline-polling hook for swap transparency (a 503 to open-webui users, even a polite one, is worse UX than a 30 s slow first request), but the refuse-and-retry-after semantics is the right upstream default. Thanks — feel free to consider this resolved from our side.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#797
No description provided.