Skip to content

fix(memory): keep one entry when a fact is remembered again - #235

Open
chuiwenwei wants to merge 1 commit into
CopilotKit:mainfrom
chuiwenwei:fix/memory-repeat-fact
Open

chuiwenwei wants to merge 1 commit into
CopilotKit:mainfrom
chuiwenwei:fix/memory-repeat-fact

Conversation

@chuiwenwei

Copy link
Copy Markdown

What changed

remember_fact built its row id from the conversation turn (requestKey includes the thread id and latest message id). Confirming the same preference in a later turn therefore inserted a second row with identical text, and every duplicate was sent back to the model in later task prompts.

The tool now delegates to AgentService.rememberFact. It trims the fact, reuses a matching row (including rows saved under the old id scheme), and otherwise derives the id from the text alone, so insertIfAbsent keeps the first row, source and createdAt even when two turns race.

Verification

  • pnpm lint
  • pnpm typecheck
  • pnpm --dir apps/worker typecheck
  • pnpm build:server
  • pnpm test — 527 passing

New tests/memory-dedupe.test.ts covers: a fact repeated in a later turn, a legacy row with the old id, two distinct facts, and blank text.

Integration limits

None. Server-side state only; no provider credentials or platform checks are involved. Existing duplicate rows are not deleted, but a new confirmation with that text reuses one instead of adding another.

remember_fact derived the row id from the thread and message, so confirming the
same fact in a later turn inserted a second row with the same text. Derive the
id from the trimmed text instead, and reuse a matching row saved under an older
id so the first repeat after an upgrade does not add a copy either.

insertIfAbsent keeps the original row, its source and its createdAt when two
turns race.

Adds a regression test for repeated, legacy, distinct and blank facts.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant