Repository navigation
Conversation
…ancelled SessionRecorder.flush() ran flushNow() through Mono.fromRunnable(...).subscribeOn(Schedulers.boundedElastic()). Disposing that subscription cancels the scheduled task, and cancelling a running task interrupts its thread, so renew() or commit() could be interrupted in flight. An interrupted commit leaves the durable outcome unknown, and retrying a partially applied commit is not safe. Submit the storage work so that only the signal can be cancelled: the write always runs to completion, and the caller still observes completion, failure or cancellation as before. finish() closes the recorder through the same path, which also protects the writer release. Regression: SessionRecorderCancellationTest blocks the journal's renew(), disposes the flush subscription, and asserts the worker was not interrupted and that the queued event still committed. Before this change it fails with "disposing flush interrupted the thread executing journal I/O".
5 tasks done
juruoO-o
approved these changes
Nov 11, 2026
juruoO-o
left a comment
Collaborator
There was a problem hiding this comment.
取消订阅不应中断已开始的 renew/commit/release;将存储工作独立调度且不绑定下游取消,是针对性的修复,保留原有接口与正常顺序,没有引入不安全的写入重试。已检查新增取消回归用例与 finish 路径,未发现本次变更的阻塞问题。本轮未重跑测试;独立的初始化取消/lease 生命周期问题仍按 PR 描述保留在范围外。
juruoO-o
approved these changes
Nov 11, 2026
juruoO-o
left a comment
Collaborator
There was a problem hiding this comment.
已复核本次冲突解决:保留 #4046 的 SessionRecorderCancellationTest,将原 flush 取消回归改名为 SessionRecorderFlushCancellationTest,生产修复保持原范围。当前集成提交本地 core 全量及 spotless:check 通过:3250 项,0 failures/errors,11 项既有条件跳过;两组取消测试和 4 项原生工具取消回归均通过。未发现新增阻塞问题;全仓及 Windows 验证等待本次 CI。
juruoO-o
force-pushed
the
fix/issue-3815-cancellation-safe-flush
branch
from
November 11, 2026 11:05
b82ed74 to
2f7abb9
Compare
Contributor
Author
|
Thank you for the review and the merge. #3823 is the same change family — session-prefix replay batching, one commit, CI green — and would take a rebase gladly if the diff has drifted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SessionRecorder.flush()schedules storage work like this:flushNow()callslog.renew(writer, LEASE)and thenlog.commit(...). Reactor'sboundedElasticruns the task on aScheduledThreadPoolExecutor, and disposing the subscription cancels the task with interruption. A caller that cancels a flush — a request whose subscriber goes away, aMono.usingcleanup, a timeout — therefore interrupts the thread while it is insidereneworcommit.That is worse than a lost write: the durable outcome becomes unknown. A commit that was interrupted halfway may or may not have been applied, and automatically retrying a partially applied commit is not safe.
finish()had the same shape forclose()(.then(...)plus theonErrorResumepath), so a cancellation could also interruptlog.release(writer).Change
Storage work is now submitted so that only the signal can be cancelled: the runnable runs to completion on the elastic pool, and the returned
Monostill reports completion, failure or cancellation to its subscriber as before.flush()and bothclose()call sites infinish()use it. No signature, sequencing or error-propagation change beyond "cancelling no longer aborts an in-flight write".I deliberately did not touch the second problem in the report (a cancelled initialization can leave the recorder's writer lease held). That is a lifecycle question about when
close()is guaranteed to run, and it deserves its own change rather than being folded in here.Regression
SessionRecorderFlushCancellationTest.disposingFlushDoesNotInterruptJournalIowraps the journal in a spy whoserenewblocks on a latch, queues one event, subscribes toflush(), disposes the subscription while the journal call is in flight, and then asserts:Before the change it fails with:
Verification
mvn -B -pl agentscope-core -Dtest='io.agentscope.core.session.*Test' test: 23 tests, 0 failures.mvn -B -pl agentscope-core test: 2959 tests, 0 failures, 0 errors other than the two pre-existingDangerousPathBypassTestWindows symlink errors, which also fail on unmodifiedmain.mvn -B -pl agentscope-core spotless:check: BUILD SUCCESS.Addresses the first problem in #3815.
Maintainer integration validation
Merged
mainat9d4f86426470f06a5b15e0788efd4bad5eab6253into this original PR branch. Resolved the add/add test conflict with #4046 by retaining itsSessionRecorderCancellationTestand naming this PR's original regressionSessionRecorderFlushCancellationTest; no production behavior was added beyond the original cancellation-safe storage change.On integration commit
b82ed745f75be301a732853dc09df15c56e08d6f,mvn -B -T1C -pl agentscope-core -am test spotless:checkpassed locally on JDK 21 (source release 17): 3250 tests, 0 failures/errors, 11 skipped. Skips are 3 Windows-only tests, 1 opt-in structured-output race test, and 7 pre-existing disabled stream-contract tests. Both cancellation suites ran (11 checkpoint cases and 1 flush-cancellation case), as did the 4 native tool cancellation cases. Full repository verification and Windows execution are left to the new CI run.