Skip to content

fix(worker): include HTTP status in code host retry warnings - #1576

Merged
brendan-kellam merged 3 commits into
mainfrom
brendan/fix-github-rate-limit-classification
Aug 13, 2026
Merged

fix(worker): include HTTP status in code host retry warnings#1576
brendan-kellam merged 3 commits into
mainfrom
brendan/fix-github-rate-limit-classification

Conversation

@brendan-kellam

@brendan-kellam brendan-kellam commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • replace the misleading rate-limit-specific warning with neutral request-failure wording
  • include the HTTP response status in retry warnings
  • preserve existing retry behavior and timing

Testing

  • yarn workspace @sourcebot/backend test --run
  • yarn workspace @sourcebot/backend build

Summary by CodeRabbit

  • Bug Fixes

    • Improved retry warnings for code host requests by including the request identifier and HTTP response status.
    • Retry timing and behavior remain unchanged.
  • Documentation

    • Added an unreleased changelog entry describing the enhanced retry warning details.

@github-actions

This comment has been minimized.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Changes

Retry warning status reporting

Layer / File(s) Summary
Retry warning message and validation
packages/backend/src/utils.ts, packages/backend/src/utils.test.ts, CHANGELOG.md
fetchWithRetry now logs the request identifier and HTTP status. The test checks status 429. The changelog records the change.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Mergeability Score: 🟡 Moderate · up to 8130f

The retry behavior may still misclassify unrelated 403 responses and omit useful GitHub response metadata, which could delay recovery and weaken production diagnosis; merge should wait for these issues to be corrected or explicitly accepted.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding HTTP status information to code host retry warnings.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch brendan/fix-github-rate-limit-classification

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit eb47d31. Configure here.

Comment thread packages/backend/src/utils.ts Outdated
@brendan-kellam brendan-kellam changed the title fix(worker): classify GitHub rate limit retries fix(worker): include status in retry warnings Aug 13, 2026
@brendan-kellam brendan-kellam changed the title fix(worker): include status in retry warnings fix(worker): include HTTP status in code host retry warnings Aug 13, 2026
@brendan-kellam
brendan-kellam merged commit a07c681 into main Aug 13, 2026
11 of 12 checks passed
@brendan-kellam
brendan-kellam deleted the brendan/fix-github-rate-limit-classification branch August 13, 2026 03:06

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/backend/src/utils.ts (1)

83-101: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Classify rate-limit responses before retrying.

Retry only rate-limited 403 responses. Keep 5xx retries on exponential backoff. Honor a valid Retry-After value first, then use x-ratelimit-reset only when x-ratelimit-remaining is 0. Fall back when headers are missing or invalid. Add tests for unrelated 403, secondary-limit Retry-After, primary-limit reset, 5xx with rate-limit headers, and malformed headers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/utils.ts` around lines 83 - 101, Update the retry logic
around the visible status check and reset-date calculation to classify responses
before retrying: retry 5xx errors with exponential backoff, but retry 403 only
when it is rate-limited; honor a valid Retry-After value first, then use
x-ratelimit-reset only when x-ratelimit-remaining is 0, otherwise fall back
safely for missing or malformed headers. Add coverage for unrelated 403s,
secondary-limit Retry-After, primary-limit reset, 5xx responses carrying
rate-limit headers, and malformed headers.

Source: MCP tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/backend/src/utils.ts`:
- Line 102: Update the retry warning in the request retry handler around
isOctokitRequestError(e) to pass available e.response?.headers values for
retry-after, x-ratelimit-remaining, x-ratelimit-reset, and x-github-request-id
as Winston metadata. Omit headers that are unavailable while preserving the
existing warning message and retry behavior.

---

Outside diff comments:
In `@packages/backend/src/utils.ts`:
- Around line 83-101: Update the retry logic around the visible status check and
reset-date calculation to classify responses before retrying: retry 5xx errors
with exponential backoff, but retry 403 only when it is rate-limited; honor a
valid Retry-After value first, then use x-ratelimit-reset only when
x-ratelimit-remaining is 0, otherwise fall back safely for missing or malformed
headers. Add coverage for unrelated 403s, secondary-limit Retry-After,
primary-limit reset, 5xx responses carrying rate-limit headers, and malformed
headers.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7dcb8fb1-10fd-472b-a1bc-f3ddf9b288d6

📥 Commits

Reviewing files that changed from the base of the PR and between eb47d31 and 8130f6b.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • packages/backend/src/utils.test.ts
  • packages/backend/src/utils.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • CHANGELOG.md
  • packages/backend/src/utils.test.ts


const waitTime = Math.max(0, resetDateMs - Date.now());
logger.warn(`Rate limit exceeded for ${identifier}. Waiting ${waitTime}ms before retry ${attempts}/${maxAttempts}...`);
logger.warn(`Request failed for ${identifier} with status ${e.status}. Waiting ${waitTime}ms before retry ${attempts}/${maxAttempts}...`);

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- target file outline ---'
ast-grep outline packages/backend/src/utils.ts || true

