Skip to content

Commit 205a027

Browse files
fix: wall-clock timeout, null source validation, thread-safety doc
- waitForApproval now uses System.nanoTime() for accurate wall-clock timeout instead of accumulating sleep durations - Builder.source() rejects null with Objects.requireNonNull - Add thread-safety Javadoc: adapter is not thread-safe
1 parent 36ada1d commit 205a027

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/main/java/com/getaxonflow/sdk/adapters/LangGraphAdapter.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
* registration, step gate checks, per-tool governance, MCP tool interception,
4444
* and workflow lifecycle management.
4545
*
46+
* <p><strong>Thread safety:</strong> This class is not thread-safe. Each workflow
47+
* execution should use its own adapter instance from a single thread.
48+
*
4649
* <p>"LangGraph runs the workflow. AxonFlow decides when it's allowed to move forward."
4750
*
4851
* <p>Example usage:
@@ -391,8 +394,8 @@ public boolean waitForApproval(String stepId, long pollIntervalMs, long timeoutM
391394
throws InterruptedException, TimeoutException {
392395
requireStarted();
393396

394-
long elapsed = 0;
395-
while (elapsed < timeoutMs) {
397+
long deadlineNanos = System.nanoTime() + java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(timeoutMs);
398+
while (System.nanoTime() < deadlineNanos) {
396399
WorkflowStatusResponse status = client.getWorkflow(workflowId);
397400

398401
for (WorkflowStepInfo step : status.getSteps()) {
@@ -410,7 +413,6 @@ public boolean waitForApproval(String stepId, long pollIntervalMs, long timeoutM
410413
}
411414

412415
Thread.sleep(pollIntervalMs);
413-
elapsed += pollIntervalMs;
414416
}
415417

416418
throw new TimeoutException("Approval timeout after " + timeoutMs + "ms for step " + stepId);
@@ -532,7 +534,7 @@ private Builder(AxonFlow client, String workflowName) {
532534
* @return this builder
533535
*/
534536
public Builder source(WorkflowSource source) {
535-
this.source = source;
537+
this.source = Objects.requireNonNull(source, "source cannot be null");
536538
return this;
537539
}
538540

0 commit comments

Comments
 (0)