refactor(api): tighten relay retry policy and config safety bounds
This commit is contained in:
@@ -1148,3 +1148,44 @@ Validation:
|
||||
Follow-ups:
|
||||
|
||||
- Optional next hardening increment: introduce endpoint-specific retry overrides for write paths (if future non-GET use is introduced) to keep retry policy conservative by operation type.
|
||||
|
||||
---
|
||||
|
||||
### CL-031: TASK22236 P2-S3 Batch 2A policy tightening (retry classification, config clamping, log de-dup)
|
||||
|
||||
date: 2026-03-24
|
||||
author: Cline
|
||||
scope: `pages/api/middleware/relayForwarding.js`, `tests/phase21/relay-forwarding-hardening.test.cjs`
|
||||
type: change
|
||||
rationale: Execute P2-S3 Batch 2A by tightening relay retry policy and operational safety bounds while preventing duplicate error noise between relay-layer and endpoint-layer logging.
|
||||
impact: Stronger resilience and cleaner observability with no endpoint contract changes; retry behavior is now explicitly conservative for deterministic client/auth failures.
|
||||
status: completed
|
||||
|
||||
Summary:
|
||||
|
||||
- Updated relay retry policy:
|
||||
- explicitly non-retryable statuses: `400`, `401`, `403`, `404`, `422`
|
||||
- retries still allowed for transient classes (`408`, `429`, `5xx`) and selected transport error codes
|
||||
- any other explicit numeric HTTP status now treated as non-retryable by default
|
||||
- Added runtime-safe config clamping for relay knobs:
|
||||
- timeout clamped to `100..30000ms`
|
||||
- retries clamped to `0..4`
|
||||
- retry delays clamped to `0..5000ms`
|
||||
- both env-derived and per-call numeric overrides are sanitized
|
||||
- Reduced duplicate logging noise:
|
||||
- non-retry terminal relay failures are marked as already logged in middleware
|
||||
- `relayGet` catch now skips `consoleLogger` when relay layer has already emitted a structured log
|
||||
- Expanded relay hardening tests:
|
||||
- no retry on `401`
|
||||
- duplicate logging suppression path through `relayGet`
|
||||
- env-value clamping behavior for timeout bounds
|
||||
|
||||
Validation:
|
||||
|
||||
- `node tests/phase21/relay-forwarding-hardening.test.cjs` -> pass (6/6)
|
||||
- `node tests/phase21/endpoint-handler-contract.test.cjs` -> pass (152/152)
|
||||
- `npm run lint` -> warnings only (pre-existing `react-hooks/exhaustive-deps`; no new lint errors)
|
||||
|
||||
Follow-ups:
|
||||
|
||||
- Batch 2B: update memory/context docs with canonical relay hardening policy, env knobs, and rollback/tuning guidance.
|
||||
|
||||
Reference in New Issue
Block a user