Skip to content

Commit 984741b

Browse files
committed
Some changes for PR comments
1 parent 7766228 commit 984741b

3 files changed

Lines changed: 5 additions & 67 deletions

File tree

temporal-sdk/src/main/java/io/temporal/internal/client/RootWorkflowClientInvoker.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ public WorkflowStartOutput start(WorkflowStartInput input) {
103103
}
104104
}
105105
if (CurrentNexusOperationContext.isNexusContext()) {
106-
CurrentNexusOperationContext.get().setStartWorkflowResponseLink(response.getLink());
106+
// Auto-capture the start-workflow backlink so the task handler drains it onto the
107+
// StartOperationResponse, the same path used for signal/signalWithStart responses.
108+
CurrentNexusOperationContext.get().addBacklink(response.getLink());
107109
}
108110
return new WorkflowStartOutput(execution);
109111
}
@@ -125,12 +127,6 @@ public WorkflowSignalOutput signal(WorkflowSignalInput input) {
125127
boolean inNexusContext = CurrentNexusOperationContext.isNexusContext();
126128
if (inNexusContext) {
127129
request.addAllLinks(CurrentNexusOperationContext.get().getNexusOperationLinks());
128-
} else {
129-
// Most signal calls (from a regular client or workflow) won't be in a Nexus context — this
130-
// is normal. The log helps a debugger when a Nexus operation handler "mysteriously" lacks
131-
// link propagation because it spawned a thread to issue the signal (the thread-local
132-
// CurrentNexusOperationContext is invisible from that thread).
133-
log.debug("signal RPC issued outside a Nexus operation context; no link propagation");
134130
}
135131

136132
DataConverter dataConverterWitSignalContext =

temporal-sdk/src/main/java/io/temporal/internal/nexus/InternalNexusOperationContext.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class InternalNexusOperationContext {
1717
private final Scope metricScope;
1818
private final WorkflowClient client;
1919
NexusOperationOutboundCallsInterceptor outboundCalls;
20-
Link startWorkflowResponseLink;
2120
// Links extracted from the inbound Nexus task. Stored once at the task-handler boundary so the
2221
// workflow client (signal, signalWithStart) can attach them to outgoing requests via
2322
// SignalWorkflowExecutionRequest.links.
@@ -50,17 +49,6 @@ public InternalNexusOperationContext(
5049
this.ownerThread = Thread.currentThread();
5150
}
5251

53-
private void assertOwnerThread() {
54-
if (Thread.currentThread() != ownerThread) {
55-
throw new IllegalStateException(
56-
"InternalNexusOperationContext mutated from thread '"
57-
+ Thread.currentThread().getName()
58-
+ "' but is owned by '"
59-
+ ownerThread.getName()
60-
+ "'. Operation handlers must not spawn threads to issue link-propagating RPCs.");
61-
}
62-
}
63-
6452
public Scope getMetricsScope() {
6553
return metricScope;
6654
}
@@ -92,20 +80,11 @@ public NexusOperationContext getUserFacingContext() {
9280
return new NexusOperationContextImpl();
9381
}
9482

95-
public void setStartWorkflowResponseLink(Link link) {
96-
this.startWorkflowResponseLink = link;
97-
}
98-
99-
public Link getStartWorkflowResponseLink() {
100-
return startWorkflowResponseLink;
101-
}
102-
10383
/**
10484
* Set the {@code common.v1.Link}s extracted from the inbound Nexus task so they can be attached
10585
* to RPCs issued by the operation handler.
10686
*/
10787
public void setNexusOperationLinks(List<Link> links) {
108-
assertOwnerThread();
10988
this.nexusOperationLinks = links == null ? Collections.emptyList() : links;
11089
}
11190

@@ -120,7 +99,6 @@ public List<Link> getNexusOperationLinks() {
12099
* StartOperationResponse.
121100
*/
122101
public void addBacklink(Link link) {
123-
assertOwnerThread();
124102
if (link != null) {
125103
this.responseBacklinks.add(link);
126104
}

temporal-sdk/src/main/java/io/temporal/nexus/WorkflowRunOperationImpl.java

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
package io.temporal.nexus;
22

3-
import static io.temporal.internal.common.LinkConverter.workflowEventToNexusLink;
4-
import static io.temporal.internal.common.NexusUtil.nexusProtoLinkToLink;
5-
63
import io.nexusrpc.handler.*;
74
import io.nexusrpc.handler.OperationHandler;
8-
import io.temporal.api.common.v1.Link;
9-
import io.temporal.api.common.v1.WorkflowExecution;
10-
import io.temporal.api.enums.v1.EventType;
115
import io.temporal.client.WorkflowClient;
126
import io.temporal.internal.client.NexusStartWorkflowRequest;
137
import io.temporal.internal.client.NexusStartWorkflowResponse;
148
import io.temporal.internal.nexus.CurrentNexusOperationContext;
159
import io.temporal.internal.nexus.InternalNexusOperationContext;
1610
import io.temporal.internal.nexus.OperationTokenUtil;
17-
import java.net.URISyntaxException;
1811

1912
class WorkflowRunOperationImpl<T, R> implements OperationHandler<T, R> {
2013
private final WorkflowHandleFactory<T, R> handleFactory;
@@ -40,38 +33,9 @@ public OperationStartResult<R> start(
4033

4134
NexusStartWorkflowResponse nexusStartWorkflowResponse =
4235
handle.getInvoker().invoke(nexusRequest);
43-
WorkflowExecution workflowExec = nexusStartWorkflowResponse.getWorkflowExecution();
4436

45-
// If the start workflow response returned a link use it, otherwise
46-
// create the link information about the new workflow and return to the caller.
47-
Link.WorkflowEvent workflowEventLink =
48-
nexusCtx.getStartWorkflowResponseLink().hasWorkflowEvent()
49-
? nexusCtx.getStartWorkflowResponseLink().getWorkflowEvent()
50-
: null;
51-
if (workflowEventLink == null) {
52-
workflowEventLink =
53-
Link.WorkflowEvent.newBuilder()
54-
.setNamespace(nexusCtx.getNamespace())
55-
.setWorkflowId(workflowExec.getWorkflowId())
56-
.setRunId(workflowExec.getRunId())
57-
.setEventRef(
58-
Link.WorkflowEvent.EventReference.newBuilder()
59-
.setEventType(EventType.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED))
60-
.build();
61-
}
62-
io.temporal.api.nexus.v1.Link nexusLink = workflowEventToNexusLink(workflowEventLink);
63-
// Attach the link to the operation result.
64-
OperationStartResult.Builder<R> result =
65-
OperationStartResult.newAsyncBuilder(nexusStartWorkflowResponse.getOperationToken());
66-
if (nexusLink != null) {
67-
try {
68-
ctx.addLinks(nexusProtoLinkToLink(nexusLink));
69-
} catch (URISyntaxException e) {
70-
// Not expected as the link is constructed by the SDK.
71-
throw new HandlerException(HandlerException.ErrorType.INTERNAL, "failed to parse URI", e);
72-
}
73-
}
74-
return result.build();
37+
return OperationStartResult.<R>newAsyncBuilder(nexusStartWorkflowResponse.getOperationToken())
38+
.build();
7539
}
7640

7741
@Override

0 commit comments

Comments
 (0)