Skip to content

fix: leave replay mode once an operation completed during suspension is consumed - #895

Open
pcbeingused333 wants to merge 1 commit into
aws:mainfrom
pcbeingused333:fix/c4495-logger-replay-after-wait
Open

pcbeingused333 wants to merge 1 commit into
aws:mainfrom
pcbeingused333:fix/c4495-logger-replay-after-wait

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Fixes #859

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

DurableLogger drops the handler's logs written after a wait or a callback get() that completed while the execution was suspended: the context stays in replay mode for the rest of the invocation, so shouldSuppress returns true for new code.

Demo/Screenshots

N/A

Design

  • Design note (rule 3): not needed (bug fix, no public API change).
  • Simpler options considered (rule 2): flipping the mode in execute() when a replayed operation is in updatedOperationIds is the same size, but it is wrong for waitAsync → step → get(): the intermediate step is still a replay and its logs must stay suppressed (covered by waitAsyncThenStep_intermediateStepStaysReplay). Changing ExecutionManager's global mode was rejected because DurableExecutor and the plugin hooks read it.
  • Root cause (rule 5): DurableContextImpl.isReplaying only 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.
  • Net change in source lines and in public API members: +5 source lines (plus a 3-line comment) in BaseDurableOperation.waitForOperationCompletion(); no public API change.

Assumptions

  • updatedOperationIds in the invocation input lists the operations that changed since the previous successful invocation (documented in DurableExecutionInput). Consequence: after a failed invocation, logs from the retried section can be emitted again. Behavior against the real service: unverified (tests use LocalDurableTestRunner, which fills updatedOperationIds).

Decisions not covered by the issue or the design note

  • Replay mode is left when the completed operation's result is consumed (get()), not when the operation is replayed, so code between an async start and its get() keeps the replay behavior.

Checklist

  • I have filled out every section of the PR template
  • I have thoroughly tested this change: the new regression tests and the full sdk + sdk-integration-tests suite were run by the AI tool (see Testing)
  • Every new branch has a test that fails without it (rule 4)
  • For a bug fix: the description or commit order shows the regression test failing before the fix and passing after it (rule 5)
  • Every edited test expectation is listed in the description, with the reason (rule 5): no existing test expectation was edited.

Testing

Unit Tests

No.

Integration Tests

Yes, ReplayModeAfterSuspensionTest (sdk-integration-tests, LocalDurableTestRunner): code after a wait that completed during suspension is not a replay; same after callback.get(); waitAsync → step → get() keeps the step in replay and leaves it afterwards. On main all 3 fail (expected: <[false]> but was: <[true]>; expected: <[middle=true, after=false]> but was: <[middle=true, after=true]>); with the fix they pass, and the full sdk + sdk-integration-tests suite 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.

…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>
@pcbeingused333
pcbeingused333 requested a review from a team November 19, 2026 04:19
@pcbeingused333
pcbeingused333 deployed to ai-pr-review-runtime November 19, 2026 04:19 — with GitHub Actions Active
Comment on lines +268 to +270
&& durableContext.isReplaying()
&& executionManager.isOperationUpdatedSinceLastInvocation(getOperationId())) {
durableContext.setExecutionMode();

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.

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.

// 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.

@github-actions

Copy link
Copy Markdown
Contributor

Codex AI review

Three findings: replay isolation and Rule 4 issues at sdk/src/main/java/software/amazon/lambda/durable/operation/BaseDurableOperation.java:268, and missing required unit coverage at sdk-integration-tests/src/test/java/software/amazon/lambda/durable/ReplayModeAfterSuspensionTest.java:15.

Static review only; tests were not executed. Real-service updatedOperationIds behavior remains unverified.

Reviewed commit 520263cf1cbb5a2fb4183c7da684c03042fb6374. Workflow run

This branch was successfully deployed

1 active deployment
ai-pr-review-runtime — 520263cf Deployed Nov 19, 2026 by pcbeingused333 via notify / Generate notification summary #362
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DurableLogger suppresses handler logs after a resumed wait

1 participant