dzen.nstarikov.ru/dzen-assistant/docs/superpowers/plans/2026-08-11-timeweb-data-inspection-retry.md

3.6 KiB
Raw Blame History

Timeweb Data Inspection Retry Implementation Plan

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.

Goal: Retry only transient Timeweb DataInspectionFailed HTTP 400 responses within the existing bounded LLM request loop.

Architecture: Extend the existing HTTPStatusError branch in call_llm() with one exact provider marker. Reuse the configured attempt count and backoff; keep every other status path unchanged and cover both retry and non-retry behavior with mocked HTTP responses.

Tech Stack: Python 3.12, stdlib unittest and unittest.mock, HTTPX, Docker Compose, Celery, Forgejo Actions.


Task 1: Add failing HTTP retry tests

Files:

  • Create: tests/test_worker_llm_http_retry.py

  • Test: tests/test_worker_llm_http_retry.py

  • Step 1: Test transient inspection rejection followed by success

Mock SessionLocal to return no extra instructions, mock httpx.Client with a 400 response containing DataInspectionFailed followed by a valid completion, and mock time.sleep. Assert two POST calls, one sleep(2), and returned completion content.

  • Step 2: Test that an unrelated 400 remains final

Return HTTP 400 with invalid_request_error but without DataInspectionFailed. Assert one POST call, no sleep, and RuntimeError containing LLM-редактор отклонил запрос с кодом 400.

  • Step 3: Run the tests before implementation

Run in the project Docker test image:

docker run --rm -v "$PWD:/workspace:ro" -w /workspace dzen-assistant-test:local python -m unittest tests.test_worker_llm_http_retry -v

Expected: the transient-inspection test errors on the first 400; the unrelated-400 test passes.

Task 2: Implement the bounded provider-specific retry

Files:

  • Modify: app/worker.py:945-954

  • Test: tests/test_worker_llm_http_retry.py

  • Step 1: Add the exact marker branch

Inside except httpx.HTTPStatusError, before the generic status handling, add:

                if status_code == 400 and "DataInspectionFailed" in detail:
                    if attempt < attempts:
                        time.sleep(2 * attempt)
                        continue
                    raise RuntimeError(
                        f"Timeweb LLM отклонил проверку входных данных после {attempts} попыток: {detail}"
                    ) from exc
  • Step 2: Run focused tests and syntax checks

Run:

docker run --rm -v "$PWD:/workspace:ro" -w /workspace dzen-assistant-test:local python -m unittest tests.test_worker_llm_http_retry tests.test_worker_llm_retry -v
docker run --rm -e PYTHONPYCACHEPREFIX=/tmp/pycache -v "$PWD:/workspace:ro" -w /workspace dzen-assistant-test:local python -m compileall -q app tests
git diff --check -- app/worker.py tests/test_worker_llm_http_retry.py

Expected: three tests pass; compile and diff checks exit 0.

  • Step 3: Commit, push, and verify production

Commit only app/worker.py and tests/test_worker_llm_http_retry.py, push main, verify the Forgejo deployment rebuilds all app services, public /health returns 200, and the running worker contains the exact marker branch.

  • Step 4: Reprocess video 213 once

Queue the current automatically selected chapters once, monitor to drafted or error, and query the resulting non-rejected articles. Do not launch another full-video retry if the bounded provider retry is exhausted.