fix(worker): include HTTP status in code host retry warnings - #1576
Conversation
This comment has been minimized.
This comment has been minimized.
WalkthroughChangesRetry warning status reporting
Estimated code review effort: 1 (Trivial) | ~5 minutes Mergeability Score: 🟡 Moderate · up to 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)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ 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.
There was a problem hiding this comment.
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 winClassify rate-limit responses before retrying.
Retry only rate-limited
403responses. Keep5xxretries on exponential backoff. Honor a validRetry-Aftervalue first, then usex-ratelimit-resetonly whenx-ratelimit-remainingis0. Fall back when headers are missing or invalid. Add tests for unrelated403, secondary-limitRetry-After, primary-limit reset,5xxwith 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
📒 Files selected for processing (3)
CHANGELOG.mdpackages/backend/src/utils.test.tspackages/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}...`); |
There was a problem hiding this comment.
📐 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 200Repository: 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 300Repository: 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'}")
PYRepository: 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:
- 1: https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api
- 2: https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2026-03-10
- 3: https://docs.github.com/en/rest/using-the-rest-api/troubleshooting-the-rest-api?apiVersion=2026-03-10
- 4: https://github.com/github/docs/blob/main/content/rest/using-the-rest-api/rate-limits-for-the-rest-api.md
- 5: https://docs.github.com/en/enterprise-cloud@latest/rest/using-the-rest-api/best-practices-for-using-the-rest-api?apiVersion=2026-03-10
- 6: https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api?tool=cli
- 7: https://docs.github.com/en/rest/using-the-rest-api/troubleshooting-the-rest-api
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

Summary
Testing
Summary by CodeRabbit
Bug Fixes
Documentation