Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void httpUsesExplicitCreationAndTargetedIdempotentControls() throws Exception {
new ChatSessions(
workspace,
new DemoChatModel(Duration.ofMillis(2), Duration.ofMillis(10)))) {
var web = WebTestClient.bindToController(new ChatController(sessions)).build();
var web = webClient(new ChatController(sessions));
web.get().uri("/api/sessions/conversation").exchange().expectStatus().isNotFound();
assertTrue(sessions.list().isEmpty());
web.post().uri("/api/sessions/conversation").exchange().expectStatus().isOk();
Expand Down Expand Up @@ -188,7 +188,7 @@ void sseUsesReconnectHeaderAndDisconnectDoesNotCancelTask() throws Exception {
assertEquals(turn, payload.path("turnId").asText());
ChatSessionsTest.await(
sessions, s -> ChatSessionsTest.status(s, turn) == TurnStatus.SUCCEEDED);
var web = WebTestClient.bindToController(controller).build();
var web = webClient(controller);
web.get()
.uri("/api/sessions/conversation/events?after=invalid")
.accept(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -221,4 +221,18 @@ void toolOutputPreviewIsDeliveredWithoutAdvancingTheSessionCursor() throws Excep
assertFalse(delta.path("data").path("data").asText().isBlank());
}
}

/**
* Every exchange that reaches the store borrows a SQLite connection with {@code
* busy_timeout}=10s and commits its writes durably, so WebTestClient's default 5s response
* timeout is below the store's own budget: #4481 (2026-11-28, windows-latest) crossed it on the
* idempotent replay, 6.61s for the test against 1.45-6.00s when green on windows-latest
* (0.45-2.30s on ubuntu).
*/
private static WebTestClient webClient(ChatController controller) {
return WebTestClient.bindToController(controller)
.configureClient()
.responseTimeout(Duration.ofSeconds(15))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.agentscope.core.agent.test.MockModel;
import io.agentscope.core.event.AgentResultEvent;
import io.agentscope.core.event.ConfirmResult;
import io.agentscope.core.journal.InMemoryThreadJournalStore;
import io.agentscope.core.message.GenerateReason;
import io.agentscope.core.message.Msg;
import io.agentscope.core.message.MsgRole;
Expand Down Expand Up @@ -62,6 +63,18 @@
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

/**
* Every HarnessAgent in this class uses an ephemeral {@link InMemoryThreadJournalStore}. The tests
* assert agent behavior over the native Thread journal (compaction, background delivery, skill
* loading, spawn and resume, tool visibility), not its persistence backend, and the default
* workspace journal is SQLite on Windows: one connection and one durable transaction per storage
* operation costs the journal-enabled rows of the two parameterized tests 0.7-4.3s there against
* 0.01-0.05s for the journal-disabled rows (0.18-0.72s and 0.05-0.21s on ubuntu). Under -T1C load
* journaled invocations stopped finishing within their {@code block} deadlines (Surefire elapsed up
* to 15.56s) in ten windows-latest runs between 2026-11-26 and 2026-12-02 (#4102, #4470, #4499,
* #4508, #4509, #4441, #4515, #4541, #4551, #4213) while the journal-disabled rows stayed at
* 0.01-0.47s.
*/
class HarnessContextRegressionTest {
@TempDir Path workspace;
private final String dynamicSession = UUID.randomUUID().toString();
Expand Down Expand Up @@ -107,6 +120,7 @@ void ordinaryCompactionKeepsTheLatestUserMessageAfterSeveralToolSteps() {
try (var agent =
HarnessAgent.builder()
.workspace(workspace)
.threadJournalStore(new InMemoryThreadJournalStore())
.model(model)
.toolkit(toolkit)
.disableDefaultWorkspaceSkills()
Expand Down Expand Up @@ -231,6 +245,7 @@ && new String(file.getValue(), StandardCharsets.UTF_8)
.abstractFilesystem(filesystem)
.messageBus(bus)
.journalEnabled(journalEnabled)
.threadJournalStore(new InMemoryThreadJournalStore())
.model(model)
.disableDefaultWorkspaceSkills()
.compaction(
Expand Down Expand Up @@ -335,6 +350,7 @@ void newSubagentResultIsReadableByLegacyInbox() {
var sender =
HarnessAgent.builder()
.workspace(workspace)
.threadJournalStore(new InMemoryThreadJournalStore())
.abstractFilesystem(filesystem)
.messageBus(bus)
.model(new MockModel("unused"))
Expand Down Expand Up @@ -434,6 +450,7 @@ void smallSkillCatalogSupportsDirectLoading(boolean dynamicSkills) throws Except
HarnessAgent.builder()
.model(model)
.workspace(workspace)
.threadJournalStore(new InMemoryThreadJournalStore())
.abstractFilesystem(new LocalFilesystem(workspace))
.disableSubagents()
.disableCompaction();
Expand Down Expand Up @@ -526,6 +543,7 @@ void compactionFlushRequiresMemoryOptIn(
.workspace(workspace)
.abstractFilesystem(new LocalFilesystem(workspace))
.journalEnabled(journal)
.threadJournalStore(new InMemoryThreadJournalStore())
.disableDefaultWorkspaceSkills()
.disableMemoryHooks()
.compaction(
Expand Down Expand Up @@ -609,6 +627,7 @@ void dynamicSpawnResumesInNewRuntimeContext(boolean allow) throws Exception {
try (var agent =
HarnessAgent.builder()
.workspace(workspace)
.threadJournalStore(new InMemoryThreadJournalStore())
.model(model)
.abstractFilesystem(new LocalFilesystem(workspace))
.disableDefaultWorkspaceSkills()
Expand Down Expand Up @@ -657,6 +676,7 @@ void memoryToolVisibilityInheritedByBothFactories(boolean memory, boolean disabl
HarnessAgent.builder()
.model(new MockModel("ok"))
.workspace(workspace)
.threadJournalStore(new InMemoryThreadJournalStore())
.disableDefaultWorkspaceSkills()
.disableMemoryHooks();
if (memory) builder.enableLongTermMemory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardWatchEventKinds;
import java.security.DigestInputStream;
import java.security.MessageDigest;
Expand Down Expand Up @@ -577,6 +578,7 @@ void execute_interruptTerminatesLocalProcessTreeAndDrainers(@TempDir Path tempDi
worker.interrupt();
worker.join(TimeUnit.SECONDS.toMillis(60));
}
awaitDirectoryReleased(tempDir);
}

@Test
Expand All @@ -598,6 +600,7 @@ void execute_timeoutTerminatesLocalParentAndChild(@TempDir Path tempDir) throws
ProcessHandle.of(pid).ifPresent(ProcessHandle::destroyForcibly);
}
}
awaitDirectoryReleased(tempDir);
}

@Test
Expand Down Expand Up @@ -642,6 +645,35 @@ void execute_reactorCancellationInterruptsAndCleansLocalTree(@TempDir Path tempD
}
scheduler.dispose();
}
awaitDirectoryReleased(tempDir);
}

/**
* On Windows a forcibly terminated process reports as dead before its working-directory handle
* is released, and the fixture processes above run with the temp directory as their working
* directory, so JUnit's deletion of that directory right after the test can fail with "being
* used by another process" while a killed JVM is still being torn down: #4523 and main run
* 46571815777, both windows-latest on 2026-12-01, one sibling test each. Renaming the directory
* is refused by the same hold, so poll it instead of sleeping; the first attempt succeeds
* unless the hold is still open.
*/
private static void awaitDirectoryReleased(Path directory)
throws IOException, InterruptedException {
Path probe = directory.resolveSibling(directory.getFileName() + ".release-probe");
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(60);
while (true) {
try {
Files.move(directory, probe, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException stillHeld) {
assertTrue(
System.nanoTime() < deadline,
"workspace still in use after cleanup: " + stillHeld);
Thread.sleep(20);
continue;
}
Files.move(probe, directory, StandardCopyOption.ATOMIC_MOVE);
return;
}
}

private static void assertProcessesStopped(List<Long> pids, Set<String> existingDrainers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import io.agentscope.core.agent.RuntimeContext;
import io.agentscope.core.event.AgentResultEvent;
import io.agentscope.core.journal.InMemoryThreadJournalStore;
import io.agentscope.core.message.Msg;
import io.agentscope.core.message.MsgRole;
import io.agentscope.core.message.TextBlock;
Expand Down Expand Up @@ -56,6 +57,12 @@

class HarnessGatewayEventPublicationTest {

/**
* The agent runs on an ephemeral {@link InMemoryThreadJournalStore}: the test asserts gateway
* wakeup semantics, not journal persistence, and the default workspace journal is SQLite on
* Windows, where this test took 0.99-8.67s when green against 0.15-0.32s on ubuntu, and #2871
* (2026-12-01, windows-latest) crossed {@code turn.get(5s)}.
*/
@Test
void completionsDuringTheFinalModelCallWakeOnceAfterTheTurn(@TempDir java.nio.file.Path dir)
throws Exception {
Expand Down Expand Up @@ -101,6 +108,7 @@ public Flux<ChatResponse> stream(
.name("main")
.model(model)
.workspace(dir.resolve("agent"))
.threadJournalStore(new InMemoryThreadJournalStore())
.messageBus(bus)
.disableSubagents()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -678,10 +679,15 @@ public boolean cancelTask(RuntimeContext rc, String sessionId, String taskId) {
}
}

/**
* The completer thread appends while the tool thread polls this list from {@code getTask()}, so
* a plain {@link ArrayList} threw ConcurrentModificationException in #4471 (2026-11-28), #4395
* and main run 46441604698 (both 2026-11-30), all windows-latest.
*/
private static class MutableTaskRepository extends StubTaskRepository {

MutableTaskRepository(List<BackgroundTask> tasks) {
super(new ArrayList<>(tasks));
super(new CopyOnWriteArrayList<>(tasks));
}

void add(BackgroundTask task) {
Expand Down
Loading