wenjin272 opened a new pull request, #1448:
URL: https://github.com/apache/flink-agents/pull/1448
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.
#### Runtime flow
```text
close()
-> stop the worker pool from taking queued work
-> cancel tracked submissions
-> wait for workers and their cleanup to finish
gather wait times out
-> remember that the wait expired
-> collect calls that have already completed
-> prevent unfinished calls from starting, then cancel them
-> collect the remaining outcomes
```
#### Key decisions
- Stop the pool before cancelling submissions. Cancelling a running Future
first can free a worker while queued tasks are still eligible to run.
- Treat a timeout from the wait as an explicit scheduler signal, preserving
the completion sweep before cancellation.
- Drive timeout unit tests after the required calls have started. Keep real
deadline coverage in the operator test, which starts the child before timing
its wait.
- Check lifecycle notification ordering and pairing without requiring a
fixed number of handoffs. Remove minimum remote-poll counts; reconciliation
accepts an existing task that has already completed.
### Behavioral Semantics
#### Interaction decisions
| Condition | Handling |
|---|---|
| Worker is occupied and another call is queued during shutdown | Stop the
pool before cancellation can free the worker; cancel the queued submission. |
| Callable reacts to the shutdown interrupt before its Future is cancelled |
Exceptional completion is valid; closing still waits for worker cleanup. |
| Call completes before timeout cancellation wins | Keep its actual outcome.
|
| Durable call has not started when the batch times out | Return a timeout
outcome and leave its durable slot pending for replay. |
| Started subgraph emits events after its caller times out | Existing
cancellation handling discards late events and retires the scheduled actions. |
#### 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
| Contract | Coverage |
|---|---|
| Shutdown cancels queued work and waits for cleanup |
`AsyncBatchExecutorTest.closeCancelsSubmissionsAndWaitsForManagedThreadCleanup`
|
| Completed results survive a batch timeout |
`JavaRunnerContextImplDurableExecuteAsyncTest.testGatherTimeoutKeepsCompletedOutcomes`;
`MixedFutureGatherTest` completion-versus-cancellation cases |
| Unstarted durable calls remain replayable | Durable async tests for
unsubmitted and queued calls, including the real fallback executor |
| Late subgraph events do not fail the operator | `SubgraphTimeoutTest`, for
chat and internal subagents |
| Recovery restores lifecycle notifications in valid order |
`TaskLifecycleListenerNotificationTest` |
| External subagent results and idempotent reconciliation remain correct |
`ExternalAgentSubagentSetupTest` against the local HTTP stub |
The six affected test classes passed after clean rebuilds:
| JDK | Passed | Conditionally skipped |
|---|---:|---:|
| 11 | 86 | 16 |
| 17 | 86 | 16 |
| 21 | 104 | 4 |
Spotless and `git diff --check` passed. Full-reactor tests,
Python/cross-language suites, and a live external agent service were not rerun.
<details>
<summary>Test synchronization details</summary>
- The lifecycle suspension fixture releases its callable from the transfer
notification; restore assertions allow varying numbers of paired
transfer/prepared notifications.
- Timeout unit fixtures disable the wall-clock deadline and inject a wait
timeout after explicit startup/completion signals. This exercises the
production scheduler's timeout handling without a 250–1000 ms startup
assumption.
- The late-event operator fixture starts the graph and waits for the child
to enter before invoking timed gather. The child remains blocked until the
caller has returned from gather.
- Shutdown assertions accept interruption winning the race with explicit
Future cancellation, while still checking that queued callable bodies do not
execute.
</details>
### 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-needed`
- [x] `doc-not-needed`
- [ ] `doc-included`
### Was this patch authored or co-authored using generative AI tooling?
- [x] Yes
- [ ] No
Generated-by: Codex CLI 0.153.4 (GPT-6; exact model version unavailable)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]