Files
OmniRoute/tests/unit/13601-embed-retry.test.ts
lorenzozane 5847c43922 fix(resilience): name collision keys, surface header drops, retry embeds, skip far-reset pings (#13766)
Merged. Four small, independently justified changes, each with its own regression test — naming both sides of a case-insensitive key collision, surfacing the dropped-header count to the caller instead of only to the log, one retry before a memory is left unvectorized, and skipping warm pings for a window whose reset is more than 24h out. The first-seen-wins resolution and the caller-visible behaviour of everything else are unchanged.

Validated as a combined board first (this PR merged with the 21 siblings of the same wave on the release tip): eslint with the frozen suppressions, typecheck:core, check:open-sse-typecheck, complexity, cognitive-complexity, changelog-integrity, i18n new-key coverage, docs-counts, docs-sync, migration-numbering, provider-consistency and a duplicate-identifier audit all green, plus 176 passing / 0 failing focused node:test cases across the 25 test files the wave touches and the dashboard test under Vitest (2/0). Then re-validated alone on the fresh tip before this merge: conflicts re-resolved, file sizes rebaselined for this PR's own growth, eslint and this PR's focused tests re-run.

Thank you for keeping each of the four minimal and commented — that is what made this reviewable as one PR.
2026-09-16 13:36:35 -03:00

44 lines
1.6 KiB
TypeScript

// #13601.3: a failed memory vector embedding write must be retried once
// before it is logged and queued for reindex — a single transient failure
// (slow potion load, brief remote 5xx) should not silently skip vectorization.
import { test } from "node:test";
import assert from "node:assert/strict";
const { embedWithRetry } = await import("../../src/lib/memory/embedding/index.ts");
type EmbedResult = { vector: number[] } | { reason: string; message: string };
const settings = {} as Parameters<typeof embedWithRetry>[1];
test("#13601.3: success on the first attempt performs exactly one embed", async () => {
let calls = 0;
const result = (await embedWithRetry("hello", settings, async () => {
calls += 1;
return { vector: [1, 2, 3] };
})) as EmbedResult;
assert.equal(calls, 1);
assert.ok("vector" in result);
});
test("#13601.3: a transient first failure is retried and can still succeed", async () => {
let calls = 0;
const result = (await embedWithRetry("hello", settings, async () => {
calls += 1;
if (calls === 1) return { reason: "request_failed", message: "boom" };
return { vector: [1, 2, 3] };
})) as EmbedResult;
assert.equal(calls, 2);
assert.ok("vector" in result);
});
test("#13601.3: a persistent failure surfaces the last error after one retry", async () => {
let calls = 0;
const result = (await embedWithRetry("hello", settings, async () => {
calls += 1;
return { reason: "request_failed", message: `boom-${calls}` };
})) as EmbedResult;
assert.equal(calls, 2);
assert.ok(!("vector" in result));
if (!("vector" in result)) assert.equal(result.message, "boom-2");
});