Skip to content

feat(session): 使用 active/historical 双列表优化会话历史存储#80

Merged
helloopenworld merged 1 commit into
mainfrom
bugfix/summary_checker_opt
Jun 12, 2026
Merged

feat(session): 使用 active/historical 双列表优化会话历史存储#80
helloopenworld merged 1 commit into
mainfrom
bugfix/summary_checker_opt

Conversation

@raychen911

Copy link
Copy Markdown
Contributor

本次调整将会话历史从原先依赖 Event model_flags 区分模型可见性,改为使用
Session.events 与 Session.historical_events 分别存储 active 模型窗口和历史数据,减少内部遍历与过滤开销,并统一 Redis、SQL、InMemory
后端的持久化语义。

主要变更:

  • Session.events 现在只保留模型可见的 active event window。
  • 新增 Session.historical_events,用于按需保存被 max_events、TTL 或 summary 移出 active window 的历史事件。
  • 新增 SessionServiceConfig.store_historical_events,控制是否保存历史事件。
  • 保留 Event.is_model_visible() / set_model_visible() 公共接口用于兼容,但 SDK 内部不再依赖该 flag 进行模型历史过滤。
  • 调整 Session.add_event() / apply_event_filtering() 内部实现,新增内部 helper 返回本次被裁剪的事件,避免影响公共返回值兼容。
  • Summary 压缩后使用 [summary_event, recent_events...] 作为新的 active window,旧 summary 会参与下一轮 re-summary,避免历史摘要丢失。
  • Summarizer checker 只跳过首位 summary anchor,避免每次反向扫描 events,降低大窗口下的触发检查成本。
  • RedisSessionService 写回裁剪后的 active events 与 historical_events,同时保留 app/user/session/temp state 的分层存储语义。
  • SqlSessionService 将 active events 存在 events 表,将 historical_events 存在 sessions 表 JSON 字段;append 时仅在本次发生裁剪时删除对应旧 event rows,避免每次全量同步。
  • InMemory、Redis、SQL 的 list_sessions() 均不返回 events 和 historical_events,避免列表接口返回大量历史数据。
  • MemPalace、Mem0、SQL/Redis/InMemory memory service 适配新的 active events 语义,不再使用 is_model_visible() 过滤。
  • 更新相关单测,覆盖 Redis/SQL active-historical 持久化、state 分层、summary re-compress、list_sessions 不返回 historical_events 等场景。

兼容性说明:

  • Event.is_model_visible() / set_model_visible() 仍保留,避免业务调用时报错。
  • SDK 内部模型可见性以 Session.events / Session.historical_events 的归属为准。
  • Redis/SQL 后端仅在未显式传入 session_config 时默认开启 store_historical_events;显式传入 SessionServiceConfig() 时仍按默认 False,不保存历史事件。
  • SQL stale reload 场景保留现有 best-effort 行为,并通过注释说明并发写入下可能存在窗口不一致,需要更重的版本控制/锁机制才能彻底解决。

本次调整将会话历史从原先依赖 Event model_flags 区分模型可见性,改为使用
Session.events 与 Session.historical_events 分别存储 active
模型窗口和历史数据,减少内部遍历与过滤开销,并统一 Redis、SQL、InMemory
后端的持久化语义。

主要变更:
- Session.events 现在只保留模型可见的 active event window。
- 新增 Session.historical_events,用于按需保存被 max_events、TTL 或
  summary 移出 active window 的历史事件。
- 新增
  SessionServiceConfig.store_historical_events,控制是否保存历史事件。
- 保留 Event.is_model_visible() / set_model_visible()
  公共接口用于兼容,但 SDK 内部不再依赖该 flag 进行模型历史过滤。
- 调整 Session.add_event() / apply_event_filtering() 内部实现,新增内部
  helper 返回本次被裁剪的事件,避免影响公共返回值兼容。
- Summary 压缩后使用 [summary_event, recent_events...] 作为新的 active
  window,旧 summary 会参与下一轮 re-summary,避免历史摘要丢失。
- Summarizer checker 只跳过首位 summary anchor,避免每次反向扫描
  events,降低大窗口下的触发检查成本。
