Skip to content

fix(context_engine): prevent retry loop on connection refused errors#2395

Merged
tusharmath merged 3 commits intomainfrom
connection-error-retry
Feb 13, 2026
Merged

fix(context_engine): prevent retry loop on connection refused errors#2395
tusharmath merged 3 commits intomainfrom
connection-error-retry

Conversation

@tusharmath
Copy link
Copy Markdown
Collaborator

@tusharmath tusharmath commented Feb 13, 2026

Summary

Improves gRPC error handling by detecting connection refused errors and preventing unnecessary retry attempts. This change eliminates retry loops when the semantic search service is offline, providing faster failure feedback and reducing system load from futile connection attempts.

Changes

Core Functionality

  • Enhanced retry logic: Added connection error detection in should_retry_grpc() to identify service offline scenarios
  • Error pattern matching: Checks for "Connection refused" and "tcp connect error" messages before attempting retries
  • Improved logging: Updated retry warning message for better clarity

Implementation Details

  • Modified should_retry_grpc() function in context_engine.rs to inspect error messages for connection failures
  • Connection errors (ECONNREFUSED, tcp connect errors) now return false immediately, skipping retry logic
  • Existing retry behavior preserved for transient errors (timeouts, rate limits, service unavailable without connection issues)

Testing

Added comprehensive test coverage:

  • ✅ Connection refused errors (OS error 61)
  • ✅ TCP connect errors
  • ✅ Transport errors with connection issues
  • ✅ Unavailable status with underlying connection refused (bug scenario)
  • ✅ Normal unavailable errors still trigger retries (regression test)

Impact

  • Faster failure detection: Applications fail immediately when service is offline instead of exhausting retry attempts
  • Reduced resource usage: Eliminates CPU and network overhead from retry loops on dead connections
  • Better user experience: Clearer error messages without retry noise in logs

Co-Authored-By: ForgeCode noreply@forgecode.dev

@github-actions github-actions Bot added the type: fix Iterations on existing features or infrastructure. label Feb 13, 2026
@tusharmath tusharmath changed the title fix(context_engine): skip retry on connection refused errors fix(context_engine): prevent retry loop on connection refused errors Feb 13, 2026
Comment on lines +54 to +56
let error_msg = format!("{:#}", error);
if error_msg.contains("Connection refused") || error_msg.contains("tcp connect error") {
return false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case-sensitive string matching will miss lowercase error messages

The string matching uses .contains("Connection refused") and .contains("tcp connect error") which are case-sensitive. If an error message contains "connection refused" (lowercase) or "TCP connect error" (uppercase), it won't be caught and will proceed to retry.

While OS errors typically use consistent casing, different OS versions, libraries, or error wrapping could produce varied casing.

Fix:

let error_msg = format!("{:#}", error).to_lowercase();
if error_msg.contains("connection refused") || error_msg.contains("tcp connect error") {
    return false;
}
Suggested change
let error_msg = format!("{:#}", error);
if error_msg.contains("Connection refused") || error_msg.contains("tcp connect error") {
return false;
let error_msg = format!("{:#}", error).to_lowercase();
if error_msg.contains("connection refused") || error_msg.contains("tcp connect error") {
return false;

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@tusharmath tusharmath enabled auto-merge (squash) February 13, 2026 06:30
@tusharmath tusharmath merged commit 94ee66c into main Feb 13, 2026
9 checks passed
@tusharmath tusharmath deleted the connection-error-retry branch February 13, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant