fix: add rate limit patterns for 'too many tokens' and 'tokens per day' (#39377)

Merged via squash.

Prepared head SHA: 132a457286
Co-authored-by: gambletan <266203672+gambletan@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
This commit is contained in:
gambletan
2026-03-08 18:03:33 +08:00
committed by GitHub
parent aedf3ee68f
commit 8a20f51460
7 changed files with 98 additions and 3 deletions

View File

@@ -103,6 +103,32 @@ describe("memory embedding batches", () => {
expect(calls).toBe(3);
}, 10000);
it("retries embeddings on too-many-tokens-per-day rate limits", async () => {
const memoryDir = fx.getMemoryDir();
const managerSmall = fx.getManagerSmall();
const line = "e".repeat(120);
const content = Array.from({ length: 4 }, () => line).join("\n");
await fs.writeFile(path.join(memoryDir, "2026-01-08.md"), content);
let calls = 0;
embedBatch.mockImplementation(async (texts: string[]) => {
calls += 1;
if (calls === 1) {
throw new Error("AWS Bedrock embeddings failed: Too many tokens per day");
}
return texts.map(() => [0, 1, 0]);
});
const restoreFastTimeouts = useFastShortTimeouts();
try {
await managerSmall.sync({ reason: "test" });
} finally {
restoreFastTimeouts();
}
expect(calls).toBe(2);
}, 10000);
it("skips empty chunks so embeddings input stays valid", async () => {
const memoryDir = fx.getMemoryDir();
const managerSmall = fx.getManagerSmall();