- RedisSessionService 写回裁剪后的 active events 与
  historical_events,同时保留 app/user/session/temp state
的分层存储语义。
- SqlSessionService 将 active events 存在 events 表,将
  historical_events 存在 sessions 表 JSON 字段;append
时仅在本次发生裁剪时删除对应旧 event rows,避免每次全量同步。
- InMemory、Redis、SQL 的 list_sessions() 均不返回 events 和
  historical_events,避免列表接口返回大量历史数据。
- MemPalace、Mem0、SQL/Redis/InMemory memory service 适配新的 active
  events 语义,不再使用 is_model_visible() 过滤。
- 更新相关单测,覆盖 Redis/SQL active-historical 持久化、state
  分层、summary re-compress、list_sessions 不返回 historical_events
等场景。

兼容性说明:
- Event.is_model_visible() / set_model_visible()
  仍保留,避免业务调用时报错。
- SDK 内部模型可见性以 Session.events / Session.historical_events
  的归属为准。
- Redis/SQL 后端仅在未显式传入 session_config 时默认开启
  store_historical_events;显式传入 SessionServiceConfig() 时仍按默认
False,不保存历史事件。
- SQL stale reload 场景保留现有 best-effort
  行为,并通过注释说明并发写入下可能存在窗口不一致,需要更重的版本控制/锁机制才能彻底解决。
@raychen911 raychen911 force-pushed the bugfix/summary_checker_opt branch from d8604b5 to f37f118 Compare June 12, 2026 08:09
@helloopenworld helloopenworld merged commit ce81a2c into main Jun 12, 2026
5 checks passed
raychen911 added a commit that referenced this pull request Jun 12, 2026
本次调整将会话历史从原先依赖 Event model_flags 区分模型可见性,改为使用
Session.events 与 Session.historical_events 分别存储 active
模型窗口和历史数据,减少内部遍历与过滤开销,并统一 Redis、SQL、InMemory
后端的持久化语义。

主要变更:
- Session.events 现在只保留模型可见的 active event window。
- 新增 Session.historical_events,用于按需保存被 max_events、TTL 或
  summary 移出 active window 的历史事件。
- 新增
  SessionServiceConfig.store_historical_events,控制是否保存历史事件。
- 保留 Event.is_model_visible() / set_model_visible()
  公共接口用于兼容,但 SDK 内部不再依赖该 flag 进行模型历史过滤。
- 调整 Session.add_event() / apply_event_filtering() 内部实现,新增内部
  helper 返回本次被裁剪的事件,避免影响公共返回值兼容。
- Summary 压缩后使用 [summary_event, recent_events...] 作为新的 active
  window,旧 summary 会参与下一轮 re-summary,避免历史摘要丢失。
- Summarizer checker 只跳过首位 summary anchor,避免每次反向扫描
  events,降低大窗口下的触发检查成本。
- RedisSessionService 写回裁剪后的 active events 与
  historical_events,同时保留 app/user/session/temp state
的分层存储语义。
- SqlSessionService 将 active events 存在 events 表,将
  historical_events 存在 sessions 表 JSON 字段;append
时仅在本次发生裁剪时删除对应旧 event rows,避免每次全量同步。
- InMemory、Redis、SQL 的 list_sessions() 均不返回 events 和
  historical_events,避免列表接口返回大量历史数据。
- MemPalace、Mem0、SQL/Redis/InMemory memory service 适配新的 active
  events 语义,不再使用 is_model_visible() 过滤。
- 更新相关单测,覆盖 Redis/SQL active-historical 持久化、state
  分层、summary re-compress、list_sessions 不返回 historical_events
等场景。

兼容性说明:
- Event.is_model_visible() / set_model_visible()
  仍保留,避免业务调用时报错。
- SDK 内部模型可见性以 Session.events / Session.historical_events
  的归属为准。
- Redis/SQL 后端仅在未显式传入 session_config 时默认开启
  store_historical_events;显式传入 SessionServiceConfig() 时仍按默认
False,不保存历史事件。
- SQL stale reload 场景保留现有 best-effort
  行为,并通过注释说明并发写入下可能存在窗口不一致,需要更重的版本控制/锁机制才能彻底解决。
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