Skip to content

fix(core): do not drop export requests committed during an in-flight drain - #3840

Merged
juruoO-o merged 1 commit into
agentscope-ai:mainfrom
xubenqiang:fix/session-recorder-pending-export
Nov 12, 2026
Merged

juruoO-o merged 1 commit into
agentscope-ai:mainfrom
xubenqiang:fix/session-recorder-pending-export

Conversation

@xubenqiang

@xubenqiang xubenqiang commented Oct 28, 2026 •

Copy link
Copy Markdown

AgentScope-Java Version

2.1.0-SNAPSHOT (main at 4b6c59a)

Description

Fixes #3836.

SessionRecorder.exportCommitted() returned immediately when another drain was already running (exporting.compareAndSet(false, true) failed), without remembering that a new drain was needed. An event committed during that drain therefore had no follow-up trigger. Once close() disposed the heartbeat, the final message/assistant, turn/output and run/end records stayed in the SessionLog but were only accepted by the retry path — or not at all if the process exited first.

The recorder now records the request (exportRequested) and the running drain keeps draining until no request is left, re-scheduling itself if a request arrives between the loop exit and clearing exporting.

Files:

  • agentscope-core/src/main/java/io/agentscope/core/session/SessionRecorder.java
  • agentscope-core/src/test/java/io/agentscope/core/session/SessionRecorderExportTest.java (new)

How to test

mvn -pl :agentscope-core test -Dtest=SessionRecorderExportTest

Result: Tests run: 1, Failures: 0, Errors: 0.

The test follows the reproduction in the issue: a sink that blocks the first accept(), an event committed while that drain is blocked, close() to dispose the heartbeat, then release. It fails on main (the second event is never accepted; secondAccepted.await times out) and passes with the change.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test) — the new test passes as shown above; the full reactor suite was not run locally
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.) — no documentation change needed
  • Code is ready for review

AI assistance

Prepared with an AI coding agent (DeepSeek Harness / deepseek-flash) and verified with the run above.

The whole io.agentscope.core.session test package also passes with the change:mvn -pl :agentscope-core test -Dtest=io.agentscope.core.session.*Test -> 23 tests, 0 failures.

Copilot AI balanced review requested due to automatic review settings October 28, 2026 17:35
@CLAassistant

CLAassistant commented Oct 28, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

…drain

exportCommitted() returned as soon as another drain was running, so an event
committed during that drain had no follow-up trigger. When close() then disposed
the heartbeat, the final assistant message and run/end stayed unexported until an
external retry.

Record the request and drain until none is left.

Fixes agentscope-ai#3836
@xubenqiang
xubenqiang force-pushed the fix/session-recorder-pending-export branch from 1e59d2d to 1082ddf Compare October 28, 2026 18:56

@chcodex chcodex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified locally:

  • mvn -pl agentscope-core -am test -Dtest='io.agentscope.core.session.*Test' → 23 tests pass on this PR, including the new SessionRecorderExportTest.
  • Replacing SessionRecorder with the main version makes the new test fail (secondAccepted.await times out), so the test is decisive for the bug.
  • Walked the commit-vs-drain interleavings with the exportRequested flag + while (CAS(true,false)) drain loop + finally re-scheduling: no window where a committed export request is lost, including the close()-after-last-flush case — since every commit goes through flushNow() → exportCommitted() before close() runs, the while loop still exports the final events even with the heartbeat disposed. Keeping close() untouched keeps the diff minimal, which is good.

Two non-blocking notes:

  1. In the catch block, exportRequested.set(false) also drops a request that arrives concurrently with the failing drain. That matches the intended trade-off (the committed prefix stays in the log, the cursor is untouched, and an external retry picks it up) — just worth recording in the PR description/thread for future readers.
  2. Schedulers.boundedElastic().schedule(...) has no rejection guard: after the scheduler is shut down, flushNow() re-raises a RejectedExecutionException as a persistence failure even though the commit succeeded. Pre-existing behavior, not introduced here — probably worth a separate issue.

CI is green (ubuntu + windows). Approving.

@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 pending export request tracking and the drain completion handoff race, including the close-during-drain regression scenario.

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 2ec6ec0 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

Development

Successfully merging this pull request may close these issues.

SessionRecorder drops export requests committed during an in-flight drain

6 participants