AWS Lambda Durable Functions and the Replay Bug in Human-in-the-Loop Agents
Ciao ๐ Here is a sentence that should not be possible: my workflow executed an action a human explicitly did not approve. Not a different user's action, not a race condition, not a bug in my business logic. The human looked at the screen, saw "refund," clicked approve, and the system went and did "escalate" instead. Nobody tampered with anything. The code looked correct. The culprit was aโฆ
AWS Lambda durable functions, introduced in late 2025, enable developers to create long-running, multi-step workflows within a single Lambda handler. This feature suspends the function for up to a year while waiting for human input or external events, eliminating the need for a separate state machine or task tokens. Durable functions simplify code structure by collapsing complex orchestration into regular top-to-bottom code using two primitives: context.step(...) to checkpoint a unit of work and context.wait_for_callback(...) to pause execution until an external callback.
The author built a human-in-the-loop agent workflow using AWS Lambda durable functions to propose an action, seek human approval, and execute if approved. The agent suspends the workflow, awaiting human approval, and resumes when the human decides. However, the author discovered a dangerous bug called "replay" that can lead to unexpected behavior.
When the agent proposes an action outside a step, the function replays from the top upon resumption, executing the proposal again if the agent's output differs. This results in executing a different action than what the human approved.
The author demonstrated this issue with a mock agent that returns different actions each time it runs. In the unsafe version, where the agent proposal is outside a step, the human approved a refund, but the system executed an escalation instead, as the agent generated a different proposal on replay. Conversely, in the safe version, where the agent proposal is inside a step, the system executed the approved refund, as the checkpointed result maintained consistency.
This replay bug highlights the importance of understanding AWS Lambda durable functions' mechanics to avoid unexpected behavior in human-in-the-loop agent workflows. By properly structuring code within steps, developers can prevent such issues and ensure accurate execution of approved actions.
Written by urgent.news from Dev.to's reporting โ not their text. Machine-written โ may contain errors; check the original before relying on it.