Skip to content

Flaky on Windows: HarnessAgent stream/observation tests exceed block() timeout and leak SQLite journal handle, breaking @TempDir cleanup #4337

Open

Description

@blueice1986

Summary

On Windows, HarnessAgentStructuredOutputStreamEventsTest (3 of 4 tests) and
HarnessActionObservationTest.defaultHarnessPersistsBeforePublishingSettledEvent intermittently
fail with:

java.lang.IllegalStateException: Timeout on blocking read for 10000000000 NANOSECONDS
    at reactor.core.publisher.BlockingSingleSubscriber.blockingGet

and the same error carries a suppressed cleanup chain:

Suppressed: org.junit.platform.commons.JUnitException: Failed to close extension context
Caused by: java.io.IOException: Failed to delete temp directory ...\junit-...
  ... .agentscope-runtime\journal.sqlite3, .agentscope-runtime\journal.sqlite3-journal
Suppressed: java.nio.file.FileSystemException: ...journal.sqlite3:
  另一个程序正在使用此文件,进程无法访问。 (file in use by another process)

Failing tests observed:

Test Block timeout
HarnessAgentStructuredOutputStreamEventsTest.msgAndStringConvenienceOverloads_delegateStructuredOutput 10s
HarnessAgentStructuredOutputStreamEventsTest.jsonNodeOverload_delegatesStructuredOutput 10s
HarnessAgentStructuredOutputStreamEventsTest.classOverload_delegatesStructuredOutput 10s
observation.HarnessActionObservationTest.defaultHarnessPersistsBeforePublishingSettledEvent 20s

Environment

  • Windows 10 (reproduced locally) + windows-latest in the CI matrix (.github/workflows/maven-ci.yml)
  • Module: agentscope-harness
  • JDK 17/21

Reproduction rate

Fails in ~2 of 3 observed full/partial module runs; within the same test class some tests pass
while siblings time out (e.g. sandboxBackedStreamEvents_acquiresAndReleasesExactlyOncePerSubscription
passed in a run where three sibling tests timed out) — load sensitivity, not a deterministic break.
The same signature appeared independently in two separate runs.

Root cause analysis (code-level)

  1. Windows-only SQLite journal backend: LocalJournalStorage.java:55-58 selects
    SqliteJournalStorage only when separator().equals("\\") (Linux/mac use plain files).
  2. Write cost: SqliteJournalStorage.java:60-69 opens a connection per write with
    JournalMode.DELETE rollback-journal, synchronous FULL/EXTRA fsync, and
    busyTimeout(10_000) — a single write can take seconds under load; a cancelled block()
    can leave an in-flight write connection holding journal.sqlite3 / journal.sqlite3-journal.
  3. Test-side: both test classes use @TempDir Path workspace and
    block(Duration.ofSeconds(10/20)) but have no @AfterEach / agent.close() — after a
    timeout nobody releases the SQLite handle.
  4. Windows cannot delete open files, so JUnit's @TempDir cleanup throws the suppressed
    FileSystemException. On Linux this surfaces only as the timeout, never as the file-lock
    error — a pure Windows shape.

CI impact

windows-latest runs these tests (the durable-module skip flag does not apply here), so this
produces intermittent red CI on GitHub-hosted Windows runners (slower, and checkout/temp on
different drives).

Suggested direction (maintainer's call)

  • Close the agent in these tests (@AfterEach) so the journal handle is always released, and/or
  • make the stream-event tests robust for slow hosts (larger/awaitility-style block waits), and/or
  • cover the Windows SQLite guard in a smaller focused unit test instead of full streaming runs —
    per AGENTS.md, without weakening assertions.

Activity

  1. k65010825-ship-it commented on Nov 23, 2026

    @k65010825-ship-it

    I'd like to investigate this on Windows. The four reported tests already use try-with-resources on current main, so I'll start by reproducing the timeout and checking whether in-flight SQLite writes keep the journal files open after cancellation. If I can isolate the cause, I'll propose a focused regression test.

  2. blueice1986 commented on Nov 25, 2026

    @blueice1986
    ContributorAuthor

    Thanks for picking this up! The reproduction details (full stacks with the suppressed @tempdir cleanup chain, failure rate across runs, and the Windows-only SQLite journal mechanism at LocalJournalStorage.java:55-58 / SqliteJournalStorage.java:60-69) are all in the issue body. Happy to provide additional run logs if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions