wenjin272 commented on code in PR #1299:
URL: https://github.com/apache/flink-agents/pull/1299#discussion_r4332712238


##########
runtime/src/main/java/org/apache/flink/agents/runtime/subagent/InternalSubagentFuture.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.agents.runtime.subagent;
+
+import org.apache.flink.agents.api.context.RunnerContext;
+import org.apache.flink.agents.api.subagent.SubagentFuture;
+import org.apache.flink.agents.api.subagent.SubagentFutures;
+import org.apache.flink.agents.api.subagent.SubagentResult;
+import org.apache.flink.agents.runtime.context.RunnerContextImpl;
+import org.apache.flink.agents.runtime.subgraph.SubgraphExecution;
+
+import javax.annotation.Nullable;
+
+import java.util.concurrent.CancellationException;
+
+/**
+ * Handle to one internal sub-agent invocation, backed by {@link 
SubgraphExecution} rather than a
+ * durable callable of its own.
+ */
+final class InternalSubagentFuture extends SubagentFuture implements 
PhasedSubagentFuture {
+
+    private final RunnerContext ctx;
+    private final InternalSubagentSetup setup;
+    private final Object prompt;
+    @Nullable private final PendingSubagentCallRegistry registry;
+
+    /** The id every step after registration names this call by. */
+    @Nullable private String id;
+
+    private boolean done;
+    private boolean cancelled;
+    @Nullable private SubagentResult value;
+
+    InternalSubagentFuture(
+            String sessionId,
+            String callId,
+            RunnerContext ctx,
+            InternalSubagentSetup setup,
+            Object prompt,
+            @Nullable PendingSubagentCallRegistry registry) {
+        super(sessionId, callId);
+        this.ctx = ctx;
+        this.setup = setup;
+        this.prompt = prompt;
+        this.registry = registry;
+        if (registry != null) {
+            registry.trackPendingSubagentCall(identity());
+        }
+    }
+
+    /** Prepares the call, or installs the terminal result recorded in its 
durable slot. */
+    @Override
+    public void prepare() throws Exception {
+        if (cancelled) {
+            throw new CancellationException("Sub-agent call cancelled: " + 
identity());
+        }
+        if (id == null) {
+            RunnerContextImpl runner = (RunnerContextImpl) ctx;
+            SubgraphExecution.requireReleasableOperator(runner);
+            id =
+                    SubgraphExecution.prepare(

Review Comment:
   Please fail fast on mixed internal/deferred batches before preparing any 
handle. I reproduced that `externalDeferred.combine(internal).awaitAll()` 
clears recorded results during replay and re-executes the external call. Since 
mixed batches are unsupported, reject them before touching the journal.



##########
runtime/src/main/java/org/apache/flink/agents/runtime/operator/ActionExecutionOperator.java:
##########
@@ -167,6 +172,34 @@ static boolean 
shouldEnableParallelExecutionWithoutCoroutine(
                 && (!usesPythonResource(agentPlan) || supportAsync());
     }
 
+    /**
+     * Rejects a child plan this engine cannot run: a worker cannot execute 
Python, and {@link
+     * #shouldEnableParallelExecutionWithoutCoroutine} screens only the root 
plan's own actions.
+     */
+    static void checkChildPlansRunOnParallelEngine(AgentPlan agentPlan) {
+        for (Map<String, ResourceProvider> providersByName :
+                agentPlan.getResourceProviders().values()) {
+            for (ResourceProvider provider : providersByName.values()) {
+                Optional<AgentPlan> child = 
InternalSubagentPlans.plan(provider);
+                if (!child.isPresent()) {
+                    continue;
+                }
+                for (Action action : child.get().getActions().values()) {
+                    checkState(
+                            action.getExec() instanceof JavaFunction,
+                            "The parallel execution engine runs an internal 
sub-agent's child"
+                                    + " actions on workers that cannot execute 
Python, but action"
+                                    + " %s of scope %s is not a Java action. 
Run this agent on JDK"
+                                    + " 21, or remove that action from the 
scope.",
+                            action.getName(),
+                            provider.getName());
+                }
+                // The plan tree is a DAG because cycles are rejected at 
compile time.
+                checkChildPlansRunOnParallelEngine(child.get());

Review Comment:
   Please check Python-resource compatibility recursively in child plans. When 
`supportAsync()` is false, a Python resource disables parallel execution at the 
root, but placing it inside a Java child bypasses this guard and allows 
unsupported worker execution.



-- 
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