Repository navigation
test: deflake four single-OS CI failure classes under -T1C contention - #4435
Merged
xzxiaoshan merged 1 commit intoNov 26, 2026
Merged
Conversation
## Background Swept the last 125 PRs (agentscope-ai#4434→agentscope-ai#4239), every single-OS-failed CI run since 2026-11-19 and the main-branch push runs for `mvn -B -T1C clean verify` failures (one build OS red and the other green on the same commit = flake suspect). Four test classes still fail on current main: three fail on windows-latest only, and the fourth sits at its deadline on both OSes. All fixes are test-side only (no `src/main` changes). ## Fixes and evidence | Test class | Victims | Signature | Fix | |---|---|---|---| | `HarnessAgentStructuredOutputStreamEventsTest` | agentscope-ai#4296, agentscope-ai#4349, agentscope-ai#4071, main run 44879286932 (2026-11-20 to 11-23), all windows-latest | `streamEvents(...).block(10s)` timed out at 10.2-11.3s per call; the class takes 3.7-9.6s on windows-latest when green and 1-1.5s on ubuntu | ephemeral `InMemoryThreadJournalStore` in the three workspace-backed tests (the fourth already used one) | | `HarnessAgentOverflowRecoveryTest` | agentscope-ai#4042, agentscope-ai#4426 (2026-11-26), both windows-latest; the journal rows were added by agentscope-ai#4399 on 11-25 | row `[3]` (journal=true) crossed `block(30s)` at 36.3-38.1s and row `[4]` passed with 33.8s; the same rows take 0.4-1.3s on ubuntu, and main's own run 45595615922 needed 61s for the class on windows-latest | ephemeral `InMemoryThreadJournalStore` in `newAgent` | | `DashScopeMultiModalEmbeddingTest` | agentscope-ai#4413 (2026-11-25), windows-latest | the first SDK request in the fork hit the 5s latch (7.29s elapsed); the class takes 1.4-4.2s on windows-latest even when green | first-request latch 5s→15s | | `AnthropicAutoConfigurationTest` | agentscope-ai#2363, run 45137197507 (2026-11-23), windows-latest | the first gateway test crossed `block(10s)` at 15.66s; the other three take under 1s, and this one already takes 5-11s on windows-latest and 9-12s on ubuntu when green | block 10s→30s | The first two share one cause: since agentscope-ai#4154 the default workspace journal is `SqliteJournalStorage` on Windows, which opens a JDBC connection per storage operation and commits every CAS as a durable transaction (DELETE journal, synchronous EXTRA). A journaled turn issues about 20 such writes at roughly 8ms each on a fast local disk. Neither class asserts journal persistence, so they now use the ephemeral backend the repository already documents for tests. Locally on Windows the overflow-recovery class dropped from 17.9s to 5.6s and the structured-output class from 3.2s to 1.6s. ## Constraint compliance - Happy path zero cost: the journal swap removes work, the two relaxations only move failure deadlines, and no sleeps or weakened assertions were added. - Structural hardening first: the journal swap is structural. For the two cold-start waits the structural alternative, a warm-up request before the timed section, would add a request to every run, so the deadline was relaxed instead. - Minimal widening anchored to measured data: each relaxation is 3x the deadline that was crossed, and every comment cites its victims and measured values. - No `src/main` changes. ## Observed but deliberately not fixed here - `WorkerRuntimeTest.saturatedStartsDoNotBlockRecoveryAndDrainPreservesActiveLeases` (agentscope-ai#4294, windows-latest, 36.19s at the `renewed` latch): with the test's 4s worker lease a heartbeat delayed by more than 2.7s finds the lease already expired and fails with `Worker lease lost` instead of arriving late, so widening the latch (as agentscope-ai#4274 did to 30s) cannot help. That latch is the only place asserting the runtime renews leases, and a longer lease would delay the first heartbeat by lease/3, so the fix needs a design decision. - `SubagentFactoryDeclarationTest.declaredFactory_persistSessionIsolatesUsers` (main run 45172445003, 2026-11-23, 31.45s) and `ChatControllerTest.httpUsesExplicitCreationAndTargetedIdempotentControls` (main run 44566773929 and agentscope-ai#4255, both 2026-11-19): no recurrence since. - Two windows-latest hangs that ended at the 2h job timeout: `AgentSpawnToolPermissionTest` (agentscope-ai#4305, run 44760439728) and `AgentSpawnToolPlanModeTest` (main run 45739005058 on the current head). Both classes wait with unbounded `.block()`; the root cause is not established, and the 30-minute Surefire fork timeout in the root pom did not end either run. - The cost of the Windows default journal itself (one JDBC connection and one durable transaction per storage operation) is a production concern that deserves its own `src/main` change. - Already fixed upstream, victims predate the fix: `JevEvidenceProcessorTest` (13 runs, fixed by agentscope-ai#4346), `ChatSessionsTest`, `RocketMqExecutionTest` and `AgentScopeAdapterTest` (fixed by agentscope-ai#4274).
jujn
approved these changes
Nov 26, 2026
z43460018724
added a commit
to z43460018724/agentscope-java
that referenced
this pull request
Nov 28, 2026
…6ff9e, pull in agentscope-ai#4435 deflake + harness fixes)
5 tasks done
juruoO-o
pushed a commit
that referenced
this pull request
Dec 2, 2026
…() returns (#4509) ## Problem `JdbcRecordStore.close()` only flipped an `AtomicBoolean` and returned immediately: ```java /** Prevents new operations; existing borrowed connections finish and return normally. */ @OverRide public void close() { closed.set(true); } ``` Nothing enforced the javadoc's claim. Every operation borrows a fresh connection through `connect()`, and nothing bounds how long a `store.transaction(...)` may hold one — the caller's action, `synchronous=FULL` fsyncs, and up to 10 seconds of SQLite lock waiting all run on that borrow. So `close()` could return while a write was still in flight, leaving an open SQLite file handle behind. On Windows that surfaces as JUnit `@TempDir` teardown failure, because `unlink` on an open handle succeeds on POSIX but not there. This turned `main` red three times: | Date | Run | Failing method | | --- | --- | --- | | 2026-11-19 | `44566773929` | `httpUsesExplicitCreationAndTargetedIdempotentControls` | | 2026-11-28 | `46179100442` / `46098902103` | (see runs) | | 2026-11-29 | `46231881667` (job `141249277724`) | `toolOutputPreviewIsDeliveredWithoutAdvancingTheSessionCursor` | ``` org.junit.platform.commons.JUnitException: Failed to close extension context Caused by: java.io.IOException: Failed to delete temp directory ...\junit-... The following paths could not be deleted: <root>, preview, preview\durable, preview\durable\durable.db ``` Only `durable.db` resists deletion while the sibling `stateHome` `@TempDir` deletes cleanly, which pins the holder to this class. #4435 listed this exact failure under *"Observed but deliberately not fixed here"* with the note *"no recurrence since"*. It has recurred — the 2026-11-29 run above hit a different victim method. ## Change Track in-flight borrowed connections and have `close()` wait for them, mirroring the already-merged `MemoryBackgroundTasks.awaitQuiescence` from #2935 (which fixed the same bug class for harness memory flushes). Counting lives entirely in `connect()`, the single point every caller funnels through — the constructor, `transaction()`, `ready()` and `keys()`. `connect()` now rejects-or-counts atomically under a monitor, and returns a `Proxy` over the real `Connection` that counts down when the caller closes it. All four call sites already use try-with-resources, so no call site changed and the counter cannot leak on a failure path. `close()` sets the flag, then waits up to 5s for the count to reach zero, logging a `WARNING` (not throwing) if it times out or is interrupted. This is a **bounded best-effort drain, not a guarantee**: nothing bounds how long an operation already in flight may take, so a durable write can outlive `close()`. A returned `close()` is therefore not proof that every handle is released, and callers must not delete the underlying files on the strength of it. The javadoc on `close()` says this explicitly. The 5s budget bounds *this store's drain only*. It is independent of the 5s that `DurableRuntime.close()` spends awaiting `observers`/`timer`/`workers` (`DurableRuntime.java:1163-1172`) before leaving backends to the caller (`:1184`), so a host closing runtime then store sequentially pays up to twice it. Two details worth calling out: - The proxy's `close()` is idempotent via `compareAndSet`. JDBC specifies that closing an already-closed connection is a no-op, and `Connections` is a public interface — a caller may pass a pool that calls `close()` twice. Counting the same borrow twice would steal another borrow's slot and let `close()` return early, reintroducing exactly the leak this fixes. - The proxy never escapes the class: `RecordStore.Transaction` exposes only `now()`/`get()`/`put()`/`keys()`/`schedule()`, never the `Connection`, so no caller can observe the narrowed type or hit the proxy's identity semantics. The logging uses `System.Logger`, already the convention in this module (`PostgresBackend`), so no dependency is added. ## Test `JdbcRecordStoreCloseTest` (new, 4 cases) asserts quiescence directly rather than file-deletability, which is unobservable on POSIX: - `closeWaitsForAnInFlightTransactionToReturnItsConnection` — a transaction started on another thread holds the connection open for 400ms; `close()` must not return before the write commits, and must return promptly (asserting the drain budget is not merely what masks the failure). The write is then re-read through a fresh store to prove it actually landed. - `closeReturnsOnTimeoutWithABorrowStillInFlight` — covers the documented limitation. A transaction holds the borrow past the drain budget; `close()` is asserted bounded in both directions (returns after `>= DRAIN_TIMEOUT_MILLIS`, not before the write finishes at `< +3s`), the write is still in flight when `close()` returns, and the abandoned write still lands durably afterwards. - `closeStillRejectsOperationsStartedAfterIt` — the existing `IllegalStateException` contract is preserved. - `repeatedCloseDoesNotBlock` — double close stays cheap. Per AGENTS.md §3 the test mirrors the production guard instead of weakening an assertion for a Windows-only flake. No `@Disabled`, no OS gating, no widened `ChatControllerTest` timeout, no sleep-based deflake, no surefire rerun, and `LocalBackend` is untouched. Mutation-verified — each injected defect is caught: | Mutation | Result | | --- | --- | | `close()` does not wait (original behaviour) | caught, 1 failure | | `endBorrow()` does not decrement (count never reaches zero) | caught, 1 failure | | `endBorrow()` does not `notifyAll()` (lost wakeup) | caught, 1 failure | | `connect()` does not increment (count stuck at zero) | caught, 1 failure | | timeout path loops instead of returning (`close()` never gives up) | caught, upper-bound assertion trips at 8188ms | | timeout path throws instead of returning | caught, 1 error | ## Verification Run on macOS 14, JDK 17.0.18, Maven 3.9.12. ``` mvn -pl agentscope-extensions/agentscope-extensions-durable-jdbc -am test → Tests run: 134, Failures: 0, Errors: 0, Skipped: 0 (includes the 68-case contract suite) mvn -pl agentscope-durable/durable-runtime test → Tests run: 48, Failures: 0, Errors: 0, Skipped: 0 mvn -pl agentscope-durable/durable-adapters/durable-adapter-harness-agentscope -am test → Tests run: 594, Failures: 0, Errors: 0, Skipped: 11 (pre-existing gating) → Tests run: 120, Failures: 0, Errors: 0, Skipped: 0 mvn -pl agentscope-examples/agents/agentscope-chat test → Tests run: 14, Failures: 0, Errors: 0, Skipped: 0 (includes ChatControllerTest) mvn -pl agentscope-examples/agents/agentscope-chat test -Dtest=ChatControllerTest (x32 rounds) → 32/32 green mvn -pl agentscope-extensions/agentscope-extensions-durable-jdbc -am spotless:check → BUILD SUCCESS mvn -pl agentscope-extensions/agentscope-extensions-durable-jdbc javadoc:javadoc → BUILD SUCCESS (doclint=all,-missing) ``` The new timeout case sleeps out the real 5s drain budget, so `JdbcRecordStoreCloseTest` goes 1.1s → 9.3s and the module suite grows by ~8s. I pinned the test to the production constant (`private` → package-private, reason in its javadoc) rather than adding a shrink-the-budget constructor, because the budget value is exactly what the review raised. RED confirmed first: on unmodified `main` the quiescence assertion fails at `JdbcRecordStoreCloseTest.java:87` with `close() returned while a transaction still held a borrowed connection`. Unrelated pre-existing flake observed while re-running the module: `DurableUserApiTest.committedEventOutboxReusesEventIdentityAfterFailedDeliveryAndReopen:92`. Baseline on pristine `main` (`9e9fa9f95`): 2 failures / 14 full-suite runs; on this branch: 1 / 14; single-test 20/20 green. The case passes `retryDelay = 1ms` while `now` comes from SQLite `julianday` truncated to milliseconds (`JdbcRecordStore.java:289-299`), so `deliver()`'s `dueAt > now` check races the clock's own resolution. Out of scope here. **The definitive confirmation can only come from the `windows-latest` matrix job.** The leak is equally present on Ubuntu but symptomless there, since POSIX `unlink` succeeds on an open handle. Failure rate on Windows before the fix was roughly 2/10. ## Scope notes Deliberately not included: - **No `docs/dev` update**, although AGENTS.md §5 would normally call for one. Both #4221 and #4217 currently modify `docs/dev/{en,zh}/docs/harness/durable.md`; editing it here would collide. Happy to follow up once one of them merges. - **`DurableRuntime.close()`'s single shared 5s budget** across `observers`/`timer`/`workers` (`DurableRuntime.java:1163-1172`) is a second, independent contributor to this flake: the last executor in the list can receive a zero budget. That is separable and I left it out to keep this PR focused. This change already covers it in practice, because all four pools reach SQLite through `connect()`. - The diff touches only imports, two fields, `connect()` and `close()`. `transaction()`, `ready()`, `keys()` and the constructor bodies are untouched, so this does not conflict with #4221 or #4217 beyond line-number drift. Related but distinct: #4337 covers the same bug class for `journal.sqlite3` in a different module. ## Checklist - [x] Tests added for the fixed behaviour - [x] `spotless:check` passes - [x] No public API change - [x] No new dependency - [x] EN/ZH docs — see scope note above (intentionally deferred)
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.
Background
Swept the last 125 PRs (#4434→#4239), every single-OS-failed CI run since 2026-11-19 and the main-branch push runs for
mvn -B -T1C clean verifyfailures (one build OS red and the other green on the same commit = flake suspect). Four test classes still fail on current main: three fail on windows-latest only, and the fourth sits at its deadline on both OSes. All fixes are test-side only (nosrc/mainchanges).Fixes and evidence
HarnessAgentStructuredOutputStreamEventsTeststreamEvents(...).block(10s)timed out at 10.2-11.3s per call; the class takes 3.7-9.6s on windows-latest when green and 1-1.5s on ubuntuInMemoryThreadJournalStorein the three workspace-backed tests (the fourth already used one)HarnessAgentOverflowRecoveryTest[3](journal=true) crossedblock(30s)at 36.3-38.1s and row[4]passed with 33.8s; the same rows take 0.4-1.3s on ubuntu, and main's own run 45595615922 needed 61s for the class on windows-latestInMemoryThreadJournalStoreinnewAgentDashScopeMultiModalEmbeddingTestAnthropicAutoConfigurationTestblock(10s)at 15.66s; the other three take under 1s, and this one already takes 5-11s on windows-latest and 9-12s on ubuntu when greenThe first two share one cause: since #4154 the default workspace journal is
SqliteJournalStorageon Windows, which opens a JDBC connection per storage operation and commits every CAS as a durable transaction (DELETE journal, synchronous EXTRA). A journaled turn issues about 20 such writes at roughly 8ms each on a fast local disk. Neither class asserts journal persistence, so they now use the ephemeral backend the repository already documents for tests. Locally on Windows the overflow-recovery class dropped from 17.9s to 5.6s and the structured-output class from 3.2s to 1.6s.Constraint compliance
src/mainchanges.Observed but deliberately not fixed here
WorkerRuntimeTest.saturatedStartsDoNotBlockRecoveryAndDrainPreservesActiveLeases(feat(core): evictable/prunable tool metadata replaces exclusion name lists #4294, windows-latest, 36.19s at therenewedlatch): with the test's 4s worker lease a heartbeat delayed by more than 2.7s finds the lease already expired and fails withWorker lease lostinstead of arriving late, so widening the latch (as test: deflake five single-OS CI failure classes under -T1C contention #4274 did to 30s) cannot help. That latch is the only place asserting the runtime renews leases, and a longer lease would delay the first heartbeat by lease/3, so the fix needs a design decision.SubagentFactoryDeclarationTest.declaredFactory_persistSessionIsolatesUsers(main run 45172445003, 2026-11-23, 31.45s) andChatControllerTest.httpUsesExplicitCreationAndTargetedIdempotentControls(main run 44566773929 and fix(durable): finish AG-UI runs when a turn waits for interaction #4255, both 2026-11-19): no recurrence since.AgentSpawnToolPermissionTest(fix(dashscope): preserve AudioBlock in merged text conversation history #4305, run 44760439728) andAgentSpawnToolPlanModeTest(main run 45739005058 on the current head). Both classes wait with unbounded.block(); the root cause is not established, and the 30-minute Surefire fork timeout in the root pom did not end either run.src/mainchange.JevEvidenceProcessorTest(13 runs, fixed by test(jev): absorb CI scheduler stalls in evidence processor test budget #4346),ChatSessionsTest,RocketMqExecutionTestandAgentScopeAdapterTest(fixed by test: deflake five single-OS CI failure classes under -T1C contention #4274).