Skip to content

fix(memory): harden memory followups#1796

Merged
yyhhyyyyyy merged 3 commits into
devfrom
fix/pr1794-memory-hardening-followup
Jun 22, 2026
Merged

fix(memory): harden memory followups#1796
yyhhyyyyyy merged 3 commits into
devfrom
fix/pr1794-memory-hardening-followup

Conversation

@zhangmo8

@zhangmo8 zhangmo8 commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • make memory extraction parse failures retryable and update parser tests for the union result
  • harden memory embedding/reindex, vector cleanup, FTS search/rebuild, and encrypted DB schema copying
  • improve memory settings UI error/search/delete handling and advanced configuration hints

Validation

  • pnpm run format passed
  • pnpm run i18n passed
  • pnpm run lint passed
  • pnpm run typecheck passed
  • pnpm test was started but stopped per request after memoryPresenter.test.ts surfaced failures/timeouts

Note: local environment used Node v26.0.0 while package.json expects >=24.14.1 <25, so pnpm emitted engine warnings.

Summary by CodeRabbit

Release Notes

  • New Features

    • Collapsible “Advanced” panel for memory configuration settings
    • Permanent memory deletion now uses a confirmation dialog
    • Memory manager now shows explicit search failure messages
    • Multi-word memory search now requires all terms to match
  • Bug Fixes

    • Memory extraction now omits assistant internal reasoning text
    • Prevented stale vector writes during memory reindex/reset flows
    • Improved refresh/load handling to avoid outdated overwrites
    • Improved FTS/LIKE search behavior for more consistent results
  • Documentation

    • Added updated memory hardening specification and implementation plan

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0deaa54a-57bd-4575-a35c-bdf1fe85c250

📥 Commits

Reviewing files that changed from the base of the PR and between 521b5a4 and 71e4c0f.

📒 Files selected for processing (25)
  • docs/issues/pr1794-memory-hardening/plan.md
  • docs/issues/pr1794-memory-hardening/spec.md
  • docs/issues/pr1794-memory-hardening/tasks.md
  • src/main/routes/index.ts
  • src/renderer/settings/components/MemoryManagerPanel.vue
  • src/renderer/src/i18n/da-DK/settings.json
  • src/renderer/src/i18n/de-DE/settings.json
  • src/renderer/src/i18n/es-ES/settings.json
  • src/renderer/src/i18n/fa-IR/settings.json
  • src/renderer/src/i18n/fr-FR/settings.json
  • src/renderer/src/i18n/he-IL/settings.json
  • src/renderer/src/i18n/id-ID/settings.json
  • src/renderer/src/i18n/it-IT/settings.json
  • src/renderer/src/i18n/ja-JP/settings.json
  • src/renderer/src/i18n/ko-KR/settings.json
  • src/renderer/src/i18n/ms-MY/settings.json
  • src/renderer/src/i18n/pl-PL/settings.json
  • src/renderer/src/i18n/pt-BR/settings.json
  • src/renderer/src/i18n/ru-RU/settings.json
  • src/renderer/src/i18n/tr-TR/settings.json
  • src/renderer/src/i18n/vi-VN/settings.json
  • src/renderer/src/i18n/zh-CN/settings.json
  • src/renderer/src/i18n/zh-HK/settings.json
  • src/renderer/src/i18n/zh-TW/settings.json
  • test/main/routes/memoryDto.test.ts

📝 Walkthrough

Walkthrough

PR1794 hardens the memory subsystem end-to-end: parseMemoryCandidates returns a discriminated union instead of silently returning []; the memory presenter adds embedding fingerprint guards and reindex drain-wait; FTS tables gain tokenizer/version-tracked rebuild logic with AND-tokenized search; the DB security presenter now copies indexes, triggers, and views during migration; renderer components add error recovery, stale-refresh guards, delete confirmation dialogs, and a collapsible advanced panel; 18 locale files receive matching i18n strings.

Changes

Memory Hardening (Core, DB, UI, i18n)

