Skip to content

Commit 5eea67c

Browse files
committed
fix: improve rate limit handling and error messages
- Add proper error message extraction (fixes [object Object] display) - Detect 429 rate limit errors and reduce concurrency to 1 - Use exponential backoff with factor 2, max 30s timeout - Show clearer rate limit messages to user
1 parent 00cd160 commit 5eea67c

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opencode-codebase-index",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "Semantic codebase indexing and search for OpenCode - find code by meaning, not just keywords",
55
"type": "module",
66
"main": "dist/index.js",

src/indexer/index.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ function bufferToFloat32Array(buf: Buffer): Float32Array {
3535
return new Float32Array(buf.buffer, buf.byteOffset, buf.byteLength / 4);
3636
}
3737

38+
function getErrorMessage(error: unknown): string {
39+
if (error instanceof Error) {
40+
return error.message;
41+
}
42+
if (typeof error === "string") {
43+
return error;
44+
}
45+
if (error && typeof error === "object" && "message" in error) {
46+
return String((error as { message: unknown }).message);
47+
}
48+
return String(error);
49+
}
50+
51+
function isRateLimitError(error: unknown): boolean {
52+
const message = getErrorMessage(error);
53+
return message.includes("429") || message.toLowerCase().includes("rate limit") || message.toLowerCase().includes("too many requests");
54+
}
55+
3856
export interface IndexStats {
3957
totalFiles: number;
4058
totalChunks: number;
@@ -494,10 +512,20 @@ export class Indexer {
494512
{
495513
retries: this.config.indexing.retries,
496514
minTimeout: this.config.indexing.retryDelayMs,
515+
maxTimeout: 30000,
516+
factor: 2,
497517
onFailedAttempt: (error) => {
498-
console.error(
499-
`Embedding batch failed (attempt ${error.attemptNumber}): ${String(error)}`
500-
);
518+
const message = getErrorMessage(error);
519+
if (isRateLimitError(error)) {
520+
queue.concurrency = 1;
521+
console.error(
522+
`Rate limited (attempt ${error.attemptNumber}/${error.retriesLeft + error.attemptNumber}): waiting before retry...`
523+
);
524+
} else {
525+
console.error(
526+
`Embedding batch failed (attempt ${error.attemptNumber}): ${message}`
527+
);
528+
}
501529
},
502530
}
503531
);
@@ -537,8 +565,8 @@ export class Indexer {
537565
});
538566
} catch (error) {
539567
stats.failedChunks += batch.length;
540-
this.addFailedBatch(batch, String(error));
541-
console.error(`Failed to embed batch after retries: ${error}`);
568+
this.addFailedBatch(batch, getErrorMessage(error));
569+
console.error(`Failed to embed batch after retries: ${getErrorMessage(error)}`);
542570
}
543571
});
544572
}

0 commit comments

Comments
 (0)