printf '%s\n' '--- target implementation ---'
cat -n packages/backend/src/utils.ts | sed -n '1,150p'

printf '%s\n' '--- error helper and logger usage ---'
rg -n -C 4 'isOctokitRequestError|logger\.warn|x-ratelimit|retry-after|x-github-request-id' packages/backend/src packages 2>/dev/null | head -n 300

printf '%s\n' '--- package metadata for logger dependencies ---'
rg -n '"(pino|winston|bunyan|logger)"|from .*(logger|pino|winston|bunyan)' packages/backend package.json packages/*/package.json 2>/dev/null | head -n 200

Repository: sourcebot-dev/sourcebot

Length of output: 29451


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- GitHub error helper ---'
rg -n -C 12 'isOctokitRequestError' packages/backend/src/github.ts packages/backend/src 2>/dev/null | head -n 220

printf '%s\n' '--- retry tests ---'
cat -n packages/backend/src/utils.test.ts | sed -n '1,340p'

printf '%s\n' '--- error helpers ---'
cat -n packages/backend/src/errors.ts | sed -n '1,120p'
cat -n packages/backend/src/errors.ts | sed -n '240,310p'

printf '%s\n' '--- Winston setup and logger construction ---'
rg -n -C 8 'createLogger|new Logger|winston|format\.|transports|logger\s*=' packages/backend/src packages/shared/src 2>/dev/null | head -n 300

printf '%s\n' '--- all request-id/header access ---'
rg -n -C 5 'x-github-request-id|retry-after|x-ratelimit-remaining|x-ratelimit-reset|response\.headers' packages/backend/src packages/shared/src 2>/dev/null | head -n 300

Repository: sourcebot-dev/sourcebot

Length of output: 50379


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- shared Winston logger implementation ---'
cat -n packages/shared/src/logger.ts | sed -n '1,180p'

printf '%s\n' '--- relevant package declarations ---'
rg -n -C 3 '"`@octokit/`(request-error|rest)"|"winston"' package.json packages/*/package.json pnpm-lock.yaml yarn.lock package-lock.json 2>/dev/null | head -n 160

printf '%s\n' '--- static consistency probe ---'
python3 - <<'PY'
from pathlib import Path

utils = Path("packages/backend/src/utils.ts").read_text()
logger = Path("packages/shared/src/logger.ts").read_text()

checks = {
    "retry warning currently uses one interpolated string": "logger.warn(`Request failed for ${identifier}" in utils,
    "retry path narrows Octokit errors before reading reset": "isOctokitRequestError(e) && e.response?.headers['x-ratelimit-reset']" in utils,
    "logger is Winston-backed": "import winston, { format, Logger } from 'winston';" in logger,
    "logger supports structured metadata": "return winston.createLogger({" in logger,
}
for name, result in checks.items():
    print(f"{name}: {'yes' if result else 'no'}")
PY

Repository: sourcebot-dev/sourcebot

Length of output: 11920


🌐 Web query:

GitHub REST API documentation response headers x-ratelimit-remaining x-ratelimit-reset retry-after x-github-request-id

💡 Result:

The GitHub REST API includes several response headers that provide information about your request status, rate limits, and request tracking. x-ratelimit-remaining: This header indicates the number of requests remaining in your current rate limit window [1][2]. If this value is 0, you have exhausted your primary rate limit for the current window [1][3]. x-ratelimit-reset: This header specifies the time at which the current rate limit window resets, provided in UTC epoch seconds [1][3]. If you exceed your primary rate limit (resulting in a 403 or 429 status code), you should not retry your requests until after this time has passed [1][2]. retry-after: When you exceed a secondary rate limit, the API may return this header [4][3]. It indicates the number of seconds you should wait before retrying your request [3][2]. If this header is present, you must wait at least that many seconds before making another request [3][5]. x-github-request-id: This is a unique identifier assigned to every request made to the GitHub API [6]. It is useful for troubleshooting purposes, as you can provide this ID to GitHub support if you need to investigate specific issues or failed requests. In general, if you receive a 403 or 429 error and no retry-after header is present, the documentation recommends waiting at least one minute before retrying [3][7]. If failures persist due to secondary rate limits, you should implement an exponentially increasing wait time between retries [3][2].

Citations:


Include available GitHub response metadata in the retry warning.

When isOctokitRequestError(e) is true, pass retry-after, x-ratelimit-remaining, x-ratelimit-reset, and x-github-request-id from e.response?.headers as Winston metadata. Omit unavailable headers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/utils.ts` at line 102, Update the retry warning in the
request retry handler around isOctokitRequestError(e) to pass available
e.response?.headers values for retry-after, x-ratelimit-remaining,
x-ratelimit-reset, and x-github-request-id as Winston metadata. Omit headers
that are unavailable while preserving the existing warning message and retry
behavior.

Source: MCP tools

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