Repository navigation
[runtime][java] Fix async shutdown ordering and stabilize scheduling tests - #1448
Conversation
2de6665 to
41ad17b
Compare
| assertThat(runningInterrupted.getCount()).isZero(); | ||
| // shutdownNow may interrupt the callable before its result is explicitly cancelled. | ||
| assertThat(running.isCompletedExceptionally()).isTrue(); | ||
| assertThat(queued.isCancelled()).isTrue(); |
There was a problem hiding this comment.
Would it make sense to move the queued.isCancelled() and queuedCalls assertions just after closing.get(...)? I checked this locally by adding a latch immediately after shutdownNow() to pause the thread running close(). Once the worker signalled cleanupStarted, queued.isCancelled() was still false. After I released the latch and close() returned, it was true.
Checking those two assertions after closing.get(...) would avoid depending on which thread gets scheduled first. The closing.isDone() check can stay before releaseCleanup.countDown() to verify that close() waits for cleanup.
…tests Stop the worker pool before cancelling tracked submissions. Stabilize tests by establishing call state before timed gather, checking lifecycle pairing, and removing fixed polling-count assumptions. Keep the gather scheduler unchanged. Generated-by: Codex CLI 0.153.4 (GPT-6; exact model version unavailable) Co-authored-by: Codex <codex@openai.com>
41ad17b to
8ea2484
Compare
eemario
left a comment
There was a problem hiding this comment.
Thanks for the update! Moving the queued-task assertions after closing.get(...) addresses my concern. The test still verifies that close() waits for worker cleanup. LGTM.
Linked issue: Fixes #1447
Purpose of change
Outcome
Stop queued async calls from starting when cancellation frees a worker during executor shutdown. Stabilize the Java async tests while retaining recovery, cancellation, and late-subgraph-event coverage. The only production change is executor shutdown ordering; the gather scheduler is unchanged.
Runtime flow
Key decisions
Behavioral Semantics
Interaction decisions
Behavioral contracts
Shutdown stops queued work from being picked up as a consequence of cancelling running submissions, and
close()waits for worker exit cleanup. Batch timeout handling preserves available outcomes and leaves unstarted durable calls replayable. The remaining changes adjust test synchronization and assertions without changing these contracts.Failure behavior
Running work is interrupted during shutdown; its Future may be cancelled or complete exceptionally. Unfinished batch calls receive timeout outcomes. Ordinary call failures retain the existing result-recording behavior, while fatal/framework failures continue to propagate. No new retry or fallback behavior is introduced.
Tests
AsyncBatchExecutorTest.closeCancelsSubmissionsAndWaitsForManagedThreadCleanupJavaRunnerContextImplDurableExecuteAsyncTest.testGatherTimeoutKeepsCompletedOutcomes;MixedFutureGatherTestcompletion-versus-cancellation casesSubgraphTimeoutTest, for chat and internal subagentsTaskLifecycleListenerNotificationTestExternalAgentSubagentSetupTestagainst the local HTTP stubThe six affected test classes passed after clean rebuilds:
Spotless and
git diff --checkpassed. Full-reactor tests, Python/cross-language suites, and a live external agent service were not rerun.Test synchronization details
start(), avoiding duplicate submission. Latches establish which suppliers are running; remaining calls are either queued in the real pool or left unsubmitted. Gather then reaches its real deadline.API
No public API, configuration, or persisted-state format changes. Implementation and test changes are confined to Java; Python and YAML APIs are unchanged.
Documentation
doc-neededdoc-not-neededdoc-includedWas this patch authored or co-authored using generative AI tooling?
Generated-by: Codex CLI 0.153.4 (GPT-6; exact model version unavailable)