Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Upgraded `@sentry/*` to `^10.70.0`, fixing memory leaks where spans retained request data indefinitely. [#1572](https://github.com/sourcebot-dev/sourcebot/pull/1572)
- Fixed code search result links occasionally getting stuck during navigation and restored Cmd/Ctrl-click to open matches in preview. [#1574](https://github.com/sourcebot-dev/sourcebot/pull/1574)
- Fixed a server-side memory leak where a single shared react-query cache retained state from every server render; the cache is now created per-request. [#1575](https://github.com/sourcebot-dev/sourcebot/pull/1575)
- Fixed code host retry warnings to include the HTTP response status. [#1576](https://github.com/sourcebot-dev/sourcebot/pull/1576)

## [5.1.6] - 2026-08-10

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ describe('fetchWithRetry', () => {

expect(logger.warn).toHaveBeenCalledTimes(1);
expect(logger.warn).toHaveBeenCalledWith(
expect.stringContaining('test-identifier')
expect.stringContaining('test-identifier with status 429')
);
});
});
2 changes: 1 addition & 1 deletion packages/backend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const fetchWithRetry = async <T>(
})();

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


await new Promise(resolve => setTimeout(resolve, waitTime));
continue;
Expand Down
Loading