Skip to content

Commit df067a4

Browse files
committed
Addressing PR comments
1 parent fc5b645 commit df067a4

3 files changed

Lines changed: 33 additions & 33 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ jobs:
115115
--dynamic-config-value frontend.activityAPIsEnabled=true \
116116
--dynamic-config-value activity.enableStandalone=true \
117117
--dynamic-config-value history.enableChasm=true \
118+
--dynamic-config-value history.enableCHASMSignalBacklinks=true \
118119
--dynamic-config-value history.enableTransitionHistory=true &
119120
sleep 10s
120121

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.ArrayList;
1010
import java.util.Collections;
1111
import java.util.List;
12+
import javax.annotation.Nonnull;
1213

1314
public class InternalNexusOperationContext {
1415
private final String namespace;
@@ -18,22 +19,19 @@ public class InternalNexusOperationContext {
1819
private final WorkflowClient client;
1920
NexusOperationOutboundCallsInterceptor outboundCalls;
2021
// Links extracted from the inbound Nexus task. Stored once at the task-handler boundary so the
21-
// workflow client (signal, signalWithStart) can attach them to outgoing requests via
22-
// SignalWorkflowExecutionRequest.links.
22+
// workflow client can attach them to the outgoing requests it issues (e.g. signal,
23+
// signalWithStart) via the request's links field.
2324
private List<Link> nexusOperationLinks = Collections.emptyList();
24-
// Backlinks returned by outbound RPCs the operation handler issues (currently
25-
// SignalWorkflowExecutionResponse.link and SignalWithStartWorkflowExecutionResponse.signal_link).
26-
// One entry per outbound RPC that returned a link. Drained by the task handler when building
27-
// StartOperationResponse so each RPC the handler issued gets a corresponding link on the caller
28-
// workflow's history event.
25+
// Backlinks returned by outbound RPCs the operation handler issues (such as
26+
// SignalWorkflowExecutionResponse.link or SignalWithStartWorkflowExecutionResponse.signal_link).
27+
// One entry per outbound RPC that returned a link. Drained
28+
// by the task handler when building StartOperationResponse so each RPC the handler issued gets a
29+
// corresponding link on the caller workflow's history event.
2930
//
3031
// This context is only safe for use from the single thread that runs the operation handler (the
31-
// Nexus task executor's thread). The mutators below assert this contract; a stray cross-thread
32-
// call fails fast rather than silently corrupting the ArrayList.
32+
// Nexus task executor's thread); the backing ArrayList is not synchronized. Handlers must not
33+
// mutate it from other threads.
3334
private final List<Link> responseBacklinks = new ArrayList<>();
34-
// Captured at construction (on the Nexus task executor's thread) and used to fail fast on any
35-
// cross-thread mutation. See note on responseBacklinks.
36-
private final Thread ownerThread;
3735

3836
public InternalNexusOperationContext(
3937
String namespace,
@@ -46,7 +44,6 @@ public InternalNexusOperationContext(
4644
this.endpoint = endpoint;
4745
this.metricScope = metricScope;
4846
this.client = client;
49-
this.ownerThread = Thread.currentThread();
5047
}
5148

5249
public Scope getMetricsScope() {
@@ -88,15 +85,15 @@ public void setNexusOperationLinks(List<Link> links) {
8885
this.nexusOperationLinks = links == null ? Collections.emptyList() : links;
8986
}
9087

91-
/** Links from the inbound Nexus task; empty if none. Never null. */
92-
public List<Link> getNexusOperationLinks() {
93-
return nexusOperationLinks;
88+
/** Links from the inbound Nexus task; empty if none. */
89+
public @Nonnull List<Link> getNexusOperationLinks() {
90+
return Collections.unmodifiableList(nexusOperationLinks);
9491
}
9592

9693
/**
97-
* Append a backlink returned by an outbound RPC the operation handler issued (signal or
98-
* signalWithStart). The task handler drains the list when building the operation's
99-
* StartOperationResponse.
94+
* Append a backlink returned by an outbound RPC the operation handler issued (e.g. signal,
95+
* signalWithStart, etc). The task handler drains the list when building the
96+
* operation's StartOperationResponse.
10097
*/
10198
public void addBacklink(Link link) {
10299
if (link != null) {
@@ -105,10 +102,13 @@ public void addBacklink(Link link) {
105102
}
106103

107104
/**
108-
* Backlinks from every outbound RPC the handler issued. Never null; may be empty. Returned as an
109-
* unmodifiable view; callers must not attempt to mutate.
105+
* Backlinks from every outbound RPC the handler issued. Returned as an unmodifiable view; callers
106+
* must not attempt to mutate. Entries are accumulated while the operation handler runs (the call
107+
* that flows through {@link
108+
* io.temporal.common.interceptors.NexusOperationInboundCallsInterceptor#startOperation}) and are
109+
* drained afterward by the task handler when building the StartOperationResponse.
110110
*/
111-
public List<Link> getBacklinks() {
111+
public @Nonnull List<Link> getBacklinks() {
112112
return Collections.unmodifiableList(responseBacklinks);
113113
}
114114

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ private StartOperationResponse handleStartOperation(
285285
.setCallbackUrl(task.getCallback())
286286
.setRequestId(task.getRequestId());
287287
task.getCallbackHeaderMap().forEach(operationStartDetails::putCallbackHeader);
288-
// Stash the inbound links in common.v1.Link form on the operation context so that signal
289-
// RPCs issued by the handler (e.g. SignalWithStartWorkflow on the callee) can attach them
290-
// to SignalWorkflowExecutionRequest.links.
288+
// Stash the inbound links in common.v1.Link form on the operation context so the RPCs the
289+
// handler issues (e.g. signal, signalWithStart, etc) can attach them to their
290+
// request's links field.
291291
List<io.temporal.api.common.v1.Link> inboundCommonLinks = new ArrayList<>();
292292
task.getLinksList()
293293
.forEach(
@@ -303,15 +303,15 @@ private StartOperationResponse handleStartOperation(
303303
}
304304
// LinkConverter only returns a WorkflowEvent-shaped common.v1.Link; nexus links of
305305
// other shapes (e.g. non-temporal URLs) come back null and are intentionally not
306-
// forwarded onto SignalWorkflowExecutionRequest.links, which requires the
307-
// WorkflowEvent variant. Log so a debugging session can see what was dropped.
306+
// forwarded onto the RPCs the handler issues, which require the WorkflowEvent
307+
// variant. Log so a debugging session can see what was dropped.
308308
io.temporal.api.common.v1.Link commonLink =
309309
LinkConverter.nexusLinkToWorkflowEvent(link);
310310
if (commonLink != null) {
311311
inboundCommonLinks.add(commonLink);
312312
} else {
313313
log.warn(
314-
"Dropping inbound Nexus link from outbound signal propagation: type='{}',"
314+
"Dropping inbound Nexus link from outbound link propagation: type='{}',"
315315
+ " url='{}' (not a parseable temporal WorkflowEvent link)",
316316
link.getType(),
317317
link.getUrl());
@@ -328,9 +328,10 @@ private StartOperationResponse handleStartOperation(
328328
try {
329329
OperationStartResult<HandlerResultContent> result =
330330
startOperation(context, operationStartDetails.build(), input.build());
331-
// If signal or signalWithStart RPCs the handler issued returned backlinks, propagate them
332-
// to the caller so the caller workflow's history event links to each event on the callee.
333-
// Same set of backlinks applies to both sync and async response variants.
331+
// If any RPCs the handler issued (e.g. signal, signalWithStart, etc) returned
332+
// backlinks, propagate them to the caller so the caller workflow's history event links to
333+
// each event on the callee. Same set of backlinks applies to both sync and async response
334+
// variants.
334335
List<io.temporal.api.nexus.v1.Link> backlinks = new ArrayList<>();
335336
for (io.temporal.api.common.v1.Link backlink :
336337
CurrentNexusOperationContext.get().getBacklinks()) {
@@ -388,8 +389,6 @@ private StartOperationResponse handleStartOperation(
388389
new RuntimeException("Unknown operation state: " + e.getState()));
389390
}
390391
startResponseBuilder.setFailure(dataConverter.exceptionToFailure(temporalFailure));
391-
} catch (Throwable failure) {
392-
convertKnownFailures(failure);
393392
}
394393
return startResponseBuilder.build();
395394
}

0 commit comments

Comments
 (0)