Fix: Apply HTTP client timeouts to prevent infinite hangs #23
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Fix: Apply HTTP client timeouts to prevent infinite hangs
Summary
Fixes a critical bug where octocode's GraphRAG indexing process hangs indefinitely during LLM API calls. The root cause is that
reqwest::Clientinstances are created usingClient::new()instead of the builder pattern, which prevents the configuredbatch_timeout_secondsfrom being applied.Problem
When using LLM-powered GraphRAG features (
use_llm = true), the indexing process hangs indefinitely at two points:ai_batch_size > 1)The configuration parameter
graphrag.llm.batch_timeout_secondsis loaded but never applied to the HTTP client, causing requests to wait indefinitely when the LLM provider is slow to respond.Root Cause Analysis
Primary Bug (
src/indexer/graphrag/builder.rs:74)Secondary Bug (
src/embedding/provider/huggingface.rs:460)Reproduction
use_llm = trueandai_batch_size > 1octocode indexon any codebasebatch_timeout_secondsexpiresTesting
Before Fix
ai_batch_size = 1only helped description phaseAfter Fix
Impact
This bug made LLM-powered GraphRAG features unusable for any non-trivial codebase. The fix enables:
Related Documentation
Full technical analysis available at: octocode_timeout_analysis.md
Code Quality Improvements
In addition to the core timeout fixes, this PR includes:
Enhanced Error Handling
.context()error messages to both HTTP client build failuresDocumentation Comments
These comments at both fix locations help prevent future regressions.
Code Verification
Client::new()uses verified (3 instances in commands/ use request-level timeouts correctly)Technical Details
Why Client::new() Doesn't Apply Timeouts
The
reqwest::Client::new()convenience method creates a client with default settings that do not include any timeout. To apply a timeout, you must use the builder pattern:Request-Level vs Client-Level Timeouts
This PR uses client-level timeouts. An alternative approach is request-level timeouts:
The codebase uses both patterns appropriately:
src/commands/where each request may need different timeoutsTest Results
Unit Tests
cargo test --all-featuresResults: 93 passed, 3 failed
The 3 failures are unrelated FastEmbed lock acquisition issues:
test_fastembed_provider_creationtest_fastembed_model_validationtest_fastembed_embedding_generationThese failures are environmental (file lock contention in local cache directory), not caused by the timeout fix changes.
Integration Testing
Real-world test on rust-daq codebase (113 files):
Configuration Tested
Migration Guide for Developers
If you're creating new HTTP clients in octocode:
For LLM/API Calls
For File Downloads
Don't Use Client::new()
Unless you have a specific reason to avoid timeouts (rare), always use the builder pattern.
Related Issues
This fix resolves the core issue documented in:
Checklist