Skip to content

[Bug]:Managed session turn fails with NullPointerException: Cannot invoke "SessionRecorder.acceptedMessageIds()" because "recorder" is null when legacy history is enabled #3771

Closed

Description

@ihuangweiwei

组件:service-dataplane / harness(AgentTraceMiddleware + SessionTurnRunner)

环境
agentscope-service 2.1.0-SNAPSHOT(agentscope-java 仓库)
后端:Redis(BUILDER_STORE_BACKEND=redis)
复现开关:BUILDER_AGENT_API_LEGACY_HISTORY=true(经 compose env 注入 data 容器)
复现步骤
以 BUILDER_AGENT_API_LEGACY_HISTORY=true 启动 data 容器(force-recreate);
创建 API 会话并提交一个 turn(POST /api/v1/agent-sessions/{id}/turns);
观察 data 日志。
实际行为(日志原文)
INFO HarnessAgentBuildService : Built data-plane agent ... instanceId=dpa-user-...-sess_e1aed4d8d1f8, version=3
INFO AgentTraceMiddleware : [opencode-coding-p] PRE_CALL | 1 input message(s)
ERROR AgentTraceMiddleware : NullPointerException: Cannot invoke
"io.agentscope.core.session.SessionRecorder.acceptedMessageIds()" because "recorder" is null
WARN SessionTurnRunner : Managed session turn failed: sessionId=sess_e1aed4d8d1f8,
error=Cannot invoke "io.agentscope.core.session.SessionRecorder.acceptedMessageIds()" because "recorder" is null
首个 turn 与后续 turn 均复现(新会话、旧会话一致)。

期望行为
LEGACY 历史模式(走 AgentStateStore 槽位)下 turn 应正常执行并写状态快照;
AgentTraceMiddleware 不应在 SessionRecorder 未装配时无条件访问。

附加观察(可能相关)
LEGACY 模式装配初始化会写入 agentscope:session:{userId}/{sessionId}:agent_state(含 :ver、:_keys)——
但键族是装配初始化(stateStore.saveIfVersion(expected=0))产物,不是 turn 执行写入;
turn 执行实际全部失败。即"写入侧可用、执行侧不可用"。

建议修复
LEGACY 装配路径初始化一个 SessionRecorder(或复用 AgentStateStore 快照做 accepted 追踪);
AgentTraceMiddleware 对 recorder == null 判空降级(跳过 accepted-message 追踪),避免 NPE 打断整个 turn。

Activity

  1. added
    bug
    on Oct 26, 2026
  2. aiyili commented on Oct 28, 2026

    @aiyili
    Contributor

    Hi, I'd like to work on this. The repro is precise: AgentTraceMiddleware unconditionally dereferences SessionRecorder.from(...) on the legacy-history path where no recorder is attached. Plan: null-guard the recorder access (skip/empty-set fallback when absent) so the legacy AgentStateStore-slot path executes turns and writes state snapshots normally, plus a regression test for the null-recorder path. PR coming shortly.

  3. aiyili commented on Nov 3, 2026

    @aiyili
    Contributor

    Saw the issue was closed as completed — thanks. For the maintainers' awareness, my PR #3832 (null-guards at the three unguarded SessionRecorder deref sites) is still open. Checking current main, the settleSession site now has a null check, but beforeStep and closeFailedSessionExecution still pass the nullable recorder straight through, so the NPE path from the original repro (BUILDER_AGENT_API_LEGACY_HISTORY=true, first turn) looks reachable unless something else changed upstream of these call sites.

    Two possibilities: (a) the closure was based on #3832's direction being right but wanting a different shape — happy to rebase/adjust if so; or (b) it was closed as addressed-in-spirit while the remaining guards slipped. If (b), I'd suggest keeping #3832 open (or me repushing it) until the two sites are guarded — otherwise the reporter's exact repro may still throw. Asking before pushing anything, since the issue is closed either way.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions