Skip to content

feat(memory): Dreaming and versioned long-term memory - #3509

Merged
WMC001 merged 35 commits into
developfrom
dev/feature/memory_dreaming
Aug 14, 2026
Merged

feat(memory): Dreaming and versioned long-term memory#3509
WMC001 merged 35 commits into
developfrom
dev/feature/memory_dreaming

Conversation

@JasonW404

@JasonW404 JasonW404 commented Jul 27, 2026

Copy link
Copy Markdown
Member

概述

  • 完成 Dreaming 流程及 Tenant/User 长期记忆版本架构的收敛。
  • memory_long_term_version_t 中保存不可变的 Markdown 版本,并以 is_active 作为当前生效版本的唯一事实来源。
  • 将 Dreaming 候选决策从 audit 表中的 JSON 数据规范化到 memory_dreaming_decision_t,每项决策对应一行记录。
  • 将生效的 Tenant 和 User 记忆以结构化上下文注入 Chat,并提供基于预算的语义块筛选、缓存、结果校验和确定性降级。
  • 移除未发布的中间 schema、兼容别名、废弃 API 以及独立的 Playwright 测试工程。

架构变更

长期记忆版本

  • Tenant 和 User 记忆共用 memory_long_term_version_t,版本创建后保持不可变。
  • 直接使用 is_active 表示激活状态,不再维护 activation audit 或 config pointer。
  • 删除 Dreaming 历史时,软删除 Dreaming 生成的 User 版本,同时保留手动版本;必要时自动恢复最新可用的手动版本。
  • Agent 短期记忆记录保持不变;旧的 Tenant/User record-table API 统一返回 410 Gone

Dreaming 执行与审计

  • memory_dreaming_audit_t 保存执行状态、阶段、计数、耗时、降级、遗漏及 evidence 元数据。
  • memory_dreaming_decision_t 将每项候选决策展开为类型明确的字段,包括:
    • 决策顺序和记忆 ID;
    • 评分、噪声、信号数量及上下文多样性;
    • evidence IDs、事件、原因及归档建议。
  • 决策记录随所属执行记录级联删除,并保证同一次执行中的顺序唯一。
  • 最终阶段名称统一为 summarization,移除旧的 compression 阶段及 compressor 兼容别名。

Chat 上下文

  • 生效的 Tenant 和 User 文档以结构化记忆项传入,并携带 scope、version ID 和 source 元数据。
  • 仅在确定性上下文压缩后仍超过软预算时触发语义筛选。
  • 同一个用户请求中,Tenant 和 User 两个 scope 合计最多调用一次筛选模型。
  • 模型只能选择由代码生成的 Markdown block ID,不能重写记忆正文。
  • 模型超时、调用失败或输出校验不通过时,使用 scope 公平的确定性保留与显式截断策略降级。

