Skip to content

[Bug] 会话历史存储换代后缺少删除原生会话(journal)的官方 API #3612

Open

Description

@wxh2010zd

概述

会话历史的存储后端在 JEV 重构(#3441,随 2.1.0-BETA1 引入、计划 backport 到 2.0.5)之后发生了换代:完整对话历史不再由有损的 <sessionId>.log.jsonl 承载,改由 native session journal 承载——JournalSessionLog 写结构化事件(hash 链式 commit,带完整 payload),落在受保护的 .agentscope-runtime/(本地文件或 SQLite)。

换代后,完整会话历史落在受保护的 .agentscope-runtime/ 下(native session journal)。目前观察到:

  • 框架未提供删除原生会话的官方 API——既没有类似 deleteSession(...) / purgeSession(...) / retention(...) 的入口;
  • 本地会话文件位于受保护目录 .agentscope-runtime/,使用方无法直接绕过框架去删除底层文件。

结果是:使用方无法清理/删除某个会话的原生历史数据。对于有数据留存、隐私合规、测试隔离、按用户/租户回收数据等诉求的场景,这是一个功能缺口。

环境

项 值
模块 / 依赖 io.agentscope:agentscope-harness、agentscope-core
引入换代的 PR #3441(feat: redesign Harness context and unify Service sessions with JEV)
首次包含该换代的版本 2.1.0-BETA1(不在 2.0.4,计划 backport 至 2.0.5)
上游对照 agentscope-ai/agentscope-java main(e68dd783)
本地会话落盘位置 受保护目录 .agentscope-runtime/(本地文件或 SQLite)

问题分析

1. 契约层缺少删除原语

SessionLogStore 只有 open() / list(),AtomicSessionStorage 只有 read() / listPaths() / compareAndSet()。均无删除相关方法。

2. clearContext 不等于删除

HarnessAgent.clearContext(userId, sessionId) 不是删除:它只清模型可见上下文,并且会向 journal 追加一个 context_cleared checkpoint(ReActAgent.clearNativeContext → updateAgentState),journal 本体原样保留——所以它不满足隐私合规意义上的"删除"。

3. Journal 的 hash 链式结构带来的设计张力

Journal 是 hash 链式的 append-only 审计结构,物理删除单个事件会破坏链语义。但 journal 目录按 SessionKey 完全自包含,"按会话整目录删除"不会影响其他会话。

影响

  • 无法实现"删除某个会话"这一常见且合规相关的能力(如"清除某用户的历史会话")。
  • 受保护目录不可直接操作,等于把删除能力完全锁在框架内部,而框架又没有暴露该能力,形成死角。
  • 对于有数据留存、隐私合规(如 GDPR 被遗忘权)、测试隔离、按用户/租户回收数据等诉求的场景,无法满足基本要求。

建议方案

  1. 提供 SessionLogStore.delete(SessionKey):在契约层增加删除原语,按会话整目录删除,不影响其他会话。
  2. 提供 HarnessAgent.deleteSession(rc):在高层 API 暴露删除能力,复用 updateAgentState 已有的模式(获取 writer lease、拒绝活跃执行),先写 tombstone 事件再由后端物理回收目录。
  3. 明确对 journal 与 legacy 文件的处理边界:若同时存在 legacy 文件,需明确删除行为覆盖范围。
  4. 文档/发布说明:明确删除 API 的语义(tombstone vs 物理删除)、对 journal 链完整性的影响、以及与 legacy 模式的交互。

关联

  • 原始问题:#3567(会话历史存储后端换代遗留问题总 issue)
  • 换代来源:#3441(feat: redesign Harness context and unify Service sessions with JEV)
  • 文档修正 PR:#3561(docs(harness): correct session log claims after the native journal redesign)

Activity

  1. added
    bug
    on Oct 16, 2026
  2. ningmao-hlyz commented on Oct 16, 2026

    @ningmao-hlyz
    Contributor

    计划实现如下:

    契约层补:

    • SessionLogStore.delete(SessionKey)
    • AtomicSessionStorage.deletePaths(...)(现在只有 read / listPaths / compareAndSet)

    SQLite 按 key 删行,文件后端删 SessionKey 整目录。

    Agent 层加 HarnessAgent.deleteSession(rc),复用 updateAgentState 的 writer lease:拿到 lease 才动手,会话活跃执行中直接拒绝。

    删除粒度按会话整目录。journal 是 hash 链 append-only,单事件物理删除会破坏链语义;目录按 SessionKey 完全自包含,不影响其他会话。审计要求高的场景可以讨论 tombstone + 物理回收两段式,第一版不必须。

    和 clearContext 划清界限:它只清模型可见上下文,并向 journal 追加 context_cleared checkpoint,journal 本体原样保留,不是删除。文档里写明。

    数据留存策略 retention 先不做。

  3. jujn commented on Oct 18, 2026

    @jujn
    Collaborator

    @wxh2010zd 实际看下来可能要比 #3613 复杂得多,我本身并不熟悉这块,推荐参考该思路暂时自行打包

  4. wxh2010zd commented on Oct 19, 2026

    @wxh2010zd
    Author

    5. @wxh2010zd 实际看下来可能要比 #3613 复杂得多,我本身并不熟悉这块,推荐参考该思路暂时自行打包

    好的,不过感觉这次改版涉及到的其他问题也很多,比如刚才还发现要遍历出用户对应的会话列表,我每个会话都做了一次完整的 journal 全量重放 ;再叠加 Windows 下每读一次 SQLite 都新建连接 + 建表,17 个会话串行跑就把耗时放大到了 6 秒以上

  5. aiyili commented on Nov 5, 2026

    @aiyili
    Contributor

    Hi, I'd like to work on this. The design tension (hash-chain journal vs. right-to-erasure) is well framed. Direction: tombstone-based delete — append a session_deleted sentinel event and have readers treat the session as gone (preserves chain integrity for other sessions sharing the store while making the content unreadable), plus SessionLogStore.delete(SessionKey) at the contract layer with file/SQLite implementations. Details after reading the journal layout. PR coming shortly.

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

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions