Skip to content

A self-organizing Obsidian vault that gives AI coding agents persistent memory.

fix: resolve a shared title to every memory it names, never to the memory itself (#376)

Brenno Ferrari4d5bee01117d
diff --git a/.claude/scripts/lib/mcp-server.ts b/.claude/scripts/lib/mcp-server.ts
index 1fdcf79..e0589b0 100644
--- a/.claude/scripts/lib/mcp-server.ts
+++ b/.claude/scripts/lib/mcp-server.ts
@@ -33,7 +33,7 @@ import { callerPlatforms, digestsFrom, resolvableNames, resolvableTargets } from
import { captureNote, describeToolMarkup, toolMarkupRefusal } from "./mcp-capture.ts";
import { semanticMemoryOrder } from "./mcp-memory-bridge.ts";
import { TOOLS } from "./mcp-tools.ts";
-import { recallFrom, readMemories, type MemoryEntry } from "./memory-recall.ts";
+import { recallFrom, readMemories, servedAfterSupersession, type MemoryEntry } from "./memory-recall.ts";
import {
resolvePromotedRef,
auditPromotions,
@@ -43,7 +43,7 @@ import {
import { createMemoryIndex } from "./memory-index.ts";
import { validateMemory, writeMemory, renderMemory, resolveLinks, neutralizeWikilinks } from "./memory-write.ts";
import { findSimilar } from "./memory-similarity.ts";
-import { markSuperseded, resolveSupersedes } from "./memory-supersede.ts";
+import { isServerOwned, markSuperseded, resolveSupersedes } from "./memory-supersede.ts";
import { health } from "./memory-discover.ts";
import { resolveQmdEntry, buildQmdCommand, spawnDetachedQmd } from "./qmd.ts";
import {
@@ -543,7 +543,26 @@ export function createHandlers(deps: ServerDeps): Handlers {
}
const { resolved, dropped } = resolveLinks(args.links, resolvable);
- const supers = resolveSupersedes(args.supersedes, digests);
+ // Only what recall serves this caller (#364). A title can name a memory
+ // scoped to another project, or one recall already withholds; marking it
+ // would withhold it from its own project's callers, whose only replacement
+ // is out of their reach, and naming its file here would show this caller a
+ // memory recall never would. Nor is it counted: a count would say whether
+ // another project holds that title, so a claim with no match in reach is
+ // simply not matched, which is the truth from where the caller stands.
+ const served = servedAfterSupersession(
+ digests.map((d) => ({ rel: d.rel, full: d.full, title: d.title, body: d.body, facets: d })),
+ who,
+ );
+ const supers = resolveSupersedes(
+ args.supersedes,
+ digests.filter((d) => served.has(d.rel)),
+ );
+ // A match the server may not modify (a hand-filed memory) is shown apart,
+ // so a preview never promises a mark the write will refuse.
+ const markable = supers.matched.filter((d) => isServerOwned(d.source));
+ const unmarkable = supers.matched.filter((d) => !isServerOwned(d.source));
+ const named = (m: { title: string; rel: string }) => `${m.title} (${m.rel})`;
if (args.dry_run === true) {
return [
@@ -552,6 +571,8 @@ export function createHandlers(deps: ServerDeps): Handlers {
renderMemory(v.value, resolved),
...(dropped.length ? ["", `Links dropped as unresolvable: ${dropped.join(", ")}`] : []),
...(unlinked.length ? [`Dangling wikilinks were unlinked: ${unlinked.join(", ")}`] : []),
+ ...(markable.length ? [`Would supersede: ${markable.map(named).join("; ")}`] : []),
+ ...(unmarkable.length ? [`Matched but would not be marked (not written by this server): ${unmarkable.map(named).join("; ")}`] : []),
...(supers.unmatched.length ? [`Supersedes not matched: ${supers.unmatched.join(", ")}`] : []),
...(v.warnings.length ? ["", "Warnings:", ...v.warnings.map((w) => `- ${w}`)] : []),
].join("\n");
@@ -563,22 +584,35 @@ export function createHandlers(deps: ServerDeps): Handlers {
// previous parse of a path a collision loop just reused.
memoryIndex.invalidate(written.rel);
+ // The file, not just the title: a title can name several memories (#364),
+ // and every one in reach is marked, so a caller who meant one of two that
+ // share a title by coincidence sees both, rather than one being retired
+ // silently. A match the server may not modify is named with its reason.
const retired: string[] = [];
+ const notMarked: string[] = [];
for (const m of supers.matched) {
- if (markSuperseded(ctx.vaultRoot, m.rel, v.value.title).ok) {
- retired.push(m.title);
+ const r = markSuperseded(ctx.vaultRoot, m.rel, v.value.title);
+ if (r.ok) {
+ retired.push(named(m));
// Rewritten in place, and the new frontmatter is what makes it sink.
memoryIndex.invalidate(m.rel);
- }
+ } else notMarked.push(`${m.title}: ${r.reason}`);
}
const indexed = reindex();
- audit("remember", { rel: written.rel, scope: v.value.scope, projects: v.value.projects, indexed });
+ audit("remember", {
+ rel: written.rel,
+ scope: v.value.scope,
+ projects: v.value.projects,
+ indexed,
+ ...(notMarked.length ? { not_marked: notMarked.length } : {}),
+ });
return [
`Recorded: ${written.rel}`,
`Scope: ${v.value.scope}${v.value.projects.length ? ` → ${v.value.projects.join(", ")}` : ""}`,
...(retired.length ? [`Superseded: ${retired.join("; ")} (kept and back-linked)`] : []),
+ ...(notMarked.length ? [`Matched but not marked: ${notMarked.join("; ")}`] : []),
...(supers.unmatched.length ? [`Supersedes NOT matched: ${supers.unmatched.join(", ")}`] : []),
...(dropped.length ? [`Links dropped as unresolvable: ${dropped.join(", ")}`] : []),
...(unlinked.length ? [`Dangling wikilinks were unlinked: ${unlinked.join(", ")}`] : []),
diff --git a/.claude/scripts/lib/memory-recall.ts b/.claude/scripts/lib/memory-recall.ts
index 0605711..f807093 100644
--- a/.claude/scripts/lib/memory-recall.ts
+++ b/.claude/scripts/lib/memory-recall.ts
@@ -27,7 +27,7 @@ import { readFileSync, readdirSync, statSync, existsSync } from "node:fs";
import { join } from "node:path";
import { MEMORY_ROOT, MEMORY_SOURCE, AGENT_SOURCES } from "./memory-write.ts";
import { parsePromotedMarker, type PromotedRef } from "./memory-promoted.ts";
-import { resolveSupersedes } from "./memory-supersede.ts";
+import { supersedeResolver } from "./memory-supersede.ts";
// Re-exported so a reader can take the marker from the module it reads with,
// while the writer that stamps it stays the one place it is defined.
@@ -302,6 +302,22 @@ export function supersededOutOfReach(
return !servedAfterSupersession(corpus, caller).has(entry.rel);
}
+/**
+ * Whether `a` was provably written before `b`: by the write's session
+ * timestamp where both have one, else by date. A side with neither, or a
+ * same-day pair missing a timestamp, is not provably older, so it is never
+ * ruled out. `session` is UTC and `date` the writer's local day, which across
+ * time zones can run ahead of a later write's, hence the timestamp first.
+ * `rankMemories` orders recency by date, then session; the two agree except
+ * across time zones and where a value is missing, which ranking sorts oldest.
+ */
+function olderThan(a: Facets, b: Facets): boolean {
+ const [ta, tb] = [Date.parse(a.session ?? ""), Date.parse(b.session ?? "")];
+ if (!Number.isNaN(ta) && !Number.isNaN(tb)) return ta < tb;
+ if (!a.date || !b.date) return false;
+ return a.date < b.date;
+}
+
/**
* The rels that survive both filters, resolved together rather than in sequence.
*
@@ -340,10 +356,18 @@ export function servedAfterSupersession(
// nothing and costs a factor of n: each pass becomes O(n²) and the fixpoint
// O(n³). Measured on a worst-case chain, where every pass retires exactly one
// link, that is 12s at 2000 memories against ~30ms hoisted.
+ const resolve = supersedeResolver(corpus);
const replacements = new Map<string, string[]>();
for (const entry of corpus) {
if (entry.facets.superseded_by.length === 0) continue;
- const { matched } = resolveSupersedes(entry.facets.superseded_by, corpus);
+ // A correction that keeps its title makes the claim name the memory
+ // itself, and anything older under that title (#364). Neither replaces
+ // it: the memory itself is always served, so counting it would never
+ // withhold the stale copy, and an older one would let two retired copies
+ // keep each other served.
+ const matched = resolve(entry.facets.superseded_by).matched.filter(
+ (m) => m !== entry && !olderThan(m.facets, entry.facets),
+ );
// Unresolvable claims leave the memory alone, per the rule above, so they
// are never entered here and can never be withheld.
if (matched.length === 0) continue;
diff --git a/.claude/scripts/lib/memory-supersede.ts b/.claude/scripts/lib/memory-supersede.ts
index eb7b9f8..763b911 100644
--- a/.claude/scripts/lib/memory-supersede.ts
+++ b/.claude/scripts/lib/memory-supersede.ts
@@ -143,14 +143,46 @@ export function resolveSupersedes<T extends Titled>(
claims: unknown,
existing: readonly T[],
): { matched: T[]; unmatched: string[] } {
- const matched: T[] = [];
- const unmatched: string[] = [];
- for (const claim of Array.isArray(claims) ? claims : []) {
- const needle = String(claim ?? "").trim().toLowerCase();
- if (!needle) continue;
- const hit = existing.find((e) => String(e.title ?? "").trim().toLowerCase() === needle);
- if (hit) matched.push(hit);
- else unmatched.push(String(claim));
+ // Every memory a claim's title names, not the first: see supersedeResolver.
+ return supersedeResolver(existing)(claims);
+}
+
+/**
+ * `resolveSupersedes` with the title index built once, for a caller resolving
+ * every memory's claims against one corpus: per call, each claim would
+ * otherwise normalise every title in it again.
+ *
+ * Every memory carrying the title, not the first (#364): a correction that
+ * keeps its title is the normal path, so a title can name several, and the
+ * first in listing order is an accident of the listing.
+ */
+export function supersedeResolver<T extends Titled>(
+ existing: readonly T[],
+): (claims: unknown) => { matched: T[]; unmatched: string[] } {
+ const byTitle = new Map<string, T[]>();
+ for (const e of existing) {
+ const key = titleKey(e.title);
+ const group = byTitle.get(key);
+ if (group) group.push(e);
+ else byTitle.set(key, [e]);
}
- return { matched, unmatched };
+ return (claims) => {
+ const matched = new Set<T>();
+ const unmatched: string[] = [];
+ for (const claim of Array.isArray(claims) ? claims : []) {
+ const key = titleKey(claim);
+ if (!key) continue;
+ const hits = byTitle.get(key) ?? [];
+ for (const hit of hits) matched.add(hit);
+ if (hits.length === 0) unmatched.push(String(claim));
+ }
+ return { matched: [...matched], unmatched };
+ };
+}
+
+const titleKey = (s: unknown): string => String(s ?? "").trim().toLowerCase();
+
+/** Whether a memory with this `source` is one `markSuperseded` may modify. */
+export function isServerOwned(source: unknown): boolean {
+ return source === OWNED_BY_SERVER;
}
diff --git a/.claude/scripts/tests/memory-recall.test.ts b/.claude/scripts/tests/memory-recall.test.ts
index fe699ec..838ee5d 100644
--- a/.claude/scripts/tests/memory-recall.test.ts
+++ b/.claude/scripts/tests/memory-recall.test.ts
@@ -535,6 +535,92 @@ describe("a superseded memory reaches only where its successor reaches", () => {
});
});
+/**
+ * A correction that keeps its title (#364). The claim on the old memory names
+ * a title the old memory itself carries, so resolving it by first match could
+ * land on the memory itself, which is always served, and the stale copy was
+ * never withheld. Which way it went depended on listing order.
+ */
+describe("a correction that keeps the corrected memory's title (#364)", () => {
+ const TITLE = "tokens expire after one hour";
+ const dated = (fm: Record<string, unknown>, slug: string = String(fm["date"])): MemoryEntry => ({
+ rel: `memories/${slug} ${TITLE}.md`,
+ full: `/nowhere/${slug}.md`,
+ facets: facetsOf({ source: MEMORY_SOURCE, ...fm }),
+ title: TITLE,
+ body: "b",
+ });
+ const OLD = dated({ scope: "project", projects: ["atlas", "beta"], date: "2026-06-01", superseded_by: [TITLE] });
+ const NEW = dated({ scope: "project", projects: ["atlas"], date: "2026-07-26" });
+ const beta = { project: "beta", platforms: [] };
+ const atlas = { project: "atlas", platforms: [] };
+
+ for (const [order, corpus] of [["old first", [OLD, NEW]], ["correction first", [NEW, OLD]]] as const) {
+ test(`the caller the correction excludes gets neither copy (${order})`, () => {
+ assert.deepEqual(recallFrom(corpus, beta).map((m) => m.rel), []);
+ });
+ test(`the caller it keeps gets the correction first, the old copy sunk (${order})`, () => {
+ assert.deepEqual(recallFrom(corpus, atlas).map((m) => m.rel), [NEW.rel, OLD.rel]);
+ });
+ }
+
+ test("a three-link same-title chain retires back to its head", () => {
+ const a = dated({ scope: "general", date: "2026-06-01", superseded_by: [TITLE] });
+ const b = dated({ scope: "general", date: "2026-07-01", superseded_by: [TITLE] });
+ const c = dated({ scope: "project", projects: ["atlas"], date: "2026-08-01" });
+ for (const corpus of [[a, b, c], [c, b, a], [b, a, c]]) {
+ assert.deepEqual(recallFrom(corpus, beta).map((m) => m.rel), []);
+ const served = recallFrom(corpus, atlas).map((m) => m.rel);
+ assert.equal(served[0], c.rel, "the live correction ranks first");
+ assert.deepEqual([...served].sort(), [a.rel, b.rel, c.rel].sort());
+ }
+ });
+
+ test("a claim whose only match is the memory itself is unresolvable, so the memory stays", () => {
+ const alone = dated({ scope: "general", date: "2026-06-01", superseded_by: [TITLE] });
+ assert.deepEqual(recallFrom([alone], beta).map((m) => m.rel), [alone.rel]);
+ });
+
+ // Within one day, two retired copies would otherwise each count the other as
+ // a replacement and keep each other served; the write's timestamp orders them.
+ test("on the same day, the write's session time decides which copy is newer", () => {
+ const day = (hour: string, fm: Record<string, unknown>, slug: string) =>
+ dated({ date: "2026-07-26", session: `2026-07-26T${hour}:00:00Z`, ...fm }, slug);
+ const a = day("09", { scope: "general", superseded_by: [TITLE] }, "a");
+ const b = day("12", { scope: "general", superseded_by: [TITLE] }, "b");
+ const c = day("17", { scope: "project", projects: ["atlas"] }, "c");
+ assert.deepEqual(recallFrom([a, b, c], beta).map((m) => m.rel), []);
+ assert.deepEqual(recallFrom([c, b, a], beta).map((m) => m.rel), []);
+ });
+
+ test("an undated side is never ruled out as older, so the rule still applies", () => {
+ const undated = dated({ scope: "project", projects: ["atlas"] }, "undated");
+ assert.deepEqual(recallFrom([OLD, undated], beta).map((m) => m.rel), []);
+ });
+
+ // `date` is the writer's local day and `session` its UTC time: across time
+ // zones the local day can run ahead of a later write's, so the timestamp,
+ // where both have one, decides.
+ test("a later write from a time zone whose local day runs behind is still newer", () => {
+ const old = dated({ scope: "general", date: "2026-10-14", session: "2026-10-13T16:00:00Z", superseded_by: [TITLE] }, "tokyo");
+ const fix = dated({ scope: "project", projects: ["atlas"], date: "2026-10-13", session: "2026-10-13T17:00:00Z" }, "seattle");
+ assert.deepEqual(recallFrom([old, fix], beta).map((m) => m.rel), []);
+ });
+
+ // A hand-filed memory can carry a session with an offset; compared as text it
+ // would sort by its local clock, so the timestamps are parsed.
+ test("a session written with a time-zone offset is ordered by the instant it names", () => {
+ const old = dated({ scope: "general", date: "2026-10-14", session: "2026-10-14T01:00:00+09:00", superseded_by: [TITLE] }, "offset");
+ const fix = dated({ scope: "project", projects: ["atlas"], date: "2026-10-13", session: "2026-10-13T17:00:00.000Z" }, "utc");
+ assert.deepEqual(recallFrom([old, fix], beta).map((m) => m.rel), []);
+ });
+
+ test("explain names supersession, not scope, for the withheld old copy", () => {
+ const { withheld } = recallFrom([OLD, NEW], beta, { explain: true });
+ assert.ok(withheld.find((m) => m.rel === OLD.rel)?.why?.startsWith(SUPERSEDED_OUT_OF_REACH));
+ });
+});
+
/**
* A capture the tool refused still has to reach someone.
*
diff --git a/.claude/scripts/tests/memory-supersede-same-title.test.ts b/.claude/scripts/tests/memory-supersede-same-title.test.ts
new file mode 100644
index 0000000..e817027
--- /dev/null
+++ b/.claude/scripts/tests/memory-supersede-same-title.test.ts
@@ -0,0 +1,185 @@
+/**
+ * Supersession under a shared title (#364).
+ *
+ * A correction that keeps its title is the normal path, so a title can name
+ * several memories. Resolving a `supersedes` claim to the first of them marked
+ * whichever the listing put first: a third correction re-marked the memory
+ * already retired and left the live wrong one live. Every memory the title
+ * names is marked, and the reply names each file, so a title shared by
+ * coincidence is visible to the caller rather than retired silently.
+ *
+ * Driven through the real `tools/call` dispatch, as mcp-refusal-audit does.
+ * Every call passes `force: true`: the near-duplicate check is not what these
+ * tests are about.
+ */
+
+import { test, describe } from "node:test";
+import assert from "node:assert/strict";
+import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+
+import { createHandlers } from "../lib/mcp-server.ts";
+import { recall } from "../lib/memory-recall.ts";
+
+import { rmTemp } from "./_helpers.ts";
+
+const TITLE = "tokens expire after one hour";
+const BODY = "A body written for a session that will not have this context, long enough to clear the minimum.";
+
+function harness(vaultRoot: string): { remember: (at: Date, args: Record<string, unknown>) => Promise<string> } {
+ let clock = new Date(2026, 5, 1);
+ const session = {
+ roots: [{ uri: "file:///elsewhere/atlas", name: "atlas" }],
+ identityReady: async () => {},
+ ok: (_id: unknown, r: unknown) => r,
+ error: (_id: unknown, e: unknown) => e,
+ };
+ const handlers = createHandlers({
+ ctx: { vaultRoot, memoryRoot: "memories", qmdIndex: null },
+ policy: { roots: ["brain"], never_expose: [] },
+ session,
+ qmd: () => ({}),
+ audit: () => {},
+ reindex: () => true,
+ now: () => clock,
+ } as never);
+ const remember = async (at: Date, args: Record<string, unknown>): Promise<string> => {
+ clock = at;
+ const r = (await (handlers as never as Record<string, (id: number, p: unknown) => Promise<unknown>>)["tools/call"]!(1, {
+ name: "remember",
+ arguments: { title: TITLE, body: BODY, confidence: "verified", force: true, ...args },
+ })) as { content: { text: string }[] };
+ return r.content[0]!.text;
+ };
+ return { remember };
+}
+
+const recorded = (reply: string): string => /^Recorded: (.+)$/m.exec(reply)?.[1] ?? "";
+
+describe("remember marks every memory a shared title names", () => {
+ test("a third same-title correction retires the live wrong one, and the chain reaches only where its end does", async () => {
+ const dir = mkdtempSync(join(tmpdir(), "sup-chain-"));
+ try {
+ const { remember } = harness(dir);
+ await remember(new Date(2026, 5, 1), { scope: "general" });
+ await remember(new Date(2026, 6, 1), { scope: "general", supersedes: [TITLE] });
+ await remember(new Date(2026, 7, 1), { scope: "project", projects: ["atlas"], supersedes: [TITLE] });
+
+ const live = (project: string) => recall(dir, { project, platforms: [] }).map((m) => m.facets.superseded_by.length);
+ assert.deepEqual(live("beta"), [], "a caller outside the last correction's reach gets no part of the chain");
+ assert.deepEqual(live("atlas"), [0, 1, 1], "the live correction first, both retired copies sunk");
+ } finally {
+ rmTemp(dir);
+ }
+ });
+
+ test("two memories sharing a title by coincidence are both marked, and the reply names each file", async () => {
+ const dir = mkdtempSync(join(tmpdir(), "sup-coincide-"));
+ try {
+ const { remember } = harness(dir);
+ const first = recorded(await remember(new Date(2026, 5, 1), { scope: "general", body: `${BODY} About sessions.` }));
+ const second = recorded(await remember(new Date(2026, 5, 2), { scope: "general", body: `${BODY} About API keys.` }));
+ const reply = await remember(new Date(2026, 6, 1), { scope: "general", supersedes: [TITLE] });
+
+ assert.ok(first && second && first !== second, "two distinct files were written");
+ assert.ok(reply.includes(first), `the reply names ${first}`);
+ assert.ok(reply.includes(second), `the reply names ${second}`);
+ const marked = recall(dir, { project: "atlas", platforms: [] }).filter((m) => m.facets.superseded_by.length > 0);
+ assert.deepEqual(marked.map((m) => m.rel).sort(), [first, second].sort());
+ } finally {
+ rmTemp(dir);
+ }
+ });
+
+ test("a dry run names each file the claim would mark, before anything is marked", async () => {
+ const dir = mkdtempSync(join(tmpdir(), "sup-dry-"));
+ try {
+ const { remember } = harness(dir);
+ const first = recorded(await remember(new Date(2026, 5, 1), { scope: "general", body: `${BODY} About sessions.` }));
+ const second = recorded(await remember(new Date(2026, 5, 2), { scope: "general", body: `${BODY} About API keys.` }));
+ const preview = await remember(new Date(2026, 6, 1), { scope: "general", supersedes: [TITLE], dry_run: true });
+
+ assert.ok(preview.includes(first) && preview.includes(second), "the preview names both files");
+ const marked = recall(dir, { project: "atlas", platforms: [] }).filter((m) => m.facets.superseded_by.length > 0);
+ assert.deepEqual(marked, [], "a dry run marks nothing");
+ } finally {
+ rmTemp(dir);
+ }
+ });
+
+ test("a match the server may not mark is named in the reply, not dropped", async () => {
+ const dir = mkdtempSync(join(tmpdir(), "sup-refused-"));
+ try {
+ const { remember } = harness(dir);
+ const handFiled = recorded(await remember(new Date(2026, 5, 1), { scope: "general" }));
+ const full = join(dir, handFiled);
+ writeFileSync(full, readFileSync(full, "utf8").replace(/^source: .*$/m, "source: hand-filed"));
+ const reply = await remember(new Date(2026, 6, 1), { scope: "general", supersedes: [TITLE] });
+
+ assert.match(reply, /not marked/i);
+ assert.ok(reply.includes(handFiled), `the reply names ${handFiled}`);
+ } finally {
+ rmTemp(dir);
+ }
+ });
+
+ // A correction reaches only what its writer can see. Marking another
+ // project's memory would withhold it from that project's own callers, whose
+ // only replacement is out of their reach, and naming its file would show this
+ // caller a memory recall never would.
+ test("a match the caller cannot see is left alone, and its claim reads as not matched", async () => {
+ const dir = mkdtempSync(join(tmpdir(), "sup-unseen-"));
+ try {
+ const { remember } = harness(dir);
+ const theirs = recorded(await remember(new Date(2026, 5, 1), { scope: "general" }));
+ const full = join(dir, theirs);
+ writeFileSync(full, readFileSync(full, "utf8").replace(/^scope: .*$/m, "scope: project").replace(/^projects: .*$/m, 'projects: ["harbor"]'));
+ const reply = await remember(new Date(2026, 6, 1), { scope: "general", supersedes: [TITLE] });
+
+ assert.ok(!reply.includes(theirs), "the reply does not name a memory outside the caller's reach");
+ assert.match(reply, /Supersedes NOT matched: tokens expire after one hour/);
+ assert.doesNotMatch(reply, /outside your reach/i, "nothing says another project holds the title");
+ const harbor = recall(dir, { project: "harbor", platforms: [] });
+ assert.deepEqual(harbor.find((m) => m.rel === theirs)?.facets.superseded_by, [], "harbor's memory is not marked");
+ } finally {
+ rmTemp(dir);
+ }
+ });
+
+ test("a dry run keeps a match the server may not modify apart from what it would mark", async () => {
+ const dir = mkdtempSync(join(tmpdir(), "sup-dry-hand-"));
+ try {
+ const { remember } = harness(dir);
+ const handFiled = recorded(await remember(new Date(2026, 5, 1), { scope: "general" }));
+ const full = join(dir, handFiled);
+ writeFileSync(full, readFileSync(full, "utf8").replace(/^source: .*$/m, "source: hand-filed"));
+ const preview = await remember(new Date(2026, 6, 1), { scope: "general", supersedes: [TITLE], dry_run: true });
+
+ assert.doesNotMatch(preview, /Would supersede/, "no mark is promised that the write would refuse");
+ assert.match(preview, /would not be marked.*tokens expire after one hour/);
+ } finally {
+ rmTemp(dir);
+ }
+ });
+
+ test("a memory recall already withholds from the caller is not named or marked either", async () => {
+ const dir = mkdtempSync(join(tmpdir(), "sup-withheld-"));
+ try {
+ const { remember } = harness(dir);
+ // Withheld from atlas: its correction is scoped to harbor, out of atlas's reach.
+ const withheld = recorded(await remember(new Date(2026, 5, 1), { scope: "general" }));
+ const harborFix = recorded(await remember(new Date(2026, 5, 2), { scope: "general", title: "tokens expire after one hour (harbor)" }));
+ const fixFull = join(dir, harborFix);
+ writeFileSync(fixFull, readFileSync(fixFull, "utf8").replace(/^scope: .*$/m, "scope: project").replace(/^projects: .*$/m, 'projects: ["harbor"]'));
+ const full = join(dir, withheld);
+ writeFileSync(full, readFileSync(full, "utf8").replace(/^scope: general$/m, 'scope: general\nsuperseded_by: ["tokens expire after one hour (harbor)"]'));
+
+ const reply = await remember(new Date(2026, 6, 1), { scope: "general", supersedes: [TITLE] });
+ assert.ok(!reply.includes(withheld), "the reply does not name a memory recall withholds from the caller");
+ assert.match(reply, /Supersedes NOT matched: tokens expire after one hour/);
+ } finally {
+ rmTemp(dir);
+ }
+ });
+});
diff --git a/.claude/scripts/tests/memory-supersede.test.ts b/.claude/scripts/tests/memory-supersede.test.ts
index 92f55f1..1fa92f5 100644
--- a/.claude/scripts/tests/memory-supersede.test.ts
+++ b/.claude/scripts/tests/memory-supersede.test.ts
@@ -142,6 +142,12 @@ describe("resolveSupersedes", () => {
assert.deepEqual(resolveSupersedes(["Ghost"], existing).unmatched, ["Ghost"]);
});
+ test("a claim resolves to every memory carrying the title, not the first (#364)", () => {
+ const shared = [...existing, { rel: "c.md", title: "the old lesson" }];
+ assert.deepEqual(resolveSupersedes(["The Old Lesson"], shared).matched.map((m) => m.rel), ["a.md", "c.md"]);
+ assert.deepEqual(resolveSupersedes([" the old lesson "], shared).matched.map((m) => m.rel), ["a.md", "c.md"]);
+ });
+
test("empty and malformed claims are ignored safely", () => {
assert.deepEqual(resolveSupersedes(null, existing).matched, []);
assert.deepEqual(resolveSupersedes(["", " "], existing).matched, []);