Repository navigation
Conversation
juruoO-o
added a commit
that referenced
this pull request
Nov 11, 2026
…ancelled (#3888) ## Problem `SessionRecorder.flush()` schedules storage work like this: ```java public Mono<Void> flush() { return Mono.<Void>fromRunnable(this::flushNow).subscribeOn(Schedulers.boundedElastic()); } ``` `flushNow()` calls `log.renew(writer, LEASE)` and then `log.commit(...)`. Reactor's `boundedElastic` runs the task on a `ScheduledThreadPoolExecutor`, and disposing the subscription **cancels the task with interruption**. A caller that cancels a flush — a request whose subscriber goes away, a `Mono.using` cleanup, a timeout — therefore interrupts the thread while it is inside `renew` or `commit`. 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 for `close()` (`.then(...)` plus the `onErrorResume` path), so a cancellation could also interrupt `log.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 `Mono` still reports completion, failure or cancellation to its subscriber as before. ```java private static Mono<Void> uninterruptible(Runnable work) { return Mono.<Void>create( sink -> Schedulers.boundedElastic().schedule(() -> { try { work.run(); sink.success(); } catch (Throwable error) { sink.error(error); } })); } ``` `flush()` and both `close()` call sites in `finish()` 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.disposingFlushDoesNotInterruptJournalIo` wraps the journal in a spy whose `renew` blocks on a latch, queues one event, subscribes to `flush()`, disposes the subscription while the journal call is in flight, and then asserts: - the thread executing journal I/O was **not** interrupted; - the queued event still reached the journal. Before the change it fails with: ``` disposing flush interrupted the thread executing journal I/O ==> expected: <false> but was: <true> ``` ## 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-existing `DangerousPathBypassTest` Windows symlink errors, which also fail on unmodified `main`. - `mvn -B -pl agentscope-core spotless:check`: BUILD SUCCESS. Addresses the first problem in #3815. ### Maintainer integration validation Merged `main` at `9d4f86426470f06a5b15e0788efd4bad5eab6253` into this original PR branch. Resolved the add/add test conflict with #4046 by retaining its `SessionRecorderCancellationTest` and naming this PR's original regression `SessionRecorderFlushCancellationTest`; 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:check` passed 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. Co-authored-by: juruoO-o <[email protected]>
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.
Fixes #4045
AgentScope-Java Version
2.1.0-SNAPSHOT;本地验证提交:000386c816507cf3fbbc39fc95e0a7accadc4da0(基于85fa9a60257ceb1570e6a195d0588ceba1e8a8c2)。Description
并行工具批次中,已完成工具的
action/end可以先于批次结果写入 canonical context。若工具更新了会话状态,此时硬取消产生的新 checkpoint 会遮蔽已记录的完成结果;显式核对真正不确定的兄弟工具并恢复后,已成功工具可能再次执行。完整复现及四组对照见 #4045。本 PR 将改动限定在取消收尾:
SessionRecorder中保留本轮完成工具结果的冻结副本。finish(..., "cancelled")时,向恢复快照补入当前仍有未配对本地调用的完成结果。生产代码只改
SessionRecorder.java(35 行新增、1 行删除),另加两个测试文件;无公共 API、事件格式、依赖或配置变化。不修改SessionProjection或恢复扫描锚点。验证
在 macOS / Microsoft OpenJDK 21.0.7(源码 release 17)上,对本 PR 实际提交树完成干净构建:
mvn -B -T1C -pl agentscope-core -am clean test spotless:check本地使用 Maven Central settings 和离线缓存;结果:
git diff --check通过。verify;以上是本地验证,不代表上游 CI 已通过。范围边界
本修复确保成功写出的取消 checkpoint 保留本轮已确认结果,不承诺任意进程崩溃下的 exactly-once,也不迁移或修复已经产生的受损日志。hard cancellation 不保证协作中断回复/保存路径的现有契约不变。
Checklist
agentscope-core测试通过,条件跳过与未执行的全仓验证已在上面明确列出。