pltbkd commented on code in PR #1299: URL: https://github.com/apache/flink-agents/pull/1299#discussion_r4336201759
########## 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: Done — the group now rejects a batch mixing the two before preparing any handle, so nothing reaches the journal. Python's group gets the same check, since both languages share the one ordered cursor. -- 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]
