From 77043689483797e4ee3f4ae9fa432a9144fb2afe Mon Sep 17 00:00:00 2001 From: Joie Wu Date: Wed, 25 Nov 2026 15:15:44 -0800 Subject: [PATCH] Omit the Nexus cancellation token from JSON --- CHANGELOG.md | 2 + .../internal/nexus/NexusInfoImpl.java | 2 + .../io/temporal/nexus/NexusOperationInfo.java | 2 + .../internal/nexus/NexusInfoImplTest.java | 39 +++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 temporal-sdk/src/test/java/io/temporal/internal/nexus/NexusInfoImplTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index e3353dbdaa..100718295a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,8 @@ to docs, or any other relevant information. as asynchronous. - Client request metrics (`temporal_long_request_latency` etc.) now always carry the `update_name` tag (default `none`), fixing Prometheus tag-key conflicts when Workflow Updates are used (#3210). +- The default JSON converter omits the live cancellation token from `NexusOperationInfo`, + avoiding an extra cancellation callback each time an application serializes the info. ## [1.41.1] - 2026-11-16 diff --git a/temporal-sdk/src/main/java/io/temporal/internal/nexus/NexusInfoImpl.java b/temporal-sdk/src/main/java/io/temporal/internal/nexus/NexusInfoImpl.java index 6f853c4213..a9cdaa9716 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/nexus/NexusInfoImpl.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/nexus/NexusInfoImpl.java @@ -1,5 +1,6 @@ package io.temporal.internal.nexus; +import com.fasterxml.jackson.annotation.JsonIgnore; import io.temporal.common.CancellationToken; import io.temporal.nexus.NexusOperationInfo; import java.util.concurrent.CancellationException; @@ -62,6 +63,7 @@ public String getOperation() { } @Override + @JsonIgnore public CancellationToken getCancellationToken() { return cancellationToken; } diff --git a/temporal-sdk/src/main/java/io/temporal/nexus/NexusOperationInfo.java b/temporal-sdk/src/main/java/io/temporal/nexus/NexusOperationInfo.java index 34e3a5a098..8b17d564d2 100644 --- a/temporal-sdk/src/main/java/io/temporal/nexus/NexusOperationInfo.java +++ b/temporal-sdk/src/main/java/io/temporal/nexus/NexusOperationInfo.java @@ -55,6 +55,8 @@ default String getRequestId() { * reason. * *

Cancellation callbacks may run on the Nexus timeout thread and must return promptly. + * + *

The SDK's default JSON converter omits the live token when serializing this info. */ CancellationToken getCancellationToken(); } diff --git a/temporal-sdk/src/test/java/io/temporal/internal/nexus/NexusInfoImplTest.java b/temporal-sdk/src/test/java/io/temporal/internal/nexus/NexusInfoImplTest.java new file mode 100644 index 0000000000..3ffa754b70 --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/internal/nexus/NexusInfoImplTest.java @@ -0,0 +1,39 @@ +package io.temporal.internal.nexus; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import io.temporal.api.common.v1.Payload; +import io.temporal.common.CancellationToken; +import io.temporal.common.converter.DataConverter; +import io.temporal.common.converter.DefaultDataConverter; +import io.temporal.internal.concurrent.structured.CancelSource; +import io.temporal.nexus.NexusOperationInfo; +import java.util.Map; +import java.util.concurrent.CancellationException; +import org.junit.Test; + +public class NexusInfoImplTest { + @Test + public void serializesMetadataWithoutAccessingCancellationFuture() { + CancelSource source = new CancelSource<>(CancellationException::new); + CancellationToken token = spy(source.token()); + NexusOperationInfo info = + new NexusInfoImpl( + "namespace", "queue", "endpoint", "service", "operation", "request-id", token); + DataConverter converter = DefaultDataConverter.STANDARD_INSTANCE; + + Payload payload = converter.toPayload(info).get(); + Map metadata = converter.fromPayload(payload, Map.class, Map.class); + + verify(token, never()).getCancellationFuture(); + assertFalse(metadata.containsKey("cancellationToken")); + assertEquals("namespace", metadata.get("namespace")); + assertEquals("queue", metadata.get("taskQueue")); + assertEquals("endpoint", metadata.get("endpoint")); + assertEquals("service", metadata.get("service")); + assertEquals("operation", metadata.get("operation")); + assertEquals("request-id", metadata.get("requestId")); + assertSame(token, info.getCancellationToken()); + } +}