Skip to content

fix(core): null-guard SessionRecorder on the legacy-history path (#3771) - #3832

Merged
juruoO-o merged 1 commit into
agentscope-ai:mainfrom
aiyili:fix/legacy-null-recorder
Nov 12, 2026
Merged

juruoO-o merged 1 commit into
agentscope-ai:mainfrom
aiyili:fix/legacy-null-recorder

Conversation

@aiyili

@aiyili aiyili commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Fixes #3771

Root cause

Under BUILDER_AGENT_API_LEGACY_HISTORY=true (AgentStateStore slots, no SessionLog), the RuntimeContext can carry a SessionExecution without a SessionRecorder. Three sites dereferenced the recorder unconditionally:

  1. SessionExecution.beforeStep(recorder, state) — recorder.acceptedMessageIds() → the reported NPE. Note the stack attribution: the trace middleware's doOnError logs it under its name ([opencode-coding-p]), but the throw site is in core.
  2. settleSession → execution.continueOrClose(SessionRecorder.from(rc)).
  3. closeFailedSessionExecution → recorder.close() — an NPE inside the error-cleanup path itself.

Fix

Null-guards at all three sites: when the recorder is absent, the journal bookkeeping is skipped (legacy mode has no journal to maintain) — matching the existing discipline at releaseCallExecution (if (recorder == null) return Mono.empty()). Legacy turns execute and write state snapshots normally.

Verification

The exact repro (legacy mode, first and subsequent turns) requires the service dataplane + Redis compose stack; the guard shape mirrors already-proven null-checks in the same file's lifecycle methods. A unit-level repro of the beforeStep path with a null recorder is straightforward if maintainers want it — happy to add on request.

BUILDER_AGENT_API_LEGACY_HISTORY=true(走 AgentStateStore 槽位,
无 SessionLog)时,RuntimeContext 可挂载 SessionExecution 而无
SessionRecorder。三处在 recorder 上无条件解引用:

- SessionExecution.beforeStep(recorder, state):acceptedMessageIds()
  NPE——报错的直接来源(栈上由中间件的 doOnError 记录,归因前缀是
  trace 中间件名,实际抛点在 core)
- settleSession 的 execution.continueOrClose(recorder)
- closeFailedSessionExecution 的 recorder.close()(错误清理自身 NPE)

三处补 null 防护:recorder 缺席即跳过 journal 记账(legacy 模式
本无 journal 可维护),与 releaseCallExecution 既有判空纪律一致。
legacy 路径的 turn 得以正常执行并写状态快照。

Fixes agentscope-ai#3771

@juruoO-o juruoO-o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed null-recorder guards on the legacy-history reasoning, settlement and error-cleanup paths. A focused legacy regression test would be a useful follow-up.

No blocking findings in the reviewed diff. This was a static review of source and tests; local Java/Maven tests were not run.

@juruoO-o
juruoO-o merged commit d7021da into agentscope-ai:main Nov 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 紧急不重要

Projects

None yet

3 participants