Skip to content

Commit 84ddffa

Browse files
committed
fix(proposal-a): P1 fix errorKeywords precedence + prevent double-count
P1 (Codex 2nd round): 1. errorKeywords now checked BEFORE usedRecall heuristic. If user explicitly corrects, that overrides usage detection. No importance boost is applied for errorKeywords cases. 2. errorKeywords sets last_confirmed_use_at = Date.now(). This prevents injection path's staleInjected from double-counting in the same turn. Next injection will NOT increment bad_recall_count via staleInjected (since last_confirmed_use_at >= last_injected_at). This fixes: - Used but corrected: no boost, single increment, no staleInjected double-count - Used and confirmed: boost + reset - Silent miss: penalty applies at badCount >= 1, injection handles increment
1 parent 45247f2 commit 84ddffa

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

index.ts

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,42 +3103,32 @@ const memoryLanceDBProPlugin = {
31033103
const meta = parseSmartMetadata(entry.metadata, entry);
31043104
const currentImportance = meta.importance ?? entry.importance ?? 0.5;
31053105

3106-
if (usedRecall) {
3106+
// P1 fix (Codex): check errorKeywords BEFORE usedRecall.
3107+
// If user explicitly corrects, that overrides the heuristic usage detection.
3108+
// Also set last_confirmed_use_at here to prevent injection path's staleInjected
3109+
// from double-counting in the same turn.
3110+
const hasError = containsKeyword(userPromptText, errorKeywords);
3111+
if (hasError) {
3112+
if ((meta.injected_count || 0) >= minRecallCountForPenalty) {
3113+
await store.update(recallId, { importance: Math.max(0.1, currentImportance - penaltyOnError) }, undefined);
3114+
}
3115+
await store.patchMetadata(recallId, { bad_recall_count: (meta.bad_recall_count || 0) + 1, last_confirmed_use_at: Date.now() }, undefined);
3116+
} else if (usedRecall) {
3117+
// Pure positive use: boost importance
31073118
let newImportance = Math.min(1.0, currentImportance + boostOnUse);
31083119
if (containsKeyword(userPromptText, confirmKeywords)) {
31093120
newImportance = Math.min(1.0, newImportance + boostOnConfirm);
31103121
}
31113122
await store.update(recallId, { importance: newImportance }, undefined);
3112-
await store.patchMetadata(
3113-
recallId,
3114-
{ last_confirmed_use_at: Date.now(), bad_recall_count: 0 },
3115-
undefined,
3116-
);
3123+
await store.patchMetadata(recallId, { last_confirmed_use_at: Date.now(), bad_recall_count: 0 }, undefined);
31173124
} else {
31183125
// P1 fix: align scoring penalty threshold with injection increment.
3119-
// The injection path increments on staleInjected (previous turn not confirmed).
3120-
// To avoid double-counting: scoring only increments for explicit errors,
3121-
// and checks >= 1 to sync with injection's first increment.
3126+
// Silent miss: apply penalty if badCount >= 1 (injection path handles increment).
31223127
const badCount = meta.bad_recall_count || 0;
3123-
let newImportance = currentImportance;
3124-
if (containsKeyword(userPromptText, errorKeywords)) {
3125-
// Only increment for explicit user error/correction
3126-
if ((meta.injected_count || 0) >= minRecallCountForPenalty) {
3127-
newImportance = Math.max(0.1, newImportance - penaltyOnError);
3128-
}
3129-
await store.update(recallId, { importance: newImportance }, undefined);
3130-
await store.patchMetadata(recallId, { bad_recall_count: badCount + 1 }, undefined);
3131-
} else if (badCount >= 1) {
3132-
// P1 fix: check >= 1 to match injection path's staleInjected increment.
3133-
// After injection increments (staleInjected), badCount will be 1, so we apply
3134-
// penalty on the second miss rather than waiting for the third.
3135-
if ((meta.injected_count || 0) >= minRecallCountForPenalty) {
3136-
newImportance = Math.max(0.1, newImportance - penaltyOnMiss);
3137-
}
3138-
await store.update(recallId, { importance: newImportance }, undefined);
3139-
// Don't increment here - injection path already increments via staleInjected.
3140-
// This prevents double-counting while still applying penalty.
3128+
if (badCount >= 1 && (meta.injected_count || 0) >= minRecallCountForPenalty) {
3129+
await store.update(recallId, { importance: Math.max(0.1, currentImportance - penaltyOnMiss) }, undefined);
31413130
}
3131+
// No increment here - injection path already increments via staleInjected.
31423132
}
31433133
}
31443134
} catch (err) {

0 commit comments

Comments
 (0)