Repository navigation
fix(core): do not drop export requests committed during an in-flight drain - #3840
Conversation
There was a problem hiding this comment.
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
1e59d2d to
1082ddf
Compare
chcodex
left a comment
There was a problem hiding this comment.
Verified locally:
mvn -pl agentscope-core -am test -Dtest='io.agentscope.core.session.*Test'→ 23 tests pass on this PR, including the newSessionRecorderExportTest.- Replacing
SessionRecorderwith themainversion makes the new test fail (secondAccepted.awaittimes out), so the test is decisive for the bug. - Walked the commit-vs-drain interleavings with the
exportRequestedflag +while (CAS(true,false))drain loop +finallyre-scheduling: no window where a committed export request is lost, including theclose()-after-last-flush case — since every commit goes throughflushNow()→exportCommitted()beforeclose()runs, the while loop still exports the final events even with the heartbeat disposed. Keepingclose()untouched keeps the diff minimal, which is good.
Two non-blocking notes:
- In the
catchblock,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. Schedulers.boundedElastic().schedule(...)has no rejection guard: after the scheduler is shut down,flushNow()re-raises aRejectedExecutionExceptionas 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
left a comment
There was a problem hiding this comment.
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.
AgentScope-Java Version
2.1.0-SNAPSHOT (
mainat 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. Onceclose()disposed the heartbeat, the finalmessage/assistant,turn/outputandrun/endrecords stayed in theSessionLogbut 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 clearingexporting.Files:
agentscope-core/src/main/java/io/agentscope/core/session/SessionRecorder.javaagentscope-core/src/test/java/io/agentscope/core/session/SessionRecorderExportTest.java(new)How to test
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 onmain(the second event is never accepted;secondAccepted.awaittimes out) and passes with the change.Checklist
mvn spotless:applymvn test) — the new test passes as shown above; the full reactor suite was not run locallyAI 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.