Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package software.amazon.lambda.durable;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import software.amazon.lambda.durable.model.ExecutionStatus;
import software.amazon.lambda.durable.testing.LocalDurableTestRunner;

/** The context must leave replay mode once the first operation that completed during suspension is consumed. */
class ReplayModeAfterSuspensionTest {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex AI review · Finding arf_v1_cusqr2xcutrqallsrwjbwtztqe

[P2] Approach: include the required unit regression coverage

AGENTS.md's Testing Requirements and CONTRIBUTING.md's pull-request requirement 3 require related unit tests, with integration tests added for cross-component behavior. This PR supplies only integration tests and explicitly reports “Unit Tests: No.” The shared replay transition therefore lacks the required isolated regression coverage. Under rule 9, return to the design phase described in rule 8 and revise the validation plan to include unit regressions alongside these integration scenarios.

To suppress repeats, reply /ai verdict deferred, /ai verdict false-positive, or /ai verdict out-of-scope on the first nonblank line. Add rationale on later lines. A new /ai verdict accepted allows future repeats again.


@Test
void waitCompletedDuringSuspension_codeAfterWaitIsNotReplay() {
var replayStates = new ArrayList<Boolean>();
var runner = LocalDurableTestRunner.create(String.class, (input, ctx) -> {
ctx.step("before", String.class, s -> "a");
ctx.wait("pause", Duration.ofSeconds(1));
replayStates.add(ctx.isReplaying());
return "done";
});

assertEquals(ExecutionStatus.PENDING, runner.run("x").getStatus());
replayStates.clear();
runner.advanceTime();
assertEquals(ExecutionStatus.SUCCEEDED, runner.run("x").getStatus());
assertEquals(List.of(false), replayStates);
}

@Test
void callbackCompletedDuringSuspension_codeAfterGetIsNotReplay() {
var replayStates = new ArrayList<Boolean>();
var runner = LocalDurableTestRunner.create(String.class, (input, ctx) -> {
var cb = ctx.createCallback("approval", String.class);
var value = cb.get();
replayStates.add(ctx.isReplaying());
return value;
});

assertEquals(ExecutionStatus.PENDING, runner.run("x").getStatus());
replayStates.clear();
runner.completeCallback(runner.getCallbackId("approval"), "\"ok\"");
assertEquals(ExecutionStatus.SUCCEEDED, runner.run("x").getStatus());
assertEquals(List.of(false), replayStates);
}

@Test
void waitAsyncThenStep_intermediateStepStaysReplay() {
var states = new ArrayList<String>();
var runner = LocalDurableTestRunner.create(String.class, (input, ctx) -> {
var w = ctx.waitAsync("pause", Duration.ofSeconds(1));
ctx.step("middle", String.class, s -> "m");
states.add("middle=" + ctx.isReplaying());
w.get();
states.add("after=" + ctx.isReplaying());
return "done";
});

assertEquals(ExecutionStatus.PENDING, runner.run("x").getStatus());
states.clear();
runner.advanceTime();
assertEquals(ExecutionStatus.SUCCEEDED, runner.run("x").getStatus());
assertEquals(List.of("middle=true", "after=false"), states);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ protected Operation waitForOperationCompletion() {
throw terminateExecutionWithIllegalDurableOperationException(
String.format("%s operation not found: %s", getType(), getOperationId()));
}
// An operation that completed while the execution was suspended is the first new event of this
// invocation. Once its result is consumed, the code that follows is no longer a replay, so leave
// replay mode and stop suppressing the handler's logs.
if (replayCompletedOperation.get()
&& durableContext.isReplaying()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex AI review · Finding arf_v1_y2jsi7yzsi6fvzulsfofhh76yn

[P3] Approach: justify each retained condition under rule 4

Rule 4 requires an assertion-sensitive test for every new condition. Removing durableContext.isReplaying() cannot change the resulting state: setExecutionMode() only assigns false, including when the context already holds false. The guard therefore adds a condition without observable behavior that needs it. Under rule 9, return to the design phase described in rule 8 and simplify the transition around conditions with demonstrable behavioral requirements.

To suppress repeats, reply /ai verdict deferred, /ai verdict false-positive, or /ai verdict out-of-scope on the first nonblank line. Add rationale on later lines. A new /ai verdict accepted allows future repeats again.

&& executionManager.isOperationUpdatedSinceLastInvocation(getOperationId())) {
durableContext.setExecutionMode();
Comment on lines +268 to +270

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex AI review · Finding arf_v1_vh7pvlq3cnto2tiea4ujgg62dy

[P2] Keep replay transitions local to the consuming context

durableContext identifies the operation's creator, but ExecutionManager.waitForOperationCompletion() permits another context to await its future. When a replaying child consumes a parent-owned callback completed during suspension, this switches the parent's flag while leaving the child's flag unchanged. The parent can emit duplicate logs while still replaying, and fresh child logs remain suppressed, violating ADR-004's per-context replay isolation. Apply the transition to the context consuming the future and add a cross-context suspension regression asserting both contexts' replay states.

To suppress repeats, reply /ai verdict deferred, /ai verdict false-positive, or /ai verdict out-of-scope on the first nonblank line. Add rationale on later lines. A new /ai verdict accepted allows future repeats again.

}
return op;
}
}
Expand Down