Skip to content

Commit bb84b3e

Browse files
fix(memory): distinguish off-task feedback in compatible history entries
1 parent 0d2984d commit bb84b3e

5 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎apps/server/src/project/knowledge/ProjectKnowledge.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3481,6 +3481,10 @@ it.effect("records every lifecycle event in order and erases bodies when forgott
34813481
{ ...existing(helpful, "history-down"), action: "feedback", helpful: false },
34823482
{ kind: "user" },
34833483
);
3484+
const offTask = yield* knowledge.mutate(
3485+
{ ...existing(unhelpful, "history-off-task"), action: "feedback", helpful: "irrelevant" },
3486+
agent,
3487+
);
34843488
const detail = yield* knowledge.readFact({ projectId, factId: created.id });
34853489
assert.deepEqual(
34863490
detail.history.map((entry) => [entry.event, entry.revision, entry.helpful]),
@@ -3489,8 +3493,11 @@ it.effect("records every lifecycle event in order and erases bodies when forgott
34893493
["edited", 2, null],
34903494
["feedback", 3, true],
34913495
["feedback", 4, false],
3496+
["feedback", 5, false],
34923497
],
34933498
);
3499+
assert.equal(detail.history.at(-1)?.feedbackScope, "task");
3500+
assert.equal(detail.history.at(-1)?.reason, "Unrelated to this task.");
34943501
assert.deepEqual(detail.history[0]?.actor, agent);
34953502
assert.equal(detail.history[1]?.content, "Cache keys include tenant and region IDs.");
34963503
assert.match(detail.history[1]?.contentDigest ?? "", /^[a-f0-9]{64}$/);
@@ -3500,12 +3507,13 @@ it.effect("records every lifecycle event in order and erases bodies when forgott
35003507
[
35013508
[0.5, 0.55],
35023509
[0.55, unhelpful.trust],
3510+
[unhelpful.trust, offTask.trust],
35033511
],
35043512
);
35053513
assert.isFalse(detail.historyTruncated);
35063514

35073515
yield* knowledge.mutate(
3508-
{ ...existing(unhelpful, "history-forget"), action: "forget" },
3516+
{ ...existing(offTask, "history-forget"), action: "forget" },
35093517
{ kind: "user" },
35103518
);
35113519
const forgotten = yield* knowledge.readFact({ projectId, factId: created.id });

‎apps/server/src/project/knowledge/persistence.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,13 @@ export const makeStore = Effect.gen(function* () {
525525
? "edited"
526526
: event,
527527
...(event === "curated" || event === "restored" ? { memoryAction: event } : {}),
528-
helpful: row.helpful === null ? null : row.helpful !== 0,
529528
...(reason === null ? {} : { reason }),
529+
// Older clients label a feedback event with helpful=null as a positive vote.
530+
...(event === "feedback"
531+
? row.helpful === null
532+
? { helpful: false, feedbackScope: "task", reason: "Unrelated to this task." }
533+
: { helpful: row.helpful !== 0, feedbackScope: "fact" }
534+
: { helpful: null }),
530535
}))
531536
.toReversed();
532537
});

‎packages/client-runtime/src/projectKnowledge/index.test.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ it("traces trust from before the first recorded event through each feedback", ()
136136
});
137137

138138
it("labels memory actions carried by legacy-compatible history events", () => {
139-
expect(projectFactHistoryLabel(historyEntry(2, "feedback", 0.5, 0.5))).toBe(
140-
"Unrelated to the task",
141-
);
142139
const edited = historyEntry(2, "edited", null, 0.5);
143140
expect(projectFactHistoryLabel(edited)).toBe("Edited to revision 2");
144141
expect(projectFactHistoryLabel({ ...edited, memoryAction: "curated" })).toBe(

‎packages/client-runtime/src/projectKnowledge/index.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ export function projectFactHistoryLabel(entry: ProjectFactHistoryEntry): string
251251
case "forgotten":
252252
return entry.actor.kind === "curator" ? "Removed automatically" : "Forgotten";
253253
case "feedback":
254-
if (entry.helpful === null) return "Unrelated to the task";
255-
return entry.helpful ? "Marked helpful" : "Marked unhelpful";
254+
return entry.helpful === false ? "Marked unhelpful" : "Marked helpful";
256255
case "superseded":
257256
return "Superseded";
258257
}

‎packages/contracts/src/projectKnowledge.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ export const ProjectFactHistoryEntry = Schema.Struct({
268268
trustBefore: Schema.NullOr(Schema.Number),
269269
trustAfter: Schema.Number,
270270
helpful: Schema.NullOr(Schema.Boolean),
271+
feedbackScope: Schema.optionalKey(Schema.Literals(["fact", "task"])),
271272
// The replacement for "superseded"; the replaced fact for a superseding "created".
272273
relatedFactId: Schema.NullOr(ProjectFactId),
273274
reason: Schema.optionalKey(Schema.String),

0 commit comments

Comments
 (0)