[PR #4757] [Engine] answer an unexpected handler error with a 500, not a dropped connection #5165

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4757
Author: @Tsury
Created: 10/30/2026
Status: 🔄 Open

Base: main ← Head: fix-internal-error-500


📝 Commits (1)

  • 8a159a6 [Engine] answer an unexpected handler error with a 500, not a dropped connection

📊 Changes

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

View changed files

📝 serve/server.py (+12 -1)
➕ serve/test_internal_error_500.py (+71 -0)

📄 Description

Problem and result

When a handler raises something unexpected before the answer starts, such as a FileNotFoundError from a cached image file removed under the server, the connection closes with no response. The client can only report ECONNRESET, and the server's reason is not returned to it.

After this change, the client gets a 500 with the exception's name, in the Responses error form on /v1/responses. The traceback goes to the server log and the monitor record. ConnectionError and TimeoutError still count as a client that left. BadBody keeps its handling. An answer that has already started is not replaced.

None found in issues or pull requests.

Approach

except OSError narrows to (ConnectionError, TimeoutError), so a file error no longer reads as a disconnect. A final except Exception writes the 500 only when answer_started is false.

Validation

Passed:

  • New tests against unchanged main (870aedd9): 2 errors. With the change: all pass.
  • python -m unittest serve.test_internal_error_500 serve.test_server serve.test_structured: 372 tests pass (Linux, Python 3.14).

Not run:

  • python -m unittest discover -s serve and any GPU or model run. This change was split from a maintained v0.2.8 build that runs on an RTX 5090 Laptop; the unit tests above are the evidence for this branch.

Limits

The 500 message carries the exception's name and text. They can include a server-side path.

🤖 Generated with Claude Code


🔄 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/4757 **Author:** [@Tsury](https://github.com/Tsury) **Created:** 10/30/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix-internal-error-500` --- ### 📝 Commits (1) - [`8a159a6`](https://github.com/Niko1221/Strata/commit/8a159a6971b2ddb9631aa3ddbeae0a5efe2f44a0) [Engine] answer an unexpected handler error with a 500, not a dropped connection ### 📊 Changes **2 files changed** (+83 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+12 -1) ➕ `serve/test_internal_error_500.py` (+71 -0) </details> ### 📄 Description ## Problem and result When a handler raises something unexpected before the answer starts, such as a `FileNotFoundError` from a cached image file removed under the server, the connection closes with no response. The client can only report ECONNRESET, and the server's reason is not returned to it. After this change, the client gets a 500 with the exception's name, in the Responses error form on `/v1/responses`. The traceback goes to the server log and the monitor record. `ConnectionError` and `TimeoutError` still count as a client that left. `BadBody` keeps its handling. An answer that has already started is not replaced. ## Related discussion None found in issues or pull requests. ## Approach `except OSError` narrows to `(ConnectionError, TimeoutError)`, so a file error no longer reads as a disconnect. A final `except Exception` writes the 500 only when `answer_started` is false. ## Validation **Passed:** - New tests against unchanged `main` (870aedd9): 2 errors. With the change: all pass. - `python -m unittest serve.test_internal_error_500 serve.test_server serve.test_structured`: 372 tests pass (Linux, Python 3.14). **Not run:** - `python -m unittest discover -s serve` and any GPU or model run. This change was split from a maintained v0.2.8 build that runs on an RTX 5090 Laptop; the unit tests above are the evidence for this branch. ## Limits The 500 message carries the exception's name and text. They can include a server-side path. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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#5165
No description provided.