Add HTTP_POST_TIMEOUT to TimeoutMiddleware config (#5941)#6150
Add HTTP_POST_TIMEOUT to TimeoutMiddleware config (#5941)#6150
Conversation
POST was omitted from methods_timeout when TimeoutMiddleware was first added (ac328e5). This meant POST endpoints had no env var override for the 120s default, causing 504s on /v1/sync-local-files for large payloads. Adding the env var entry enables operators to tune it. Closes #5941 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR adds a single missing entry —
Confidence Score: 5/5Safe to merge — minimal one-line change, no behavior change until The change is a trivial one-liner that fills an obvious omission in the existing pattern. The downstream No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Incoming HTTP Request] --> B{Has x-request-start-time header?}
B -- Yes --> C{Request age > max_age + clock_skew?}
C -- Yes --> D[Return 408 clock_skew]
C -- No --> E[Lookup timeout for method]
B -- No --> E
E --> F{method in methods_timeout?}
F -- Yes --> G[Use per-method timeout\ne.g. HTTP_POST_TIMEOUT]
F -- No --> H[Use default_timeout\nHTTP_DEFAULT_TIMEOUT = 120s]
G --> I[asyncio.wait_for call_next]
H --> I
I -- success --> J[Return response]
I -- TimeoutError --> K[Return 504 Gateway Timeout]
Reviews (1): Last reviewed commit: "Add HTTP_POST_TIMEOUT to TimeoutMiddlewa..." | Re-trigger Greptile |
- test_post_timeout_override: POST returns 504 when exceeding POST-specific timeout - test_post_timeout_none_falls_back_to_default: POST falls back to HTTP_DEFAULT_TIMEOUT when unset - test_main_methods_timeout_includes_post: methods_timeout dict accepts POST key Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace test_main_methods_timeout_includes_post with an AST-based check that directly verifies backend/main.py contains POST in the methods_timeout dict, avoiding false-positive from constructing a separate dict manually. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- test_post_timeout_none_falls_back_to_default now passes {"POST": None}
to match what main.py actually builds when env var is unset
- test_main_methods_timeout_includes_post now verifies the value is wired
to HTTP_POST_TIMEOUT env var, not just that the POST key exists
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Test Evidence (#5941)Unit Tests — 16/16 pass3 new tests added:
L1 — Standalone backendL2 — Backend + client integratedChanged-path coverage
WebSocket impact: None
by AI for @beastoin |
|
lgtm |
Summary
Adds
HTTP_POST_TIMEOUTto themethods_timeoutdict inbackend/main.py, enabling per-method timeout control for POST requests.Fixes #5941 —
sync-local-files504 timeouts on large payloads. POST was the only HTTP method missing from the timeout config (omitted since the originalac328e5bcommit in Jan 2025).Changes
backend/main.py: Add"POST": os.environ.get('HTTP_POST_TIMEOUT')tomethods_timeoutbackend/tests/unit/test_timeout_middleware.py: 3 new tests covering POST timeout override, None fallback with{"POST": None}, and AST verification of both key and env var nameDeployment
After merge, set on backend-sync Cloud Run:
This matches
backend(main) which already hasHTTP_DEFAULT_TIMEOUT=600— POST there already gets 600s via fallback. The fix is specifically forbackend-sync(and any other service) where the default is 120s.Current env var state (from mon's audit):
WebSocket impact: None
HTTP_POST_TIMEOUT does NOT affect WebSocket connections (
/v4/listen):BaseHTTPMiddlewareonly handles HTTP requests — WebSocket connections go through a different ASGI pathNO_SOCKET_TIMEOUTin helm values is for a separate layerRisks
HTTP_POST_TIMEOUTapplies to ALL POST routes, not just/v1/sync-local-files. Consistent with GET/PUT/PATCH/DELETE.Noneis filtered by_parse_methods_timeout→ POST falls back toHTTP_DEFAULT_TIMEOUT.Tests
16/16 pass (
pytest backend/tests/unit/test_timeout_middleware.py):test_post_timeout_override: POST with explicit timeout → 504 on slow handlertest_post_timeout_none_falls_back_to_default:{"POST": None}→ skipped → default timeouttest_main_methods_timeout_includes_post: AST-parses main.py, asserts POST key + HTTP_POST_TIMEOUT env varLive Test Evidence
L1 (standalone backend)
L2 (backend + client integrated)
Changed-path coverage
main.py:121POST in methods_timeouttest_timeout_middleware.pytestsby AI for @beastoin