UI 与 API 行为

  • 保持 /memory/dreaming/*/memory/long-term/{tenant|user}/* HTTP 路径不变。
  • 记忆设置页面支持 Dreaming 调度、阈值、执行状态及 Tenant/User 版本管理。
  • 修复历史版本激活流程,并补齐相关错误提示的国际化。

数据库迁移

  • 全新安装时直接创建最终表结构,不再在建表后立即执行可合并的 ALTER
  • 支持从未发布的 result_jsondecisions JSONB 结构升级,并按照原有顺序将历史决策展开为独立记录。
  • 删除旧 activation audit 表和中间态 Dreaming version 结构。
  • migration 可重复执行;已有开发环境数据中的决策评分和 evidence IDs 均得到保留。

验证结果

  • GitHub Actions 单元测试:通过。
  • Codecov patch 覆盖率:90.19174%,达到仓库门禁要求。
  • SonarCloud、CodeQL:通过。
  • 前端类型检查以及全部 amd64/arm64 镜像构建:通过。
  • PostgreSQL migration 集成测试:3 passed,覆盖最终 schema、advisory lock、JSON 决策升级及重复执行。
  • Dreaming schema、数据库、服务及覆盖率相关回归测试:通过。

Dreaming进行中
image

Dreaming完成
image

租户记忆(仅人为编辑/预览)
image

用户记忆(可人为编辑/预览,也可由Dreaming写入)
image

长期记忆召回
image

@JasonW404

Copy link
Copy Markdown
Member Author

自动 Dreaming 定时能力已补齐(commit cb71431):\n\n- Dreaming 页新增自动开关,支持每日、每周、固定小时周期和浏览器 IANA 时区;默认关闭。\n- 新增按 tenant/user/agent scope 持久化的 schedule API 与数据库迁移,保存后返回下一次执行时间。\n- 复用现有 ScheduleSpec/LeaseScheduler;到期计划原子生成 trigger_source=schedule 的 queued audit,多实例通过 FOR UPDATE SKIP LOCKED 避免重复,同 scope 有活动任务时跳过本周期并推进。\n- 权限沿用 DREAMING VIEW_TENANT / EDIT_TENANT。\n\n验证:Dreaming 回归 138 passed;Ruff/ESLint/Next build PASS;真实 PostgreSQL 到期计划已自动生成并完成 run_id=13;Playwright 验证开启→2h→保存→刷新持久化→关闭,截图 /tmp/ac036-dreaming-schedule.png。AC-033~AC-036 PASS。

@JasonW404
JasonW404 marked this pull request as ready for review August 7, 2026 02:25
Copilot AI lite review requested due to automatic review settings August 7, 2026 02:25

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…_dreaming

# Conflicts:
#	.gitignore
#	frontend/const/modelConfig.ts
#	frontend/package.json
#	frontend/public/locales/en/common.json
#	frontend/public/locales/zh/common.json
#	frontend/services/api.ts
#	sdk/nexent/core/agents/context/manager.py
…rfall, i18n

Backend:
- Add per-user configurable dreaming thresholds (min_score, min_recall_count,
  min_unique_queries) stored in memory_dreaming_schedule_t
- Add clear/undo-clear endpoints for long-term memory with deactivated_version_id
- Implement 3-tier compression waterfall: not_needed -> semantic -> mechanical_fallback
- Add threshold columns to DB model and migrations (v2.5.0)
- Add timeout handling for stuck dreaming progress

Frontend:
- Add threshold configuration UI in Dreaming tab (per-user editable)
- Implement clear/undo flow with Option A: show cleared version card
  (V{n} (已清空) | 0 chars | no compression) instead of empty state
- Add version history dropdown in current LTM section
- Add comprehensive i18n support (en + zh) for all Dreaming UI elements
- Fix expand/collapse with collapsible mode
- Adjust layout to 2:1 ratio (thresholds vs automatic dreaming)

SDK:
- Update version_builder with compression status tracking

Tests:
- Add/update unit tests for compressor and version builder
- Replace hardcoded '基础设置' tab label with t('memoryManageModal.baseSettings')
- Replace hardcoded page title/description with i18n keys
- Replace hardcoded memory ability description with i18n key
- Add memoryManageModal.baseSettingsDescription (zh/en)
- Add memoryManageModal.memoryAbilityDescription (zh/en)
- Rename '启用 Dreaming' to '长期记忆Dreaming算法' (i18n zh/en)
- Fill threshold default values directly instead of placeholder hints
- Remove parameter tags from Dreaming tab header
- Add version dropdown in cleared state card (after clearing LTM)
- Add version dropdown in empty state (when no active version exists)
- Make expected_active_version_id optional for version activation
  (allows switching versions when no active version exists)
- Remove unused fetchDreamingParameters call from DreamingPanel
- Add DreamingConfigCards component for base settings thresholds
…_dreaming

# Conflicts:
#	frontend/public/locales/en/common.json
#	frontend/public/locales/zh/common.json
@JasonW404 JasonW404 changed the title feat(memory): complete Dreaming consolidation flow feat(memory): finalize Dreaming and versioned long-term memory Aug 13, 2026
@JasonW404 JasonW404 changed the title feat(memory): finalize Dreaming and versioned long-term memory feat(memory): Dreaming and versioned long-term memory Aug 14, 2026
@WMC001
WMC001 merged commit c4b2286 into develop Aug 14, 2026
16 checks passed
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.

3 participants