Skip to content

Commit 7983f9e

Browse files
fix(server): reject empty replay corpora before scaling
1 parent 11400ac commit 7983f9e

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎apps/server/scripts/replay-project-memory.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ it.effect("replays invented facts through recall and names the gate", () =>
107107
.split("\n")
108108
.map((line) => JSON.parse(line) as ReplayRow);
109109
assert.equal(lines.length, 4);
110+
yield* fs.writeFileString(factsPath, "[]");
111+
const failure = yield* replayProjectMemory({
112+
facts: factsPath,
113+
messages: messagesPath,
114+
out,
115+
factCount: 1,
116+
}).pipe(
117+
Effect.as("unexpected success"),
118+
Effect.catchCause((cause) => Effect.succeed(Cause.pretty(cause))),
119+
);
120+
assert.include(failure, "Cannot scale an empty fact corpus");
110121
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
111122
);
112123

‎apps/server/scripts/replay-project-memory.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ const scaleFacts = (
278278
left.id < right.id ? -1 : left.id > right.id ? 1 : 0,
279279
);
280280
if (count <= sorted.length) return sorted.slice(0, count);
281+
if (sorted.length === 0) throw new Error("Cannot scale an empty fact corpus");
281282
const scaled = [...sorted];
282283
let copy = 1;
283284
while (scaled.length < count) {

0 commit comments

Comments
 (0)