Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(memory): restrict tidy decisions to notes shown to the model

Afloatfb2cd85f89ed
diff --git a/server/memory-tidy.ts b/server/memory-tidy.ts
index 6dd87e9687..eb0b5d2550 100644
--- a/server/memory-tidy.ts
+++ b/server/memory-tidy.ts
@@ -125,7 +125,7 @@ export function parseContradictions(text: string, count: number): Contradiction[
if (!Number.isInteger(a) || !Number.isInteger(b) || a === b) continue;
const ia = a as number;
const ib = b as number;
- if (ia < 0 || ib < 0 || ia >= count || ib >= count) continue;
+ if (ia < 0 || ib < 0 || ia >= Math.min(count, PROMPT_ENTRIES) || ib >= Math.min(count, PROMPT_ENTRIES)) continue;
if (keep !== "a" && keep !== "b") continue;
const key = `${Math.min(ia, ib)}:${Math.max(ia, ib)}`;
if (seen.has(key)) continue;
diff --git a/server/memory-upkeep.test.ts b/server/memory-upkeep.test.ts
index 88c0f6f61e..47631e524e 100644
--- a/server/memory-upkeep.test.ts
+++ b/server/memory-upkeep.test.ts
@@ -8,7 +8,7 @@ import { passageMatcher } from "./memory-entries.ts";
import { mergeTopicText, parseTopicHeader } from "./memory-topics.ts";
import { applyMoves, MAX_MOVES, organizeCandidates, ORGANIZE_MARKER, organizePrompt, parseMoves } from "./memory-organize.ts";
import { flushMemoryJournal, readMemoryJournal, revertMemoryChange } from "./memory-journal.ts";
-import { applyTidy, contradictionBudget, contradictionCandidates, parseContradictions, planTidy } from "./memory-tidy.ts";
+import { applyTidy, contradictionBudget, contradictionCandidates, contradictionPrompt, parseContradictions, planTidy } from "./memory-tidy.ts";
import { createMemoryUpkeep, MAX_PENDING_THREADS, NO_TEXT_ENGINE, type UpkeepBot, type UpkeepEngine } from "./memory-upkeep.ts";
import { closeMessageDb } from "./message-db.ts";
import { aboutMeLine, appendAboutMe, clearForgotten, commitLearned, listLearnedFacts, planLearned, rememberForgotten, removeLearned } from "./profile-learned.ts";
@@ -163,6 +163,25 @@ describe("tidy plan", () => {
{ a: 2, b: 1, keep: "b" },
]);
});
+
+ it("never supersedes a note outside the contradiction prompt", () => {
+ const text = Array.from({ length: 205 }, (_, index) => `- 2026-09-01 · Project ${index} has its own deadline`).join("\n");
+ const candidates = contradictionCandidates(text, TODAY);
+ const prompt = contradictionPrompt(candidates);
+ expect(candidates).toHaveLength(205);
+ expect(prompt).toContain("[199] (2026-09-01) Project 199");
+ expect(prompt).not.toContain("[200]");
+ const pairs = parseContradictions(JSON.stringify({ pairs: [
+ { a: 0, b: 200, keep: "a" },
+ { a: 204, b: 1, keep: "b" },
+ { a: 2, b: 199, keep: "b" },
+ ] }), candidates.length);
+ expect(pairs).toEqual([{ a: 2, b: 199, keep: "b" }]);
+ const next = applyTidy(text, planTidy(text, TODAY, pairs), TODAY).text;
+ expect(next).toContain("- 2026-09-01 · Project 200 has its own deadline");
+ expect(next).toContain("- 2026-09-01 · Project 204 has its own deadline");
+ expect(next).toContain("~~Project 2 has its own deadline~~");
+ });
});
describe("About me, learned on its own", () => {