Skip to content

[Bug]:CompactionMiddleware 将用户中断会话降级为压缩失败并重复执行下游 reasoning #2658

Closed

Description

@CyberXavier

问题描述

CompactionMiddleware 的设计意图是在会话压缩发生普通失败时跳过压缩,并继续原始 reasoning。
但现有 onErrorResume 覆盖了 compactIfNeeded(...) 以及其后的 next.apply(...)。因此,下游 reasoning 抛出的异常也会被当作“压缩失败”处理。

当用户中断发生在压缩或下游 reasoning 阶段时,InterruptedException 会进入该 fallback,随后再次执行 next.apply(input)。第二次执行位于 ReActAgent 的入口中断检查之后,可能继续发起模型请求,直到模型流返回首个 chunk 才观察到中断。

复现条件

  1. 构建启用了 CompactionMiddleware 的 ReActAgent。
  2. 使本轮调用在压缩或后续 reasoning 阶段处于执行中。
  3. 对对应 (userId, sessionId) 调用 agent.interrupt(context)。
  4. 压缩或下游返回 InterruptedException。

修复前,日志可能出现类似内容:

Compaction failed, continuing without compaction: Agent execution interrupted

随后还会进入一次额外的 reasoning,造成取消终态延迟和额外模型请求。

期望行为

  • 普通压缩异常:仅跳过压缩,使用原始输入调用一次下游 reasoning。
  • InterruptedException 或其包装原因:原样向外传播,不调用下游 reasoning,也不记录为压缩失败。
  • 下游 reasoning 的异常:原样向外传播,不得被 fallback 捕获并重试。
  • 目标会话中断不影响其他并发会话。

实际影响

  • 用户点击停止后,前端需要等待第二次 reasoning 的首个模型 chunk 才能恢复可输入状态。
  • 产生不必要的模型调用和 token 消耗。
  • Compaction failed 告警掩盖真实的用户取消语义,增加排障误判风险。

环境

  • AgentScope-Java:2.0.3-SNAPSHOT 本地验证版本
  • Java:17
  • 操作系统:Windows 11
  • 调用方式:会话服务通过 HarnessAgent 流式执行
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/harnessbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions