fix(agent): stop reporting a repeated style note as saved (P1.5)
The pattern write-back pushed a style note into its "saved" list even when the memory store answered 'unchanged', so the chat route announced "Auto-saved 1 memory" on every repeat of the same style signal. The legacy code checked for the note before writing; the contract port lost that. A style note that already exists is now neither written nor reported. Other write-back saves keep reporting repeats, as before the port. Not logged in upstream-fixes.md: the defect came with the P1.5 port and does not exist in the commercial product.
This commit is contained in:
@@ -148,6 +148,8 @@ export async function runPatternWriteBack(
|
||||
// default to 'agent_inferred'. Genuinely user-authored memories
|
||||
// (preferences, corrections) pass 'user_stated' explicitly.
|
||||
source: MemorySource = 'agent_inferred',
|
||||
// Style notes are written once; seeing the same signal again is not a save.
|
||||
reportRepeat = true,
|
||||
): Promise<MemoryRecord | null> => {
|
||||
if (evaluateExternalMemoryIngress({ content }).action !== 'allow') return null;
|
||||
|
||||
@@ -177,7 +179,9 @@ export async function runPatternWriteBack(
|
||||
...(opts?.sessionId && { sessionId: opts.sessionId }),
|
||||
...(opts?.traceId && { metadata: { trace_id: opts.traceId } }),
|
||||
});
|
||||
saved.push(content.slice(0, DEDUP_SLICE_LENGTH));
|
||||
if (reportRepeat || change?.event === 'added') {
|
||||
saved.push(content.slice(0, DEDUP_SLICE_LENGTH));
|
||||
}
|
||||
return change?.record ?? null;
|
||||
};
|
||||
|
||||
@@ -210,8 +214,9 @@ export async function runPatternWriteBack(
|
||||
if (saved.length === 0 && userMsg.length > MIN_CONTENT_LENGTH) {
|
||||
for (const { pattern, note } of STYLE_SIGNALS) {
|
||||
if (pattern.test(userMsg)) {
|
||||
// The store does not write identical text twice in one scope.
|
||||
await save(note, 'normal', 'preference', 'personal');
|
||||
// The store does not write identical text twice in one scope, and a
|
||||
// note that already exists is not reported as saved again.
|
||||
await save(note, 'normal', 'preference', 'personal', 'agent_inferred', false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user