Skip to content

Bound Anthropic stream retries to one transport budget - #181

Open
Anteriousis wants to merge 1 commit into
10-X-eng:mainfrom
Anteriousis:fix/anthropic-retry-budget
Open

Bound Anthropic stream retries to one transport budget#181
Anteriousis wants to merge 1 commit into
10-X-eng:mainfrom
Anteriousis:fix/anthropic-retry-budget

Conversation

@Anteriousis

Copy link
Copy Markdown
Contributor

Repeated Anthropic connection/read failures could submit one streamed generation 18 times: three SDK transport attempts inside each of six application attempts. This change makes the existing application loop own stream retries, limiting a generation to six actual transport attempts.

SDK retries are disabled on the streaming client only after model capability retrieval. Metadata retrieval and the separate compaction client retain their existing SDK retry policy. HTTP status failures retain a three-failure allowance within the six-attempt total; transient 408/409/429/5xx responses and explicit server retry directives are handled by the outer loop. Retry-After seconds, milliseconds, and HTTP dates are honored within the SDK's existing 60-second range.

Retry progress now includes the transport attempt count and whether response content was observed, alongside the existing turn/attempt fields. Connection/read failures retain the existing short backoff; HTTP failures use bounded exponential backoff. Retries do not execute partially received CAD tool calls.

Verification

  • For code changes, a test failed before the implementation and passes afterward; for non-code changes, the PR explains why TDD does not apply.
  • The PR lists the exact build and test commands and their results.

Test environment: Windows, the repository-pinned Anthropic SDK 0.116.0, and httpx.MockTransport. The full provider child executes against the actual SDK; no HTTP request reaches the network. In the commands below, $python and $git denote the absolute executable paths used; machine-specific paths are omitted.

Red baseline:

& $python -m pytest -q src/Mod/VibeCAD/vibecad_tests/test_anthropic_retry_budget.py --tb=line

6 failed, 11 passed. Connection/read failures produced 18 transport attempts instead of 6; SDK-internal status retries were absent from the application retry events.

Additional telemetry red tests:

& $python -m pytest -q src/Mod/VibeCAD/vibecad_tests/test_anthropic_retry_budget.py src/Mod/VibeCAD/vibecad_tests/test_provider_subprocess.py -k 'total_transport or retry_wait' --tb=line

7 failed, 2 passed, 68 deselected before adding the telemetry fields. Parent cancellation/deadline termination tests already passed.

Final green:

& $python -m pytest -q src/Mod/VibeCAD/vibecad_tests/test_anthropic_retry_budget.py src/Mod/VibeCAD/vibecad_tests/test_provider_subprocess.py src/Mod/VibeCAD/vibecad_tests/test_gemini_provider.py --tb=short
& $python -m py_compile src/Mod/VibeCAD/VibeCADProvider.py src/Mod/VibeCAD/vibecad_tests/test_anthropic_retry_budget.py src/Mod/VibeCAD/vibecad_tests/test_provider_subprocess.py
& $git diff --cached --check

85 passed, 1 skipped; compilation and whitespace checks passed. The skip is Linux-specific.

Coverage includes persistent and mixed failures, recovery on the sixth attempt, interruption after streamed content, permanent errors, server backoff and malformed headers, and unchanged metadata/compaction retry policies. Parent cancellation/deadline tests use a simulated waiting child and verify termination before the parent continues waiting.

No paid model requests or full GUI/C++ build were performed. This is a Python provider orchestration change. Fewer failed transport attempts do not imply that every avoided attempt would have been billable.

Issues

Closes #177.

Before and After Images

Not applicable: no GUI layout changes. Under persistent connection/read failures, the observed request count changes from 18 to 6.

Compatibility

  • Existing public functions/APIs remain present.
  • No preference keys, tool names, or schema fields renamed or removed.
  • Model selection, reasoning/output limits, CAD tool contracts, and provider turn limits remain unchanged.
  • Existing six-attempt stream recovery remains available.
  • Metadata and compaction SDK retries remain unchanged.
  • No dependency or packaging changes; no deprecations.

The deliberate behavior change is removal of nested transport retries. Status errors share the overall budget while retaining their existing three-failure ceiling. This PR is independent of the Gemini fix in #180.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use one total retry budget for Anthropic stream requests

1 participant