Repository navigation
fix: leave replay mode once an operation completed during suspension is consumed - #895
pcbeingused333 wants to merge 4 commits into
Conversation
…is consumed DurableLogger suppresses logs while the context is replaying, but the context only left replay mode when starting an operation with no checkpoint. If the last checkpointed operation (wait/callback) completed while suspended, the context stayed in replay and dropped the handler's new logs after it. Fixes aws#859 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| && durableContext.isReplaying() | ||
| && executionManager.isOperationUpdatedSinceLastInvocation(getOperationId())) { | ||
| durableContext.setExecutionMode(); |
There was a problem hiding this comment.
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.
| 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 { |
There was a problem hiding this comment.
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.
| // 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() |
There was a problem hiding this comment.
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.
Codex AI reviewThree findings: replay isolation and Rule 4 issues at Static review only; tests were not executed. Real-service Reviewed commit |
|
Thanks for picking up #859, and for the clear write-up. The root-cause notes and the before/after test evidence made this easy to review. I confirmed locally that the three new tests fail on While trying a few neighbouring patterns, I found some cases where the handler's logs are still dropped after resume. So I don't think this fully closes #859 yet. What seems to be going on. The new transition fires only when the consumed operation was already terminal at the start of the invocation, that is, it completed while the execution was suspended. Some operations are still in flight when the invocation starts and complete during it. They don't set Cases I reproduced at
I expect the same mechanism to apply to these, though I haven't run them separately:
A possible way forward. The root cause in the description covers one class of operations: terminal at start and listed in
Regression tests for the cases above that check what Thanks again for working on this! Repro:
|
| if (replayCompletedOperation.get() | ||
| && durableContext.isReplaying() | ||
| && executionManager.isOperationUpdatedSinceLastInvocation(getOperationId())) { |
There was a problem hiding this comment.
Nit: could you add a test with an old wait?
The isOperationUpdatedSinceLastInvocation check keeps an operation that finished in an older invocation in replay mode. waitAsyncThenStep_intermediateStepStaysReplay already covers this check through the middle step. Waits and callbacks run the same lines today, so they should behave the same way.
A test with an old wait would stop a later change from breaking this for waits only, for example if the mode switch moves into WaitOperation. It needs three invocations, so w1 is old by the last one:
var states = new ArrayList<String>();
var runner = LocalDurableTestRunner.create(String.class, (input, ctx) -> {
ctx.wait("w1", Duration.ofSeconds(1));
states.add("afterW1=" + ctx.isReplaying());
ctx.wait("w2", Duration.ofSeconds(1));
states.add("afterW2=" + ctx.isReplaying());
return "done";
});
assertEquals(ExecutionStatus.PENDING, runner.run("x").getStatus());
runner.advanceTime();
assertEquals(ExecutionStatus.PENDING, runner.run("x").getStatus());
states.clear();
runner.advanceTime();
assertEquals(ExecutionStatus.SUCCEEDED, runner.run("x").getStatus());
assertEquals(List.of("afterW1=true", "afterW2=false"), states);🤖 AI-assisted comment
| 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()); |
There was a problem hiding this comment.
These tests check isReplaying(), but the bug in #859 is about lost log lines. Could one test also check what reaches the logger?
🤖 AI-assisted comment
| 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 { |
There was a problem hiding this comment.
#859 also asks for coverage of child contexts and parallel branches. All tests here use only the top-level context. Can you add those?
🤖 AI-assisted comment
| // 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. |
There was a problem hiding this comment.
This check can show logs twice after a failed invocation. The local runner can't show this case.
The service fills UpdatedOperationIds with every operation whose sequence number is newer than the last successful invocation. So if an invocation saves some steps and then fails or times out, the retry lists those steps as updated. If the first invocation never succeeded, the retry lists every operation.
Steps also go through waitForOperationCompletion() (StepOperation line 214). So on the retry, the first replayed step from the failed run leaves replay mode. Every log after it is written again, even though that code already ran and logged in the failed run.
#859 says it does not need exactly-once logs across retries, so this may be fine. Could you:
- Say in the PR description and in
docs/advanced/logging.mdthat logs can repeat after a failed invocation. - Check it once against the real service, for example with
CloudDurableTestRunner.LocalDurableTestRunnerdoesn't model a failed invocation followed by a retry, and the PR description lists this as unverified.
🤖 AI-assisted comment
…r suspension Document that logs can repeat after a failed invocation.
…' into fix/c4495-logger-replay-after-wait
|
Thanks for the detailed review. Pushed a1d05b7 on top of the PR:
On @zhongkechen's comment: agreed that this does not close #859, so the description now says Disclosure: this reply and the commit were prepared with an AI coding assistant. |
Refs #859 (partial: covers operations that completed while the execution was suspended; operations that complete during the resumed invocation are not covered yet, see review)
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Issue Link, if available
#859
Description
DurableLoggerdrops the handler's logs written after awaitor a callbackget()that completed while the execution was suspended: the context stays in replay mode for the rest of the invocation, soshouldSuppressreturns true for new code.Demo/Screenshots
N/A
Design
execute()when a replayed operation is inupdatedOperationIdsis the same size, but it is wrong forwaitAsync→step→get(): the intermediate step is still a replay and its logs must stay suppressed (covered bywaitAsyncThenStep_intermediateStepStaysReplay). ChangingExecutionManager's global mode was rejected becauseDurableExecutorand the plugin hooks read it.DurableContextImpl.isReplayingonly becomes false when an operation with no checkpoint starts (BaseDurableOperation.execute()). An operation that completed during suspension is replayed as terminal, so if it is the last checkpointed operation of the context, the context never leaves replay mode.BaseDurableOperation.waitForOperationCompletion(); no public API change.Assumptions
updatedOperationIdsin the invocation input lists the operations that changed since the previous successful invocation (documented inDurableExecutionInput). Consequence: after a failed invocation, logs from the retried section can be emitted again. Behavior against the real service: unverified (tests useLocalDurableTestRunner, which fillsupdatedOperationIds).Decisions not covered by the issue or the design note
get()), not when the operation is replayed, so code between an async start and itsget()keeps the replay behavior.Checklist
sdk+sdk-integration-testssuite were run by the AI tool (see Testing)Testing
Unit Tests
No.
Integration Tests
Yes,
ReplayModeAfterSuspensionTest(sdk-integration-tests,LocalDurableTestRunner, 7 tests): code after a wait that completed during suspension is not a replay; same aftercallback.get();waitAsync→step→get()keeps the step in replay and leaves it afterwards; a wait that finished in an older invocation stays a replay; logs written after the wait reach the delegate logger and replayed ones do not; same inside a child context and a parallel branch. On main all 7 fail (for exampleexpected: <[false]> but was: <[true]>;expected: <[middle=true, after=false]> but was: <[middle=true, after=true]>); with the fix they pass, and the fullsdk+sdk-integration-testssuite passes.Examples
Not applicable.
This change was prepared with the assistance of an AI tool (Claude Code); the submitter has not manually reviewed or run it.