Skip to content

Commit 2bc3eac

Browse files
committed
fix(memory): read a scope's compile watermark in the scope's own turn
Two compiles of one scope at once (two compileWiki() calls, or close() beside an explicit compile) both read the watermark before the first entered the scope's queue. The second then compiled from the old watermark and sent the same traces to the model again. The watermark is now read once the compile's turn comes, so a compile that waited starts where the earlier one left it; a scope deleted meanwhile is skipped. Signed-off-by: jddunn <[email protected]>
1 parent 7812d3a commit 2bc3eac

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎src/cognition/memory/io/facade/Memory.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,8 +1827,15 @@ export class Memory {
18271827
): Promise<CompileSkipReason | undefined> {
18281828
const BATCH = 500;
18291829
const { scopeId } = target;
1830+
// The watermark is read here, in the scope's turn: a compile that waited for another compile of the scope starts
1831+
// where that one left it, and sends none of the same traces to the model again. A scope deleted meanwhile is done.
1832+
const current = await this._brain.get<{ compiled_at: number | string | null }>(
1833+
`SELECT compiled_at FROM memory_scopes WHERE brain_id = ? AND scope = ? AND scope_id = ?`,
1834+
[this._brain.brainId, CONVERSATION_SCOPE, scopeId],
1835+
);
1836+
if (!current) return undefined;
18301837
const store = wiki.storeFor(scopeId);
1831-
let sinceMs = target.compiledAt;
1838+
let sinceMs = current.compiled_at === null || current.compiled_at === undefined ? 0 : Number(current.compiled_at);
18321839
for (;;) {
18331840
const belowMs = this._beginCompileRead();
18341841
const read = await this._compileTraces(scopeId, { sinceMs, belowMs, limit: BATCH });

0 commit comments

Comments
 (0)