Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: implement retry loop for LLM API failures in community labeling#1312

Open
matiasduartee wants to merge 7 commits into
safishamsi:v8from
matiasduartee:feat-llm-retry
Open

feat: implement retry loop for LLM API failures in community labeling#1312
matiasduartee wants to merge 7 commits into
safishamsi:v8from
matiasduartee:feat-llm-retry

Conversation

@matiasduartee

Copy link
Copy Markdown

This PR adds a retry mechanism with exponential backoff to \label_communities\ to gracefully handle transient network errors, timeouts, or API rate limits, preventing entire batches of communities from being dropped silently.

@matiasduartee

Copy link
Copy Markdown
Author

Testing Results on Real-World Repositories

To ensure the robustness of this PR, I ran the updated fork locally against three medium-to-large private enterprise repositories (ranging from backend APIs to frontend systems). The retry logic behaved exactly as expected across all scenarios.

Test Subjects:

  1. Project A (Backend): 105 code files, 746 nodes, 1,079 edges, 71 communities.
  2. Project B (Backend): 82 code files, 540 nodes, 872 edges, 22 communities.
  3. Project C (Frontend): 119 code files, 2,333 nodes, 4,957 edges, 191 communities.

Behavior Observed (Stress Testing):
During the execution of Project C (which batched 191 communities), the local Gemini free-tier API hit a hard quota (429 Too Many Requests). Without this PR, the label_communities function would have swallowed the exception and skipped the remaining batches silently.

With the new exponential backoff retry loop, we got this exact terminal output:
\\ ext
[graphify label] batch 1/2 attempt 1 failed: label response could not be parsed as JSON or via regex fallback. Retrying in 2s...
[graphify label] batch 1/2 attempt 2 failed: Error code: 429 - 'You exceeded your current quota'. Retrying in 4s...
[graphify label] batch 1/2 (100 communities) failed after 3 attempts: Error code: 429

[graphify label] batch 2/2 attempt 1 failed: Error code: 429. Retrying in 2s...
[graphify label] batch 2/2 attempt 2 failed: Error code: 429. Retrying in 4s...
[graphify label] batch 2/2 (91 communities) failed after 3 attempts: Error code: 429

[graphify label] warning: community labeling failed (Error code: 429); using Community N placeholders.
\\

The system gracefully handled multiple transient errors across different batches, backed off exponentially, and safely degraded to placeholders when the hard limit was hit without crashing the graph generation. The graph.json and graph.html were successfully generated.

The fix is robust and production-ready!

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.

1 participant