• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #434

24 Nov 2026 05:31AM UTC coverage: 71.906% (+0.02%) from 71.886%
#434

push

github

web-flow
Prioritize sticky workflow polls during autoscaling (#3208)

* Prioritize sticky workflow polls during autoscaling

Balance sticky and normal admission using backlog, the sticky scaling\ntarget, and slot capacity instead of requiring both pools to have polls.\nWake admission waiters on changes and add regression coverage.

* Preserve first-poll access without a slot maximum

Wait for the other workflow queue's first poll when its slot capacity
is unknown, rather than treating the limit as effectively unbounded.

Cover both startup orders with an unadvertised two-slot supplier and
add the incident recovery regression. Document the fallback explicitly.

8825 of 14431 branches covered (61.15%)

Branch coverage included in aggregate %.

79 of 79 new or added lines in 4 files covered. (100.0%)

6 existing lines in 4 files now uncovered.

34725 of 46134 relevant lines covered (75.27%)

0.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.97
/temporal-sdk/src/main/java/io/temporal/client/ActivityCompletionClientImpl.java
1
package io.temporal.client;
2

3
import com.uber.m3.tally.Scope;
4
import io.temporal.api.common.v1.WorkflowExecution;
5
import io.temporal.internal.client.external.ManualActivityCompletionClientFactory;
6
import io.temporal.payload.context.ActivitySerializationContext;
7
import io.temporal.payload.context.NexusSerializationContext;
8
import io.temporal.payload.context.SerializationContext;
9
import io.temporal.workflow.Functions;
10
import java.util.Optional;
11
import javax.annotation.Nonnull;
12
import javax.annotation.Nullable;
13

14
class ActivityCompletionClientImpl implements ActivityCompletionClient {
15

16
  private final ManualActivityCompletionClientFactory factory;
17
  private final Functions.Proc completionHandle;
18
  private final Scope metricsScope;
19
  private final @Nullable SerializationContext serializationContext;
20

21
  ActivityCompletionClientImpl(
22
      ManualActivityCompletionClientFactory manualActivityCompletionClientFactory,
23
      Functions.Proc completionHandle,
24
      Scope metricsScope,
25
      @Nullable SerializationContext serializationContext) {
1 ✔
26
    this.factory = manualActivityCompletionClientFactory;
1 ✔
27
    this.completionHandle = completionHandle;
1 ✔
28
    this.metricsScope = metricsScope;
1 ✔
29
    this.serializationContext = serializationContext;
1 ✔
30
  }
1 ✔
31

32
  @Override
33
  public <R> void complete(byte[] taskToken, R result) {
34
    try {
35
      factory.getClient(taskToken, metricsScope, serializationContext).complete(result);
1 ✔
36
    } finally {
37
      completionHandle.apply();
1 ✔
38
    }
39
  }
1 ✔
40

41
  @Override
42
  public <R> void complete(String workflowId, Optional<String> runId, String activityId, R result) {
43
    try {
44
      factory
×
45
          .getClient(toExecution(workflowId, runId), activityId, metricsScope, serializationContext)
×
46
          .complete(result);
×
47
    } finally {
48
      completionHandle.apply();
×
49
    }
50
  }
×
51

52
  @Override
53
  public <R> void completeStandalone(String activityId, Optional<String> activityRunId, R result) {
54
    try {
55
      factory
1 ✔
56
          .getClient(
1 ✔
57
              toStandaloneExecution(activityRunId), activityId, metricsScope, serializationContext)
1 ✔
58
          .complete(result);
1 ✔
59
    } finally {
60
      completionHandle.apply();
1 ✔
61
    }
62
  }
1 ✔
63

64
  @Override
65
  public void completeExceptionally(byte[] taskToken, Exception result) {
66
    try {
67
      factory.getClient(taskToken, metricsScope, serializationContext).fail(result);
×
68
    } finally {
69
      completionHandle.apply();
×
70
    }
71
  }
×
72

73
  @Override
74
  public void completeExceptionally(
75
      String workflowId, Optional<String> runId, String activityId, Exception result) {
76
    try {
77
      factory
×
78
          .getClient(toExecution(workflowId, runId), activityId, metricsScope, serializationContext)
×
79
          .fail(result);
×
80
    } finally {
81
      completionHandle.apply();
×
82
    }
83
  }
×
84

85
  @Override
86
  public void completeExceptionallyStandalone(
87
      String activityId, Optional<String> activityRunId, Exception result) {
88
    try {
89
      factory
1 ✔
90
          .getClient(
1 ✔
91
              toStandaloneExecution(activityRunId), activityId, metricsScope, serializationContext)
1 ✔
92
          .fail(result);
1 ✔
93
    } finally {
94
      completionHandle.apply();
1 ✔
95
    }
96
  }
1 ✔
97

98
  @Override
99
  public <V> void reportCancellation(byte[] taskToken, V details) {
100
    try {
UNCOV
101
      factory.getClient(taskToken, metricsScope, serializationContext).reportCancellation(details);
×
102
    } finally {
UNCOV
103
      completionHandle.apply();
×
104
    }
UNCOV
105
  }
×
106

107
  @Override
108
  public <V> void reportCancellation(
109
      String workflowId, Optional<String> runId, String activityId, V details) {
110
    try {
111
      factory
×
112
          .getClient(toExecution(workflowId, runId), activityId, metricsScope, serializationContext)
×
113
          .reportCancellation(details);
×
114
    } finally {
115
      completionHandle.apply();
×
116
    }
117
  }
×
118

119
  @Override
120
  public <V> void reportCancellationStandalone(
121
      String activityId, Optional<String> activityRunId, V details) {
122
    try {
123
      factory
1 ✔
124
          .getClient(
1 ✔
125
              toStandaloneExecution(activityRunId), activityId, metricsScope, serializationContext)
1 ✔
126
          .reportCancellation(details);
1 ✔
127
    } finally {
128
      completionHandle.apply();
1 ✔
129
    }
130
  }
1 ✔
131

132
  @Override
133
  public <V> void heartbeat(byte[] taskToken, V details) throws ActivityCompletionException {
134
    factory.getClient(taskToken, metricsScope, serializationContext).recordHeartbeat(details);
1 ✔
135
  }
1 ✔
136

137
  @Override
138
  public <V> void heartbeat(String workflowId, Optional<String> runId, String activityId, V details)
139
      throws ActivityCompletionException {
140
    factory
×
141
        .getClient(toExecution(workflowId, runId), activityId, metricsScope, serializationContext)
×
142
        .recordHeartbeat(details);
×
143
  }
×
144

145
  @Nonnull
146
  @Override
147
  public ActivityCompletionClient withContext(@Nonnull ActivitySerializationContext context) {
148
    return new ActivityCompletionClientImpl(factory, completionHandle, metricsScope, context);
1 ✔
149
  }
150

151
  @Nonnull
152
  @Override
153
  public ActivityCompletionClient withContext(@Nonnull NexusSerializationContext context) {
154
    return new ActivityCompletionClientImpl(factory, completionHandle, metricsScope, context);
1 ✔
155
  }
156

157
  @Override
158
  public <V> void heartbeatStandalone(String activityId, Optional<String> activityRunId, V details)
159
      throws ActivityCompletionException {
160
    factory
1 ✔
161
        .getClient(
1 ✔
162
            toStandaloneExecution(activityRunId), activityId, metricsScope, serializationContext)
1 ✔
163
        .recordHeartbeat(details);
1 ✔
164
  }
1 ✔
165

166
  private static WorkflowExecution toExecution(String workflowId, Optional<String> runId) {
167
    return WorkflowExecution.newBuilder()
×
168
        .setWorkflowId(workflowId)
×
169
        .setRunId(runId.orElse(""))
×
170
        .build();
×
171
  }
172

173
  private static WorkflowExecution toStandaloneExecution(Optional<String> activityRunId) {
174
    // TODO: consider not using a WorkflowExecution here, but instead passing
175
    // workflow/activity and run IDs to the factory separately.
176
    return WorkflowExecution.newBuilder()
1 ✔
177
        .setWorkflowId("") // empty workflowId = standalone activity
1 ✔
178
        .setRunId(activityRunId.orElse(""))
1 ✔
179
        .build();
1 ✔
180
  }
181
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc