wenjin272 opened a new pull request, #1456:
URL: https://github.com/apache/flink-agents/pull/1456

   Linked issue: #1338. Python follow-up to #1348.
   
   ### Purpose of change
   
   Python gather supports ordinary, durable, Chat and built-in subagent calls. 
Await and `combine` share its scheduler. Runtime `SubagentTool` owns 
submission/conversion, simplifying `ToolCallAction`.
   
   #### Runtime flow
   
   ```text
   execute_async        -> SingleAsyncFuture --------+
   durable_execute_async -> SingleDurableFuture -----+
   chat / internal agent -> SubgraphFuture ----------+--> single await / gather
   external agent        -> SubagentFutureImpl ------+           |
                            (durable delegate)                   v
                                                  prepare -> start -> finish
                                                  close on every exit
   
   ToolCallAction
     +-- ordinary Tool -> framework durable wrapper --+
     +-- AsyncTool ----> call_async returns a handle -+--> await / gather
                                                             |
                                                             v
                                                  original tool-call IDs
   ```
   
   Python drives Java `SubgraphFuture` by ID through lifecycle methods, 
separating reservation from startup. This replaces the old bridge path; Java 
subagent tool metadata also crosses the bridge.
   
   #### Key decisions
   
   Keep `Tool.call` synchronous; `AsyncTool` owns execution without an outer 
durable wrapper. Chat/internal subagents share a subgraph handle; external 
waits delegate to durable handles.
   
   ### Behavioral Semantics
   
   #### Interaction decisions
   
   | Call / stored state | Single await or gather |
   | --- | --- |
   | Ordinary call | Execute on the pool; cache locally without persistence. |
   | Durable call / terminal | Replay without running preparation or the 
callback. |
   | Durable call / pending | Repeat preparation, then reconcile if available, 
otherwise execute. |
   | Chat or internal subagent | Reserve through Java; start when admitted and 
yield the Python continuation while waiting. |
   | External async subagent | Durable submission precedes the handle; gather 
schedules its durable result wait. |
   
   #### Behavioral contracts
   
   1. Gather returns input-ordered Outcomes; repeated terminal awaits reuse the 
local result.
   2. Durable slots are reserved before execution. Terminal replay skips 
preparation; pending recovery may repeat its side effects, which must be safe 
to repeat.
   3. Unsupported, duplicate, foreign-context and nested gather handles are 
rejected before work starts.
   4. Only gather applies batch limits. External async parallelism limits 
result waits, not already-submitted remote runs.
   5. Tool responses retain call IDs, normalization and reporting names. 
Completion/failure releases subagent registrations.
   
   #### Failure behavior
   
   Ordinary callable/preparation exceptions become failure Outcomes in gather 
and are raised by direct await; durable call failures are recorded. The 
scheduler propagates cancellation, interruption, uncapturable faults and 
control-flow BaseExceptions without terminal recording. Java subgraph bridge 
faults and invalid result decoding propagate as framework faults. Failed Chat 
responses still raise `ChatResponseError` when obtaining `ChatResult`.
   
   At timeout, completed calls keep their results. Started durable callables 
record timeout failures; unstarted calls and cancelled subgraph waits remain 
pending. Running callbacks cannot be forcibly interrupted. ToolCallAction 
converts ordinary preparation/execution/conversion errors into tool failures; 
uncapturable faults propagate.
   
   ### Tests
   
   | Contract | Tests |
   | --- | --- |
   | 1: mixed calls, ordering and cached awaits | 
`test_python_mixed_gather_end_to_end`; Chat/internal/async/deferred subagent 
tests |
   | 2: replay, preparation and pending recovery | `test_internal_subagent.py`; 
pending POST recovery in `test_async_subagent.py`; preparation cases in 
`test_subagent_await_cleanup.py` |
   | 3: admission validation | gather validation cases in 
`test_flink_runner_context_reconcilable.py`; duplicate mapped-call test |
   | 4: concurrency and timeout outcomes | ordinary/mixed gather and 
queued/unsubmitted timeout cases; 
`test_subgraph_timeout_cancels_wait_without_persisting_failure` |
   | 5: tool adaptation, reporting and cleanup | `test_tool_call_action.py`; 
`test_tool_call_action_subagent.py`; `test_subagent_await_cleanup.py`; ReAct 
subagent E2E |
   | Failure propagation and persistence | `test_durable_exception.py`; Java 
`ChatCallTest` and `PythonBridgeContractTest` |
   
   Python API/plan/runtime: **2,696 passed, 18 skipped**. Java targeted 
runtime/bridge tests on JDK 21: **90 passed, 1 skipped**. Rebuilt JARs and 
wheel; Flink 2.3 E2E: **16 passed on JDK 21**, plus **3 Chat/mixed-gather tests 
on JDK 17**. Ruff and Spotless passed.
   
   Not verified: JDK 11/Flink 1.20 E2E, real external services, 
checkpoint/restore of the new mixed Python subgraph batch, or cross-version 
savepoint upgrades. Unit replay tests use an in-memory journal.
   
   <details>
   <summary>Future relationships and implementation details</summary>
   
   `SchedulableFuture` extends `AsyncFuture` and supplies the common await 
lifecycle. `SingleAsyncFuture`, `SubgraphFuture`, `MappedAsyncFuture` and 
`CompletedSubagentFuture` implement that lifecycle. `SingleDurableFuture` 
extends `SingleAsyncFuture`; it and `SubgraphFuture` also implement 
`DurableFuture`.
   
   `SubagentFutureImpl` extends `MappedAsyncFuture` and implements the 
`SubagentFuture` API. It retains IDs, remote probes/cancellation and 
pending-handle cleanup while delegating execution. Mapping shares the source's 
call identity and adds no durable slot. `GatherAsyncFuture` extends 
`AsyncFuture` only; it aggregates participants and is not itself schedulable.
   
   The scheduler reserves slots in input order and finalizes by index, fences 
queued callbacks before cancellation, checks readiness again after 
cancellation, and closes every participant on exit. Python yields to the 
mailbox; it does not block a worker waiting for a child graph. Java's public 
Future interfaces and existing Java gather scheduler are unchanged.
   
   Startup/reconciliation tests traverse the production entry points. Tool 
batch assertions allow either worker completion order.
   
   </details>
   
   ### API
   
   - `SubagentFuture` extends `AsyncFuture`. `ResourceContext` implementations 
must provide `get_subagent_tool`.
   - Deferred setup `prepare` returns `SubagentCall(call, reconciler=None)` 
instead of `(key, call, reconcile)`; the framework owns durable 
identity/serialization.
   - `BaseAsyncSubagentSetup.submit_request` now returns a POST callback 
synchronously; the framework owns durability.
   - `SubagentTool` and its name prefix leave API. Old concrete runtime Future 
classes are replaced. Custom API-only subagent Future support remains separate 
work in #1355.
   - RunnerContext entry-point signatures and synchronous `Tool.call` remain 
unchanged. Single async durable calls now reserve pending state even without a 
reconciler.
   
   ### Documentation
   
   - [x] `doc-needed`
   - [ ] `doc-not-needed`
   - [ ] `doc-included`
   
   Java/Python documentation will be updated together after the interfaces 
settle.
   
   ### 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]

Reply via email to