Skip to content

Add exponential backoff retry for Overpass API timeouts#23

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/add-timeout-handling-overpass
Draft

Add exponential backoff retry for Overpass API timeouts#23
Copilot wants to merge 4 commits intomainfrom
copilot/add-timeout-handling-overpass

Conversation

Copy link
Contributor

Copilot AI commented Feb 11, 2026

Overpass API calls fail on transient 504 Gateway Timeout and 429 Rate Limit errors without retry, causing unnecessary data collection failures.

Changes

  • Retry logic with exponential backoff: Added withRetry<T> wrapper in collect/api/overpass.ts that attempts requests 3 times (initial + 2 retries) with 1s, 2s backoff delays
  • Selective retry: Only retries on OverpassGatewayTimeoutError (504) and OverpassRateLimitError (429); other errors fail fast
  • Transparent integration: Both overpassSimpleQuery() and overpassRawQuery() automatically benefit through callApi()

Implementation

async function withRetry<T>(function_: () => Promise<T>, maxRetries: number = 2): Promise<T> {
    for (let attempt = 0; attempt <= maxRetries; attempt += 1) {
        try {
            return await function_();
        } catch (error) {
            const isRetriableError = error instanceof OverpassGatewayTimeoutError 
                || error instanceof OverpassRateLimitError;
            
            if (!isRetriableError || attempt === maxRetries) {
                throw error;
            }
            
            await delay((2 ** attempt) * 1000); // Exponential backoff
        }
    }
}

Test coverage includes retry success scenarios, backoff timing verification, retry exhaustion, and non-retriable error handling.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 11, 2026 18:30
Co-authored-by: wvanderp <2423856+wvanderp@users.noreply.github.com>
…e limits

Co-authored-by: wvanderp <2423856+wvanderp@users.noreply.github.com>
Co-authored-by: wvanderp <2423856+wvanderp@users.noreply.github.com>
Copilot AI changed the title [WIP] Add robust handling of timeouts with Overpass Add exponential backoff retry for Overpass API timeouts Feb 11, 2026
Copilot AI requested a review from wvanderp February 11, 2026 18:37
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.

2 participants

Comments