Layer / File(s) Summary
Extraction parsing discriminated union and plain-text span filter
src/main/presenter/memoryPresenter/extraction.ts, src/main/presenter/agentRuntimePresenter/index.ts, src/main/routes/index.ts, src/main/presenter/memoryPresenter/index.ts, test/main/presenter/memoryExtraction.test.ts, test/main/routes/memoryDto.test.ts
parseMemoryCandidates now returns { ok, candidates } or { ok: false, reason } instead of [] on failure; agentRuntimePresenter and formatMemorySourceRecordContent filter array content to type=content only (drops reasoning fields); extractAndStore propagates the failure result; tests updated to match all new contract shapes.
Embedding fingerprint guards, reindex drain wait, and vector delete helper
src/main/presenter/memoryPresenter/index.ts
drainPendingEmbeddings compares embedding model fingerprint before and after writing vectors and discards stale results; runReindex awaits any in-flight drain before resetting the store; restoreMemory/forgetMemory gate on canWriteAgentMemory; a new deleteVectorsForMemoryIds helper centralizes locked per-agent vector deletion.
SQLite/FTS lifecycle hardening
src/main/presenter/sqlitePresenter/tables/agentMemory.ts, src/main/presenter/sqlitePresenter/tables/deepchatTapeSearchProjection.ts, src/main/presenter/sqlitePresenter/index.ts
AgentMemoryTable tracks FTS tokenizer/version in agent_memory_fts_meta and conditionally drops/rebuilds the FTS index; multi-word queries are tokenized for AND semantics in both FTS and LIKE paths. deepchatTapeSearchProjection links FTS rows via projection.rowid and guards all meta-table operations on table-existence checks. SQLitePresenter seeds schema_versions for brand-new databases and removes the stale FTS meta delete from clearNewAgentData.
DatabaseSecurityPresenter: copy indexes, triggers, and views
src/main/presenter/databaseSecurityPresenter/index.ts
copySchemaAndData now calls copySchemaObjects after table data copy; listMigratableSchemaObjects queries sqlite_master and filters out FTS maintenance objects and virtual-table-associated objects; qualifyCreateSchemaObjectSql rewrites CREATE INDEX/TRIGGER/VIEW SQL for the migration target schema.
Renderer UI: error recovery, stale-refresh guard, delete confirmation, advanced panel
src/renderer/settings/components/MemorySettings.vue, src/renderer/settings/components/MemoryManagerPanel.vue, src/renderer/settings/components/MemoryConfigPanel.vue
MemorySettings adds a loadError ref and reload() helper with an error display and reset button. MemoryManagerPanel adds a refreshRequestId staleness guard, searchError display, AlertDialog delete confirmation, and post-delete refresh(). MemoryConfigPanel wraps advanced settings in a collapsible panel driven by advancedOpen.
i18n: memory manager and advanced config strings (18 locales)
src/renderer/src/i18n/*/settings.json
All 18 locale files receive new memoryManager strings (searchFailed, deletePermanent, deleteConfirmTitle/Body) and new memory.config advanced settings strings (advancedTitle/Hint, inheritedHint, topKHint, rrfKHint, similarityThresholdHint, weightHint).
Spec, plan, and task checklist
docs/issues/pr1794-memory-hardening/*
Adds the PR1794 memory hardening spec, implementation plan, and completed/pending task checklist.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • ThinkInAIXYZ/deepchat#1770: This PR directly hardens the agent-memory implementation added in #1770, modifying parseMemoryCandidates contract, embedding drain logic, and FTS lifecycle.

Poem

🐇 Hoppity-hop through the memory lane,
No stale vectors shall muddy the brain!
FTS rebuilt when tokenizers shift,
Each parse now returns an ok: true gift.
Delete with a dialog, search errors shown clear—
The rabbit has hardened what memory holds dear! 🧠✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix(memory): harden memory followups' is somewhat vague and uses the term 'followups' without clear context about what specific hardening improvements are being implemented. Consider a more specific title that describes the main hardening focus, such as 'fix(memory): harden memory extraction and FTS operations' or 'fix(memory): improve memory robustness with error handling and schema safety'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pr1794-memory-hardening-followup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zhangmo8 zhangmo8 marked this pull request as draft June 22, 2026 03:08

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 19

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/renderer/src/i18n/da-DK/settings.json`:
- Around line 2293-2297: Replace the English language values for the memory
management keys in the Danish locale file with proper Danish translations. The
keys searchFailed, deletePermanent, deleteConfirmTitle, deleteConfirmBody, and
the advanced hint keys at lines 2429-2436 currently contain English text but
should have Danish translations to maintain consistent language in the Danish
UI. Translate each of these string values from English to Danish to provide a
complete localized experience for Danish users.

In `@src/renderer/src/i18n/de-DE/settings.json`:
- Around line 224-228: The new memory-related keys searchFailed,
deletePermanent, deleteConfirmTitle, and deleteConfirmBody in the
de-DE/settings.json localization file are still in English and need to be
translated to German. Translate each of these values to their German equivalents
to ensure German users see consistent language throughout the interface. Also
apply the same translations to the additional range mentioned at lines 2420-2427
for any similar untranslated keys.

In `@src/renderer/src/i18n/es-ES/settings.json`:
- Around line 224-228: The Spanish translation file es-ES/settings.json contains
four untranslated keys that are still in English: "searchFailed",
"deletePermanent", "deleteConfirmTitle", and "deleteConfirmBody". Translate each
of these key values from English to Spanish to maintain consistency with the
rest of the Spanish UI localization. Ensure the translations are accurate and
follow the same style and tone as the existing Spanish translations in the file,
and also apply the same translation fixes to the other affected ranges mentioned
(lines 2420-2427).

In `@src/renderer/src/i18n/fa-IR/settings.json`:
- Around line 2293-2297: The fa-IR language file contains English text values
for newly added memory management keys (searchFailed, deletePermanent,
deleteConfirmTitle, deleteConfirmBody) and similar keys in the 2429-2436 range,
which should be translated to Persian. Locate each of these English string
values in the fa-IR settings.json file and replace them with their appropriate
Persian translations to maintain UI consistency and provide proper localization
for Persian-speaking users.

In `@src/renderer/src/i18n/fr-FR/settings.json`:
- Around line 2293-2297: The French localization file fr-FR/settings.json
contains new memory-related string keys that are still in English instead of
French. Translate the values for the keys searchFailed, deletePermanent,
deleteConfirmTitle, and deleteConfirmBody from English to French. Additionally,
translate the corresponding memory configuration strings in the range referenced
as applying to lines 2429-2436. Keep all key names unchanged, only translate the
string values to maintain locale consistency for the French language file.

In `@src/renderer/src/i18n/he-IL/settings.json`:
- Around line 2294-2297: The memory-related string keys searchFailed,
deletePermanent, deleteConfirmTitle, and deleteConfirmBody in the Hebrew locale
file are still in English, causing mixed-language UI for Hebrew users. Translate
these four string values to Hebrew by replacing the English text with
appropriate Hebrew translations. Apply the same Hebrew translations to the
duplicate keys mentioned in the additional range at lines 2430-2436 to ensure
consistent localization throughout the memory search/delete dialogs and advanced
settings.

In `@src/renderer/src/i18n/id-ID/settings.json`:
- Around line 225-228: The new strings added to the Indonesian locale file
(searchFailed, deletePermanent, deleteConfirmTitle, deleteConfirmBody) and the
additional entries mentioned at lines 2421-2427 are currently left in English.
Translate all these string values to Indonesian to maintain consistent
localization and avoid mixing languages in the user interface. Update each
English value with its proper Indonesian translation while keeping the key names
unchanged.

In `@src/renderer/src/i18n/it-IT/settings.json`:
- Around line 225-228: The Italian translation file it-IT/settings.json contains
English text for the memory-related strings searchFailed, deletePermanent,
deleteConfirmTitle, and deleteConfirmBody. Replace these English values with
their proper Italian translations to ensure the Italian UI displays Italian text
instead of English fallbacks. Also check and translate any similar untranslated
English strings in the file around lines 2421-2427 that are mentioned as having
the same issue.

In `@src/renderer/src/i18n/ja-JP/settings.json`:
- Around line 2294-2297: The ja-JP/settings.json file contains English strings
for newly added keys (searchFailed, deletePermanent, deleteConfirmTitle,
deleteConfirmBody and additional entries mentioned in the comment) that should
be localized to Japanese. Translate all these English strings to their
appropriate Japanese equivalents to ensure the Japanese localization is complete
and consistent. Review all the mentioned sections to identify and replace each
English string with its Japanese translation.

In `@src/renderer/src/i18n/ko-KR/settings.json`:
- Around line 2294-2297: The Korean translation file (ko-KR/settings.json)
contains English text for the newly added keys searchFailed, deletePermanent,
deleteConfirmTitle, and deleteConfirmBody (around lines 2294-2297), which
creates inconsistent mixed-language content on Korean settings screens.
Translate these English string values into proper Korean equivalents. Also apply
the same Korean translations to the related keys mentioned at lines 2430-2436
that have the same localization issue.

In `@src/renderer/src/i18n/ms-MY/settings.json`:
- Around line 225-228: The strings "searchFailed", "deletePermanent",
"deleteConfirmTitle", and "deleteConfirmBody" in the ms-MY locale file are
currently in English and need to be translated to Malay to provide consistent
language in the Malay UI. Replace the English values with their Malay
translations for all four of these keys. Additionally, ensure the same
localization is applied to the corresponding strings mentioned at lines
2421-2427 as indicated in the comment.

In `@src/renderer/src/i18n/pl-PL/settings.json`:
- Around line 225-228: The Polish locale file (pl-PL/settings.json) contains
English text for new memory-related keys instead of Polish translations.
Translate the values for the keys searchFailed, deletePermanent,
deleteConfirmTitle, and deleteConfirmBody from English to Polish. Additionally,
check lines 2421-2427 mentioned in the comment for any other English text that
needs Polish translation to ensure the entire Polish locale file is complete and
consistent.

In `@src/renderer/src/i18n/pt-BR/settings.json`:
- Around line 2293-2297: The pt-BR settings file contains newly added keys with
English values instead of Brazilian Portuguese translations. Locate and
translate the following keys to Portuguese: searchFailed, deletePermanent,
deleteConfirmTitle, deleteConfirmBody, and the additional keys mentioned in the
range 2429-2436. Replace each English string value with an appropriate Brazilian
Portuguese translation to ensure consistent localization for Portuguese-speaking
users.

In `@src/renderer/src/i18n/ru-RU/settings.json`:
- Around line 2293-2297: The ru-RU localization file contains new keys with
English values instead of Russian translations, creating mixed-language UI. For
the keys searchFailed, deletePermanent, deleteConfirmTitle, and
deleteConfirmBody in the settings.json file, replace the English text values
with proper Russian translations. Also check the additional ranges mentioned
(lines 2429-2436) for similar untranslated English strings and provide Russian
translations for those keys as well.

In `@src/renderer/src/i18n/tr-TR/settings.json`:
- Around line 225-228: The newly added memory-related strings in the Turkish
locale file (tr-TR) are still in English instead of being translated. Translate
the following keys to Turkish: "searchFailed", "deletePermanent",
"deleteConfirmTitle", "deleteConfirmBody", and the advanced memory hint strings
(which are also referenced in lines 2421-2427). Replace the English values with
appropriate Turkish translations for each of these keys to ensure the UI
displays consistently in Turkish for users of this locale.

In `@src/renderer/src/i18n/vi-VN/settings.json`:
- Around line 225-228: The new memory-manager and advanced-config translation
keys including searchFailed, deletePermanent, deleteConfirmTitle,
deleteConfirmBody (lines 225-228) and additional keys at lines 2421-2427 are
still in English rather than Vietnamese, causing inconsistent language
presentation. Translate all these English string values to their Vietnamese
equivalents to maintain consistent language throughout the vi-VN settings file.
Ensure the translations accurately convey the original meaning while using
appropriate Vietnamese phrasing.

In `@src/renderer/src/i18n/zh-CN/settings.json`:
- Around line 222-225: The Chinese locale file settings.json contains English
strings for newly added memory feature keys instead of Chinese translations.
Locate and replace the English values for the keys searchFailed,
deletePermanent, deleteConfirmTitle, and deleteConfirmBody (appearing at lines
222-225 and lines 2421-2427) with their appropriate Chinese translations to
ensure consistent localization in the zh-CN locale file.

In `@src/renderer/src/i18n/zh-HK/settings.json`:
- Around line 2294-2297: The zh-HK locale file contains English text for the
keys searchFailed, deletePermanent, deleteConfirmTitle, and deleteConfirmBody
instead of Hong Kong Chinese translations. Replace all English string values for
these keys with appropriate Traditional Chinese translations suitable for Hong
Kong locale. Ensure all four keys are translated consistently with the rest of
the Hong Kong Chinese locale file to maintain a consistent user experience.

In `@src/renderer/src/i18n/zh-TW/settings.json`:
- Around line 2294-2297: The memory-related strings in the zh-TW locale file
(searchFailed, deletePermanent, deleteConfirmTitle, and deleteConfirmBody around
line 2294, and additional strings around lines 2430-2436) are still in English
instead of being translated to Traditional Chinese. Translate these English
values to their appropriate Traditional Chinese equivalents to maintain
consistent localization throughout the file and prevent mixed-language text from
appearing in the user interface for Taiwanese users.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a417a972-2951-4824-ab96-278a373e733c

📥 Commits

Reviewing files that changed from the base of the PR and between a468ae6 and 521b5a4.

📒 Files selected for processing (34)
  • docs/issues/pr1794-memory-hardening/plan.md
  • docs/issues/pr1794-memory-hardening/spec.md
  • docs/issues/pr1794-memory-hardening/tasks.md
  • src/main/presenter/agentRuntimePresenter/index.ts
  • src/main/presenter/databaseSecurityPresenter/index.ts
  • src/main/presenter/memoryPresenter/extraction.ts
  • src/main/presenter/memoryPresenter/index.ts
  • src/main/presenter/sqlitePresenter/index.ts
  • src/main/presenter/sqlitePresenter/tables/agentMemory.ts
  • src/main/presenter/sqlitePresenter/tables/deepchatTapeSearchProjection.ts
  • src/renderer/settings/components/MemoryConfigPanel.vue
  • src/renderer/settings/components/MemoryManagerPanel.vue
  • src/renderer/settings/components/MemorySettings.vue
  • src/renderer/src/i18n/da-DK/settings.json
  • src/renderer/src/i18n/de-DE/settings.json
  • src/renderer/src/i18n/en-US/settings.json
  • src/renderer/src/i18n/es-ES/settings.json
  • src/renderer/src/i18n/fa-IR/settings.json
  • src/renderer/src/i18n/fr-FR/settings.json
  • src/renderer/src/i18n/he-IL/settings.json
  • src/renderer/src/i18n/id-ID/settings.json
  • src/renderer/src/i18n/it-IT/settings.json
  • src/renderer/src/i18n/ja-JP/settings.json
  • src/renderer/src/i18n/ko-KR/settings.json
  • src/renderer/src/i18n/ms-MY/settings.json
  • src/renderer/src/i18n/pl-PL/settings.json
  • src/renderer/src/i18n/pt-BR/settings.json
  • src/renderer/src/i18n/ru-RU/settings.json
  • src/renderer/src/i18n/tr-TR/settings.json
  • src/renderer/src/i18n/vi-VN/settings.json
  • src/renderer/src/i18n/zh-CN/settings.json
  • src/renderer/src/i18n/zh-HK/settings.json
  • src/renderer/src/i18n/zh-TW/settings.json
  • test/main/presenter/memoryExtraction.test.ts
💤 Files with no reviewable changes (1)
  • src/main/presenter/agentRuntimePresenter/index.ts

Comment thread src/renderer/src/i18n/da-DK/settings.json Outdated
Comment thread src/renderer/src/i18n/de-DE/settings.json Outdated
Comment thread src/renderer/src/i18n/es-ES/settings.json Outdated
Comment thread src/renderer/src/i18n/fa-IR/settings.json Outdated
Comment thread src/renderer/src/i18n/fr-FR/settings.json Outdated
Comment thread src/renderer/src/i18n/tr-TR/settings.json Outdated
Comment thread src/renderer/src/i18n/vi-VN/settings.json Outdated
Comment thread src/renderer/src/i18n/zh-CN/settings.json Outdated
Comment thread src/renderer/src/i18n/zh-HK/settings.json Outdated
Comment thread src/renderer/src/i18n/zh-TW/settings.json Outdated
@zhangmo8 zhangmo8 marked this pull request as ready for review June 22, 2026 03:38
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator

LGTM

@yyhhyyyyyy yyhhyyyyyy merged commit 094fcd9 into dev Jun 22, 2026
2 of 3 checks passed
yyhhyyyyyy added a commit that referenced this pull request Jun 22, 2026
@zhangmo8 zhangmo8 deleted the fix/pr1794-memory-hardening-followup branch June 22, 2026 06:16
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.

2 participants