1.9 KiB
Timeweb Data Inspection Retry Design
Context
After the malformed-JSON retry fix reached production, video #213 passed JSON parsing and processed several chapters. Timeweb then intermittently returned HTTP 400 with InternalError.Algo.DataInspectionFailed. The same chapter was accepted in one run and rejected in another, so this provider response is transient in practice. The current HTTP client treats every 4xx response as final and aborts the whole multi-chapter transaction immediately.
Design
- Recognize only HTTP 400 responses whose body contains the exact marker
DataInspectionFailed. - Retry those responses inside the existing
call_llm()loop usingsettings.llm_retry_attemptsand the existing2 * attemptbackoff. - Preserve immediate failure for every other 4xx response.
- Preserve the existing handling of transport errors and 5xx responses.
- After the configured attempts are exhausted, raise a specific runtime error that states Timeweb rejected input inspection after all attempts.
Testing
Use isolated stdlib unittest mocks for httpx.Client, SessionLocal, and time.sleep:
- A
DataInspectionFailedresponse followed by a valid completion performs two requests, sleeps once, and returns the completion content. - A different HTTP 400 response performs one request, does not sleep, and raises the existing rejection error.
No real LLM, database, or network calls are used.
Production Verification
Deploy through Forgejo, verify public health and the code inside the running worker, then reprocess video #213. Completion requires at least one draft article and a terminal drafted status; health alone is insufficient. Do not launch repeated full-video jobs if the bounded retry is exhausted.
Non-goals
- Do not weaken or bypass Timeweb moderation.
- Do not retry arbitrary HTTP 400 responses.
- Do not change transcript text, prompts, article quality rules, or frame lifecycle.