[PR #4833] [Engine] /v1/responses sends Retry-After on a GPU-busy 503, as chat and messages do #5203

Open
opened 2026-11-07 16:33:26 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4833
Author: @gdevenyi
Created: 10/31/2026
Status: 🔄 Open

Base: main ← Head: api/responses-retry-after


📝 Commits (1)

  • 0113844 /v1/responses: send Retry-After on a GpuBusy 503, as chat and messages do

📊 Changes

2 files changed (+22 additions, -1 deletions)

View changed files

📝 serve/server.py (+3 -1)
📝 serve/test_server.py (+19 -0)

📄 Description

Problem and result

When the server refuses to load an unloaded model because the GPU is busy, chat and messages answer 503 with Retry-After: 15. /v1/responses answers the same 503 with no header, on stream and non-stream requests. A client then retries too soon and gives up.

After this change /v1/responses sends the header too. In the two scenarios measured on the mock engine, the OpenAI Python SDK at its default 2 retries now recovers on /v1/responses, as it does on chat. In one run on the real engine it recovers on /v1/responses too.

Strata's docs promise the header with no route limit. docs/DETAILS.md: "with min_free_vram_mib set and not enough free, the request gets 503 with Retry-After".

OpenAI's spec allows the header but does not require it. In openai/openai-openapi (2e9ebb3), the 503 of POST /responses is InferenceServiceUnavailable. Its Retry-After is an integer, minimum 1, and "may be omitted". So the case rests on Strata's docs and the SDK behaviour below.

  • #1997 added the header for this refusal. Its commit has no change that names /v1/responses.
  • #451 added the /v1/responses route, before the header existed.
  • #2497 and #3336 (both open) are nearby but do not change this header on this route.
  • A search of issues and pull requests found no duplicate. The search was not exhaustive.

No scope agreement is needed: this is a bug fix, not a feature, refactor or change of default.

Approach

The /v1/responses handler now reads retry_after from the error and passes it to the 503, the same way as the shared handler that chat and messages go through. Only GpuBusy carries that value, so EngineStarting, EngineStuck and EngineDied stay as they were. The error body does not change. The docs already state this behaviour, so they do not change.

Validation

Revision: base c62d5e3a plus 0113844d. Linux, Python 3.12.3, OpenAI Python SDK 3.42.0. Mock engine, except for the real-engine section at the end of Passed.

Passed:

Regression test, stream and non-stream:
python -m unittest serve.test_server.SharingTheGpu.test_gpu_refusal_on_responses_sends_retry_after_too
With the fix it passes. With serve/server.py from the base, both cases fail with AssertionError: None != '15'.

Test suite:
python -m unittest serve.test_server serve.test_responses serve.test_anthropic_base_url serve.test_chat_tool_results serve.test_context_overflow serve.test_images
Ran 438 tests: FAILED (failures=1, skipped=1). The one failure is listed under Failed.

Differential on the wire, base against branch, with a local script that is not in this PR. It sends 63 requests: chat, messages and responses, stream and non-stream; GpuBusy with retry_after 15, 2.5, 0 and none; EngineStarting, EngineStuck and EngineDied; normal 200s; a real min_free_vram_mib refusal; a foreign Origin; a missing and a correct API key; and GpuBusy raised during the run. It compares status, Retry-After, Content-Type, the CORS allow-origin header and the first 220 bytes of the body, with ids and timestamps normalized.

  • Base against a second base run: no differences.
  • Base against branch: 7 lines differ. All are /v1/responses with a nonzero retry_after, and each gains the header (15, or 2 for 2.5). Nothing else changes, including chat and messages.
  • The real refusal, with load not mocked and the free VRAM faked: chat, messages and /v1/responses all answer 503 with Retry-After: 15, stream and non-stream.

Real OpenAI Python SDK against the mock engine, with a local script that is not in this PR. Each cell is one run. The time is from the start of the scenario.

Scenario Route Base Branch
before_load_strict, a real hook that fails until 10 s chat OK at 15.1 s OK at 15.1 s
same responses InternalServerError at 1.3 s OK at 15.1 s
min_free_vram_mib, the shipped 15 s wait, faked VRAM frees at 55 s chat OK at 60.1 s OK at 60.1 s
same responses InternalServerError at 46.4 s OK at 60.1 s

Real engine: RTX 5080 16 GB, engine 0.1.55 from release v0.2.9, Qwen3.8 IQ3_S, context 65536. One session each for base c62d5e3a and branch 0113844d, one run per cell. min_free_vram_mib is 15800 and a separate program holds 300 MiB of VRAM, so the card has 15363 MiB free. Nothing is patched or faked. Each refusal takes 15.2 s, the shipped wait.

Check Base Branch
/v1/responses, non-stream 503, no Retry-After 503, Retry-After: 15
/v1/responses, stream 503, no Retry-After 503, Retry-After: 15
/v1/chat/completions, non-stream and stream 503, Retry-After: 15 503, Retry-After: 15
/v1/messages, non-stream and stream 503, Retry-After: 15 503, Retry-After: 15
OpenAI SDK, default 2 retries, responses.create non-stream, the other program leaves at 50 s InternalServerError at 46.9 s OK at 77.3 s, status completed
Normal /v1/responses after the other program left 200, completed, 17.94 s (this request did the load) 200, completed, 0.17 s (the SDK's request had done the load)

The 503 bodies are the same on base and branch. The 77.3 s is later than the 60.1 s on the mock engine because it includes a real model load.

Failed:

serve.test_server.GpuChoice.test_hip_ordinal (AssertionError: '0,1' != '1,0'). This change does not cause it: the test fails the same way on the base c62d5e3a.

Not run:

On the real engine, because they need a patch or were not part of this run:

  • GpuBusy raised during the run, EngineStarting, EngineStuck, EngineDied, and retry_after values other than 15. These were run on the mock engine only.

  • The before_load_strict scenario.

  • The SDK on chat, the Anthropic SDK, the SDK with stream=True, and a program that never leaves, so the SDK runs out of retries with the header.

  • Repeats. The SDK result on the real engine is one run on each side.

  • Windows and macOS.

  • CUDA, HIP, SYCL and Metal builds. The change is Python only.

  • Codex. The only client measured is the OpenAI Python SDK.

Limits

  • The refusal needs opt-in config (min_free_vram_mib, or before_load with before_load_strict or min_free_vram_mib) and an unloaded model. The default path does not change.
  • This PR does not change a GpuBusy raised during the run, on any route. With svc.run patched to raise it (base and branch give the same result):
    • Non-stream /v1/responses already answers 503 with the header, with a chat-shaped body.
    • On a stream of chat, messages or responses, the server writes a second raw HTTP 503 head and JSON body into the open event stream.
    • From reading the code only: besides the batch-slot refusal (retry_after=5), svc.run also calls ensure_loaded, so this error can carry 15 too. I did not trigger that through a real load.
  • The 503 body keeps its current server_error type and code. The spec's example for this response uses service_unavailable_error and server_is_overloaded. This PR does not change the body.
  • Retrying only helps if the GPU frees in time. The header makes the client wait as long as the server asks, and nothing more.

🤖 Generated with Claude Code

https://claude.ai/code/session_01W53iURzvDQMjnYemag8uvv


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4833 **Author:** [@gdevenyi](https://github.com/gdevenyi) **Created:** 10/31/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `api/responses-retry-after` --- ### 📝 Commits (1) - [`0113844`](https://github.com/Niko1221/Strata/commit/0113844d95e0b6f62fd65cd021f3463d7f321ba8) /v1/responses: send Retry-After on a GpuBusy 503, as chat and messages do ### 📊 Changes **2 files changed** (+22 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+3 -1) 📝 `serve/test_server.py` (+19 -0) </details> ### 📄 Description ## Problem and result When the server refuses to load an unloaded model because the GPU is busy, chat and messages answer 503 with `Retry-After: 15`. `/v1/responses` answers the same 503 with no header, on stream and non-stream requests. A client then retries too soon and gives up. After this change `/v1/responses` sends the header too. In the two scenarios measured on the mock engine, the OpenAI Python SDK at its default 2 retries now recovers on `/v1/responses`, as it does on chat. In one run on the real engine it recovers on `/v1/responses` too. Strata's docs promise the header with no route limit. `docs/DETAILS.md`: "with `min_free_vram_mib` set and not enough free, the request gets **503** with `Retry-After`". OpenAI's spec allows the header but does not require it. In `openai/openai-openapi` (2e9ebb3), the 503 of `POST /responses` is `InferenceServiceUnavailable`. Its `Retry-After` is an integer, minimum 1, and "may be omitted". So the case rests on Strata's docs and the SDK behaviour below. ## Related discussion - #1997 added the header for this refusal. Its commit has no change that names `/v1/responses`. - #451 added the `/v1/responses` route, before the header existed. - #2497 and #3336 (both open) are nearby but do not change this header on this route. - A search of issues and pull requests found no duplicate. The search was not exhaustive. No scope agreement is needed: this is a bug fix, not a feature, refactor or change of default. ## Approach The `/v1/responses` handler now reads `retry_after` from the error and passes it to the 503, the same way as the shared handler that chat and messages go through. Only `GpuBusy` carries that value, so `EngineStarting`, `EngineStuck` and `EngineDied` stay as they were. The error body does not change. The docs already state this behaviour, so they do not change. ## Validation Revision: base c62d5e3a plus 0113844d. Linux, Python 3.12.3, OpenAI Python SDK 3.42.0. Mock engine, except for the real-engine section at the end of Passed. **Passed:** Regression test, stream and non-stream: `python -m unittest serve.test_server.SharingTheGpu.test_gpu_refusal_on_responses_sends_retry_after_too` With the fix it passes. With `serve/server.py` from the base, both cases fail with `AssertionError: None != '15'`. Test suite: `python -m unittest serve.test_server serve.test_responses serve.test_anthropic_base_url serve.test_chat_tool_results serve.test_context_overflow serve.test_images` Ran 438 tests: `FAILED (failures=1, skipped=1)`. The one failure is listed under Failed. Differential on the wire, base against branch, with a local script that is not in this PR. It sends 63 requests: chat, messages and responses, stream and non-stream; `GpuBusy` with `retry_after` 15, 2.5, 0 and none; `EngineStarting`, `EngineStuck` and `EngineDied`; normal 200s; a real `min_free_vram_mib` refusal; a foreign Origin; a missing and a correct API key; and `GpuBusy` raised during the run. It compares status, `Retry-After`, `Content-Type`, the CORS allow-origin header and the first 220 bytes of the body, with ids and timestamps normalized. - Base against a second base run: no differences. - Base against branch: 7 lines differ. All are `/v1/responses` with a nonzero `retry_after`, and each gains the header (15, or 2 for 2.5). Nothing else changes, including chat and messages. - The real refusal, with `load` not mocked and the free VRAM faked: chat, messages and `/v1/responses` all answer 503 with `Retry-After: 15`, stream and non-stream. Real OpenAI Python SDK against the mock engine, with a local script that is not in this PR. Each cell is one run. The time is from the start of the scenario. | Scenario | Route | Base | Branch | | --- | --- | --- | --- | | `before_load_strict`, a real hook that fails until 10 s | chat | OK at 15.1 s | OK at 15.1 s | | same | responses | `InternalServerError` at 1.3 s | OK at 15.1 s | | `min_free_vram_mib`, the shipped 15 s wait, faked VRAM frees at 55 s | chat | OK at 60.1 s | OK at 60.1 s | | same | responses | `InternalServerError` at 46.4 s | OK at 60.1 s | Real engine: RTX 5080 16 GB, engine 0.1.55 from release v0.2.9, Qwen3.8 IQ3_S, context 65536. One session each for base c62d5e3a and branch 0113844d, one run per cell. `min_free_vram_mib` is 15800 and a separate program holds 300 MiB of VRAM, so the card has 15363 MiB free. Nothing is patched or faked. Each refusal takes 15.2 s, the shipped wait. | Check | Base | Branch | | --- | --- | --- | | `/v1/responses`, non-stream | 503, no `Retry-After` | 503, `Retry-After: 15` | | `/v1/responses`, stream | 503, no `Retry-After` | 503, `Retry-After: 15` | | `/v1/chat/completions`, non-stream and stream | 503, `Retry-After: 15` | 503, `Retry-After: 15` | | `/v1/messages`, non-stream and stream | 503, `Retry-After: 15` | 503, `Retry-After: 15` | | OpenAI SDK, default 2 retries, `responses.create` non-stream, the other program leaves at 50 s | `InternalServerError` at 46.9 s | OK at 77.3 s, status `completed` | | Normal `/v1/responses` after the other program left | 200, `completed`, 17.94 s (this request did the load) | 200, `completed`, 0.17 s (the SDK's request had done the load) | The 503 bodies are the same on base and branch. The 77.3 s is later than the 60.1 s on the mock engine because it includes a real model load. **Failed:** `serve.test_server.GpuChoice.test_hip_ordinal` (`AssertionError: '0,1' != '1,0'`). This change does not cause it: the test fails the same way on the base c62d5e3a. **Not run:** On the real engine, because they need a patch or were not part of this run: - `GpuBusy` raised during the run, `EngineStarting`, `EngineStuck`, `EngineDied`, and `retry_after` values other than 15. These were run on the mock engine only. - The `before_load_strict` scenario. - The SDK on chat, the Anthropic SDK, the SDK with `stream=True`, and a program that never leaves, so the SDK runs out of retries with the header. - Repeats. The SDK result on the real engine is one run on each side. - Windows and macOS. - CUDA, HIP, SYCL and Metal builds. The change is Python only. - Codex. The only client measured is the OpenAI Python SDK. ## Limits - The refusal needs opt-in config (`min_free_vram_mib`, or `before_load` with `before_load_strict` or `min_free_vram_mib`) and an unloaded model. The default path does not change. - This PR does not change a `GpuBusy` raised during the run, on any route. With `svc.run` patched to raise it (base and branch give the same result): - Non-stream `/v1/responses` already answers 503 with the header, with a chat-shaped body. - On a stream of chat, messages or responses, the server writes a second raw HTTP 503 head and JSON body into the open event stream. - From reading the code only: besides the batch-slot refusal (`retry_after=5`), `svc.run` also calls `ensure_loaded`, so this error can carry 15 too. I did not trigger that through a real load. - The 503 body keeps its current `server_error` type and code. The spec's example for this response uses `service_unavailable_error` and `server_is_overloaded`. This PR does not change the body. - Retrying only helps if the GPU frees in time. The header makes the client wait as long as the server asks, and nothing more. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01W53iURzvDQMjnYemag8uvv --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#5203
No description provided.