Skip to content

fix(core): keep export requests that arrive during a running drain - #3849

Closed
wahllllll wants to merge 1 commit into
agentscope-ai:mainfrom
wahllllll:fix/issue-3836-export-drain-pending
Closed

wahllllll wants to merge 1 commit into
agentscope-ai:mainfrom
wahllllll:fix/issue-3836-export-drain-pending

Conversation

@wahllllll

Copy link
Copy Markdown
Contributor

Problem

SessionRecorder.exportCommitted() takes the exporting flag and returns silently when another drain already holds it:

if (!exporting.compareAndSet(false, true)) return;

Nothing records that another drain is required, so a commit that lands during a running drain is never exported by it. The one second heartbeat usually hides this, but close() disposes the heartbeat, so events committed near the end of a run stay unexported until an external retry — the case reported in #3836, where run/end committed at 12:51:50.351 but the sink cursor only advanced at 12:52:07.255.

Change

exportCommitted() now records the request before taking the flag, and the drain runs in a loop that continues while requests are pending. The finally block re-arms when a request landed between the last check and clearing the flag, so no window is left where a committed event waits for a retry.

Behavior is otherwise unchanged: the drain still runs on Schedulers.boundedElastic() and never on the committing thread, the existing warning for a failed drain is preserved, and the cursor still advances per acknowledged event through SessionLogExporter.

Regression

SessionRecorderExportDrainTest.eventCommittedDuringDrainIsStillExported uses a sink that blocks inside accept():

  1. commit a message, which starts a drain that blocks in the sink;
  2. commit a second message while that drain is running;
  3. close() the recorder, which disposes the heartbeat;
  4. release the sink and require both events to arrive.

Before the change the sink receives only [1] and the test fails with:

the event committed during the drain never reached the sink: [1]

After the change it receives [1, 2].

Verification

  • mvn -B -pl agentscope-core -Dtest=SessionRecorderExportDrainTest,io.agentscope.core.session.*Test test: 23 tests, 0 failures.
  • mvn -B -pl agentscope-core test: 2873 tests, 0 failures, 2 errors — only the pre-existing DangerousPathBypassTest symlink cases that need Windows symlink privileges unavailable on this machine (they also fail on unmodified main).
  • mvn -B -pl agentscope-core spotless:check: BUILD SUCCESS.

Fixes #3836.

exportCommitted() returned as soon as the exporting flag was taken, so a
commit that landed while a drain was running was never exported by that
drain. The one second heartbeat normally caught it later, but close()
disposes the heartbeat, so events committed near the end of a run waited
for an external retry before reaching the sink, leaving exported state
behind the durable journal.

Record the request before taking the flag and let the drain loop until no
new request arrived, re-arming when one lands while the flag is cleared.

Regression: a sink that blocks inside accept() while a second message is
committed now receives both events after close() disposes the heartbeat;
before the change it only ever received the first.
@wahllllll
wahllllll force-pushed the fix/issue-3836-export-drain-pending branch from 055bbf7 to e106ce4 Compare October 29, 2026 06:23
@wahllllll

Copy link
Copy Markdown
Contributor Author

Closing in favour of #3840, which was opened earlier and is already approved on the same fix. A second PR for the same behaviour only splits review attention.

One note for whoever lands #3840, also recorded here: its re-arm calls exportRequested.set(false) before checking the flag, so a commit arriving between the drain loop and that reset can be cleared without a re-dispatch. A compareAndSet in the finally block, as in this branch, has no such window.

@wahllllll wahllllll closed this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SessionRecorder drops export requests committed during an in-flight drain

1 participant