Skip to content

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

fix: verify single-line memory moves against live topic entries

Afloat82fffe0a4268
diff --git a/server/memory-upkeep.test.ts b/server/memory-upkeep.test.ts
index 12ef1892fc..04009b36dd 100644
--- a/server/memory-upkeep.test.ts
+++ b/server/memory-upkeep.test.ts
@@ -572,9 +572,11 @@ describe("the upkeep loop", () => {
expect(readMemoryTopic(BOT.id, "project.md")).toBe(topic);
});
- it.each(["2026-09-07", "2026-09-26"])("keeps a permanent entry when its topic copy expires on %s", async (until) => {
+ it.each(["2026-09-07", "2026-09-26"].flatMap((until) => [
+ { until, details: " deploy --current\n" },
+ { until, details: "" },
+ ]))("keeps a permanent entry when its topic copy expires on $until (details: $details)", async ({ until, details }) => {
ensureWorkspace(BOT.id);
- const details = " deploy --current\n";
const source = `- 2026-09-25 · Deployment steps\n${details}`;
writeMemoryFile(BOT.id, source);
writeMemoryTopic(BOT.id, "project.md", `- 2026-09-01 · Deployment steps · until ${until}\n${details}`);
@@ -585,6 +587,17 @@ describe("the upkeep loop", () => {
expect(memory()).toBe(source);
});
+ it("retains both code blocks when their identical headings hide meaningful whitespace differences", async () => {
+ const source = "- 2026-09-25 · Cedar command\n ```sh\n printf 'a b'\n ```\n";
+ const topic = "- 2026-09-20 · Cedar command\n ```sh\n printf 'a b'\n ```\n";
+ writeMemoryFile(BOT.id, source);
+ writeMemoryTopic(BOT.id, "cedar.md", topic);
+ organizeAnswer = '{"moves":[{"i":0,"topic":"cedar"}]}';
+ expect((await upkeep().tidy(BOT.id)).organized ?? 0).toBe(0);
+ expect(memory()).toBe(source);
+ expect(readMemoryTopic(BOT.id, "cedar.md")).toBe(topic);
+ });
+
it("moves detail the bot wrote itself out of MEMORY.md into topics, keeping core facts", async () => {
ensureWorkspace(BOT.id);
writeMemoryFile(BOT.id, [
diff --git a/server/memory-upkeep.ts b/server/memory-upkeep.ts
index e513bd5f22..b55ee843ae 100644
--- a/server/memory-upkeep.ts
+++ b/server/memory-upkeep.ts
@@ -596,11 +596,16 @@ export function createMemoryUpkeep(deps: UpkeepDeps): MemoryUpkeep {
}
existing.set(name.toLowerCase(), name);
const savedLines = after.split("\n");
- const savedEntries = parseMemoryEntries(after).filter((entry) => !entry.struck && !isExpired(entry, today));
+ const parsedEntries = parseMemoryEntries(after);
+ const datedLines = new Set<number>();
+ for (const saved of parsedEntries) for (let line = saved.line; line < saved.end; line++) datedLines.add(line);
+ const undated = new Set(savedLines.filter((_, line) => !datedLines.has(line)).map(lineFactIdentity));
+ const savedEntries = parsedEntries.filter((entry) => !entry.struck && !isExpired(entry, today));
for (const { topic, entry } of moves) {
if (topic !== wanted) continue;
const details = sourceLines.slice(entry.line + 1, entry.end).join("\n");
- if (entry.end === entry.line + 1 || savedEntries.some((saved) =>
+ const plainNote = entry.end === entry.line + 1 && entry.until === null && undated.has(factIdentity(entry.body));
+ if (plainNote || savedEntries.some((saved) =>
factIdentity(saved.body) === factIdentity(entry.body)
&& saved.until === entry.until
&& savedLines.slice(saved.line + 1, saved.end).join("\n") === details)) {