SkillSpector icon indicating copy to clipboard operation
SkillSpector copied to clipboard

Fix(llm): retry transient failures and make concurrency configurable

Open jhamze7 opened this issue 5 months ago • 2 comments

This pull request addresses the issue of LLM calls immediately failing due to a lack of retry logic.

Changes:

llm_utils.py:

Created helper functions for the sync and async batch runners that retry LLM calls 4 times by default (this number is configurable with the max_attempts argument) with exponential backoff timing. These functions string match the error message to keep the implementation universal across different providers.

llm_analyzer_base.py:

Wrapped the LLM calls in the helper functions created in llm_utils.py. Also set max_concurrency to the SKILLSPECTOR_MAX_CONCURRENCY environment variable, with the value defaulting to 5 if the variable is empty.

.env.example:

Created a SKILLSPECTOR_MAX_CONCURRENCY environment variable. This change was also noted in docs/DEVELOPMENT.md

test_llm_analyzer_base.py:

Added sync and async tests verifying that LLM calls are retried when a simulated 429 error occurs. The tests also verify that processing succeeds after a transient failure and raises an exception once the retry limit is exhausted.


Closes #10

jhamze7 avatar Jun 12 '26 03:06 jhamze7

Verified on a self-hosted OpenAI-compatible backend (vLLM serving Qwen/Qwen3.6-35B-A3B-FP8).

  • Configurable concurrency works: scanning the repo's tests/fixtures/malicious_skill/ fixture with LLM analysis completes the full pass at SKILLSPECTOR_MAX_CONCURRENCY=5 (default) and at 3. Being able to tune concurrency down is what a single-instance backend needs.
  • Retry classifier behaves as written: exercising retry_llm_call_sync directly — 429 and timeout errors are retried (4 attempts with backoff), non-retryable errors raise immediately. Matches the PR's stated scope.

LGTM for the #10 retry/backoff + configurable concurrency goal.

CharmingGroot avatar Jun 12 '26 04:06 CharmingGroot

I went ahead and fixed the max concurrency logic by adding a more robust helper function in llm_utils.py that handles the edge cases discussed, along with a test to cover it in test_llm_analyzer_base.py. I've also added jitter to stagger the retry backoff of LLM API requests. Please let me know if there’s anything else that should be addressed!

jhamze7 avatar Jun 23 '26 17:06 jhamze7