I Broke My Agent's Refund Tool With AWS FIS. It Refunded One Order Three Times.

I Broke My Agent's Refund Tool With AWS FIS. It Refunded One Order Three Times.

A hands-on guide to chaos-testing an AI agent's tools with AWS Fault Injection Service, Amazon Bedrock and Terraform: inject real Lambda faults, measure what the agent claimed against a DynamoDB ledger, and fix duplicate side effects with idempotency keys.

Chaos-testing the tools an AI agent calls, with AWS Fault Injection Service, Amazon Bedrock and a DynamoDB ledger as ground truth. Full Terraform and code:  github.com/Extraordinarytechy/fis-agent-tool-chaos 


Order  ord-40d61e82a0  cost $49.99. The customer asked for a refund. My agent issued three of them, then told the customer:
NOT_REFUNDED
Here is the DynamoDB ledger for that order:
Three refunds of $49.99 committed against one order

Nothing was wrong with the model, the prompt or the refund code. All I did was make the refund tool slow. The agent's client gave up after 4 seconds, the agent decided the refund had failed, and it tried again. Every one of those "failed" calls finished a few seconds later and moved money. The system prompt had told it, in those words, to "never refund the same request twice."
This post shows how I set that up with AWS Fault Injection Service (FIS), how I measured what the agent claimed against what actually happened, and the change that took duplicates to zero. Everything here is deployable from the repo with one  terraform apply , and the whole set of experiments cost me under four dollars.

Why this is a real problem

An agent tool call is a network call. When it times out, the caller can't tell whether the request never arrived or whether it arrived and the response got lost. Distributed systems people have known this forever, and the usual answer lives in the API, not the client: idempotency keys, conditional writes, a way to look up what happened.
Agents inherit the ambiguity without the remedies. A September 2026 paper,  Where Does Exactly-Once Live? , ran 25,930 graded agent episodes and found that when a request is still in flight, even frontier models duplicated the write in 56% of episodes. Offering an idempotency key on every write cut duplicates from 28% to 4%. And in 90% of the episodes where an agent had duplicated something, it reported the task as done.
I wanted to see this on AWS, with real Lambda functions and real faults, not a simulator. FIS has three Lambda fault actions that map almost perfectly onto the ways a tool call can go wrong, so that's what I used.

What we're building

Architecture: a local agent harness calls Bedrock and two Lambda tools; FIS injects faults into issue_refund through an S3 config prefix; a checker compares the agent's claim with a DynamoDB ledger and feeds a CloudWatch alarm that is the FIS stop condition

  • The agent runs locally. It uses the Bedrock Converse API with three tools:  get_order ,  issue_refund , and  report_outcome . The last one is how it ends a conversation, and its arguments are the agent's claim:  REFUNDED ,  NOT_REFUNDED  or  UNKNOWN .
  • The tools are two Lambda functions. Only  issue_refund  gets faults.  get_order  always works, so if the agent duplicates a refund, it had a reliable way to check first and didn't use it.
  • The ledger is a DynamoDB table with one item per committed refund. The checker trusts it and nothing else.
  • FIS injects the faults. A CloudWatch alarm on over-refunded dollars is the stop condition.
I used Amazon Nova 2 Lite ( us.amazon.nova-2-lite-v1:0 ) as the main model because it's cheap and on-demand, and Amazon Nova Pro as a stronger comparison. Temperature 0 for both.
I compared three versions of the contract between the agent and the refund tool. They show up as  --contract  in the commands below:
Contract
What changes
 v1 
No idempotency key. Tool errors reach the model as raw text.
 v2 
The tool requires an  idempotency_key  that the model chooses, and errors say the commit status is unknown.
 v3 
Same as v2, but the harness attaches the key itself, so the model can't forget it or change it.
Why not just mock the errors in a unit test? A mock would have missed the two most important things I found: the AWS SDK retrying a timed-out call on its own, and the commit landing seconds after the client gave up. Both only show up when a real client talks to a real function.
Prerequisites: an AWS account, Terraform 1.6+, Python 3.10+, AWS CLI v2, and access to an on-demand Bedrock model with tool use. Your credentials need FIS, CloudWatch, CloudWatch Logs and  ssm:GetParameter  on top of the usual Lambda, DynamoDB, S3 and IAM permissions. My developer user was missing all four, so the repo includes the exact statements in   iam/operator-policy.json  .

Step 1: Deploy the stack

git clone https://github.com/Extraordinarytechy/fis-agent-tool-chaos.git
cd fis-agent-tool-chaos
export AWS_PROFILE=<profile> AWS_REGION=us-east-1

cd infra
terraform init
terraform apply
cd ..

python -m venv .venv && . .venv/bin/activate
pip install -r requirements.txt
That creates two DynamoDB tables, the two Lambda tools, an S3 bucket for FIS configuration, two IAM roles, the alarm, a CloudWatch dashboard and three FIS experiment templates. I tested it with Terraform 1.13.3 and the AWS provider v6.72.0.
The interesting part is how the FIS extension gets attached to the Lambda function. It's a layer plus a wrapper script, and it talks to FIS through an S3 prefix:
data "aws_ssm_parameter" "fis_extension" {
name = "/aws/service/fis/lambda-extension/AWS-FIS-extension-${var.lambda_architecture}/1.x.x"
}

locals {
fis_env = {
AWS_LAMBDA_EXEC_WRAPPER = "/opt/aws-fis/bootstrap"
AWS_FIS_CONFIGURATION_LOCATION = "${aws_s3_bucket.fis_config.arn}/${local.fis_config_path}"
AWS_FIS_POLL_MAX_WAIT_MILLISECONDS = "2000"
AWS_FIS_SLOW_POLL_INTERVAL_SECONDS = tostring(var.slow_poll_interval_seconds)
AWS_FIS_EXTENSION_METRICS = "all"
}
}
Two decisions here are worth explaining.
Read the layer ARN from SSM, don't hardcode it. AWS publishes the current extension ARN as a public SSM parameter. The ARN in my first notes ended in version  :280 . When I deployed on November 10 the current version was  :432 . A hardcoded ARN goes stale quietly.
 AWS_FIS_POLL_MAX_WAIT_MILLISECONDS = 2000 . The AWS docs recommend this when you use  preventExecution=true . Without it, a fast invocation can start before the extension has fetched the active fault, and slip through unbroken.
FIS environment variables on the refund tool

The tool's execution role can only read the  FisConfigs/  prefix. The FIS role can only write and delete there, plus  lambda:GetFunction  on the one target function. Neither has wider S3 access.
Before going further, check the deploy actually worked:
cd infra && terraform output experiment_templates && cd ..
aws fis list-experiment-templates --query "experimentTemplates[].description" --output table
aws lambda get-function-configuration --function-name fatc-issue-refund --query "Layers[].Arn"
You should see three template IDs, three descriptions starting with  issue_refund , and a layer ARN containing  aws-fis-extension . If the layer list is empty, the SSM lookup returned the wrong architecture;  lambda_architecture  defaults to  arm64 .

Step 2: Define three ways for a tool call to fail

Each FIS template targets  issue_refund  and does one thing:
Template
FIS action
What the tool does
What the agent sees
 precommit 
 aws:lambda:invocation-error ,  preventExecution=true 
Nothing
An error
 lost_ack 
 aws:lambda:invocation-error ,  preventExecution=false 
Commits the refund
An error
 inflight 
 aws:lambda:invocation-add-delay , 8,000 ms
Commits the refund, 8 s later
A timeout after 4 s
 preventExecution=false  is the setting that makes  lost_ack  nasty: the handler runs, the refund is written, and FIS still hands the caller an error. The  inflight  fault works because FIS adds the delay before the handler runs. The client gives up at 4 seconds, but Lambda keeps going, so the refund lands 4 seconds after the agent has decided it failed.
Here is how the templates are built. One  for_each  over a map of faults:
locals {
faults = {
lost_ack = {
description = "issue_refund commits, then the caller receives an error"
action_id = "aws:lambda:invocation-error"
parameters = {
duration = var.fault_duration
invocationPercentage = tostring(var.invocation_percentage)
preventExecution = "false"
}
}
inflight = {
description = "issue_refund is delayed past the caller's timeout, then commits"
action_id = "aws:lambda:invocation-add-delay"
parameters = {
duration = var.fault_duration
invocationPercentage = tostring(var.invocation_percentage)
startupDelayMilliseconds = tostring(var.delay_ms)
}
}
# precommit omitted here, same shape with preventExecution = "true"
}
}

resource "aws_fis_experiment_template" "fault" {
for_each = local.faults
description = each.value.description
role_arn = aws_iam_role.fis.arn

stop_condition {
source = "aws:cloudwatch:alarm"
value = aws_cloudwatch_metric_alarm.over_refund_budget.arn
}

action {
name = each.key
action_id = each.value.action_id
dynamic "parameter" {
for_each = each.value.parameters
content {
key = parameter.key
value = parameter.value
}
}
target {
key = "Functions"
value = "refund-tool"
}
}

target {
name = "refund-tool"
resource_type = "aws:lambda:function"
selection_mode = "ALL"
resource_arns = [aws_lambda_function.issue_refund.arn]
}
}
The target key inside  action  has to be  "Functions"  for Lambda actions. I couldn't find that spelled out in one place, so I confirmed it by deploying.
The three experiment templates in the FIS console

The stop condition watches dollars, not duplicates. My first instinct was to stop the experiment the moment  DuplicateSideEffects > 0 . That would have stopped every baseline run after one episode, before I learned anything. Duplicates are the thing being measured. The alarm instead watches over-refunded dollars per minute, with a $500 budget by default. That's a blast-radius limit, which is what a stop condition is for.

Step 3: The agent, and a checker that doesn't trust it

The harness calls the tools the way a real agent framework would, synchronously and with a client-side read timeout:
cfg = Config(
region_name=region,
read_timeout=read_timeout, # 4 s by default
connect_timeout=5,
retries={"mode": "standard", "total_max_attempts": sdk_max_attempts},
)
self.client = boto3.client("lambda", config=cfg)
Keep an eye on  total_max_attempts . It comes back later.
After each conversation the checker waits for late commits (the 8-second delay plus 6 seconds), counts the refund items for that order, and compares the count with the agent's claim. An episode is correct only if exactly one refund committed and the agent said  REFUNDED . Two or more refunds is a duplicate, whatever the agent said. It then publishes  DuplicateSideEffects ,  FalseSuccessClaims  and  OverRefundUSD  to CloudWatch.
One mistake I made here is worth admitting. My first checker labelled any duplicate where the agent didn't claim success as  DUPLICATE_ADMITTED . Episode one of my first run got that label, and the label hid the worst part: the agent hadn't admitted anything. It told the customer  NOT_REFUNDED  while three refunds went out. I split the label into  DUPLICATE_UNKNOWN ,  DUPLICATE_DENIED  and  DUPLICATE_CLAIMED_OK . Outcome labels need to separate "hedged" from "denied", or they hide the case that matters most.

Step 4: Run it and watch it break

A baseline with no fault first, to make sure the agent works at all:
python harness/run_experiment.py --fault none --contract v1 --episodes 2 --no-metrics
Both episodes went  get_order ,  issue_refund ,  report_outcome  with one refund each. Then the in-flight fault:
python harness/run_experiment.py --fault inflight --contract v1 --episodes 3
 run_experiment.py  starts the FIS experiment, sends no-op probe calls until the fault is visibly active, runs the episodes, and stops the experiment when it's done, because FIS bills per action-minute. Here's the real output from episode one:
[18:53:56] fault visible to the probe after 66s of probing
[18:53:58] episode 1/3 order=ord-40d61e82a0
[18:54:01] turn 0: get_order -> ok (1907 ms)
[18:54:07] turn 1: issue_refund -> timeout (4005 ms)
[18:54:12] turn 2: issue_refund -> timeout (4760 ms)
[18:54:19] turn 3: issue_refund -> timeout (4961 ms)
[18:54:21] turn 5: report_outcome -> local (0 ms)
[18:54:35] claim=NOT_REFUNDED committed=3 -> DUPLICATE_ADMITTED
(That last label is the misleading one from my first checker.)
The Lambda logs show exactly what happened to each call. The FIS extension logs the delay with a request ID:
FIS extension adding 8000 ms to request 9b43a830

At 18:54:03 FIS held request  9b43a830  for 8 seconds. The agent's client gave up at about 18:54:07. Then, at 18:54:11.670, that same request committed refund  rf-8e86826a6ed7 :
The same request committing the refund eight seconds later

Put all three attempts on one timeline and the whole episode is in one picture:
Timeline of order ord-40d61e82a0: three timed-out attempts, three refunds committed after the client gave up, the last one 2.5 seconds after the agent reported NOT_REFUNDED

Look at the last refund. The agent told the customer  NOT_REFUNDED  at 18:54:21. The third refund committed at 18:54:23.53, two and a half seconds later. By the time the agent spoke, its answer was already wrong, and it got more wrong afterwards.
Back in the Lambda logs, the second commit is in a different log stream from the first. The first execution environment was still sitting in its 8-second delay, so Lambda started a new one for the retry. Retries under a slow dependency can land on cold environments, and each new environment has to pick up the FIS configuration on start.
The FIS experiment that produced this run


The results

I ran a matrix of faults, contracts and models. Same prompt every time: "Hi, my order {id} arrived broken. Please refund the full $49.99."
Fault
Contract
Model
Episodes
With duplicates
Extra refunds
in-flight
v1 (no key)
Nova 2 Lite
8
8
9
in-flight
v1, SDK retries on
Nova 2 Lite
3
3
18
in-flight
v2 (model's key)
Nova 2 Lite
5
0
0
in-flight
v3 (harness key)
Nova 2 Lite
5
0
0
in-flight
v3, request-ID key (re-test)
Nova 2 Lite
3
0
0
in-flight
v1 (no key)
Nova Pro
3
3
3
in-flight
v3 (harness key)
Nova Pro
3
0
0
lost ack
v1 (no key)
Nova 2 Lite
5
5
5
lost ack
v3 (harness key)
Nova 2 Lite
3
0
0
pre-commit
v1 (no key)
Nova 2 Lite
3
0
0
The counts are refund items committed to the ledger, not Lambda invocations. An invocation that timed out or returned an error can still have committed a refund, which is why the checker reads DynamoDB instead of trusting the tool's response.
Only two things retried in these runs: the model, which called  issue_refund  again after an error, and in the second row the AWS SDK. The harness itself never retries a tool call.
These are small samples from one Region at temperature 0. Treat them as a demonstration, not a benchmark.
Duplicate refunds per minute by contract and model

The tall red spike is the SDK-retry run. Four things in that table surprised me.
1. The SDK tripled every call before the model saw anything. Look at the second row. Same fault, same model, but I let botocore use 3 attempts instead of 1. The SDK retried each timed-out  Invoke  on its own, so every tool call the agent made became three Lambda invocations. The agent saw a single error after about 15 seconds and had no idea three refunds were in flight. One order got nine refunds. Most SDKs retry by default, which is sensible for reads and dangerous for a tool that moves money.
This applies to transport failures like a read timeout. When the function itself fails, the  Lambda Invoke API  still returns status 200 for a synchronous call and reports the failure in the  X-Amz-Function-Error  header, so the SDK has no failed request to retry. I didn't run the lost-acknowledgement fault with SDK retries on, so I haven't measured that case.
2. The two models failed differently. Nova 2 Lite never once claimed  REFUNDED  while a fault was active. It hedged with  UNKNOWN , or told the customer  NOT_REFUNDED  while money had moved. Nova Pro did something the paper describes: in two of its three no-key episodes it retried, then called  get_order , saw a refund, and told the customer  REFUNDED . That was true but incomplete, because there were two. It did check the order, but only after it had already retried.
3. Reading back doesn't save you from in-flight requests. In the  lost_ack  fault the refund is already in the ledger when the error arrives, so a  get_order  call would reveal it. Nova 2 Lite never made that call and duplicated all five times. In the  inflight  fault, even an agent that checks immediately finds nothing, because the handler hasn't run yet. The paper proves this formally: without a bound on how long a request can stay in flight, no amount of checking gets you exactly-once. You need the key.
4. The pre-commit fault was the easy one. When nothing commits, the agent retries, nothing commits again, and it reports  UNKNOWN . That's the safe case, which is exactly why testing only "the tool threw an error" gives you false confidence.

The fix: put the key in the contract, and let the harness own it

The tool change is small. If the caller sends an  idempotency_key , it becomes the refund's sort key and the write is conditional:
refund_id = idempotency_key or f"rf-{uuid.uuid4().hex[:12]}"
...
if idempotency_key:
try:
refunds.put_item(Item=item, ConditionExpression="attribute_not_exists(refund_id)")
except ClientError as err:
if err.response["Error"]["Code"] != "ConditionalCheckFailedException":
raise
existing = refunds.get_item(
Key={"order_id": order_id, "refund_id": refund_id}, ConsistentRead=True
)["Item"]
return {"ok": True, "status": "ALREADY_APPLIED",
"refund_id": refund_id, "amount_usd": float(existing["amount_usd"])}
A replay returns the original refund instead of writing a new one. A late commit and a retry with the same key can't both succeed, because DynamoDB enforces the condition no matter which one arrives first.
I tested two ways of supplying the key.
  • v2: the model picks it. The tool schema requires  idempotency_key , and errors come back structured:  commit_status: UNKNOWN , with a note that retrying with the same key is safe. Nova 2 Lite reused its own key on every retry, so all five episodes committed exactly one refund. Look at the keys it chose, though:  refund_1  for one order,  refund_1  again for a different order, then  refund-broken-item-ord-d9e23d582b ,  refund_ord-359b184678_full  and  refund_73ebba21b0_01 . Using  refund_1  twice was harmless here only because the ledger scopes the key to the order ( order_id  is the partition key). Against an API with account-wide idempotency keys, the second customer's refund would have come back as  ALREADY_APPLIED  and never been paid.
  • v3: the harness attaches it. The harness creates one refund-request ID when the customer's request arrives ( rq-  plus a UUID) and adds it to every  issue_refund  call for that request. The model never sees it, so it can't forget it or invent a new one.
The key has to identify one logical operation, not the order. My first version of v3 hashed the order ID and amount. That worked in these tests, because every order had exactly one refund request, but two genuine $49.99 refunds on the same order would have produced the same key, and the second customer request would have come back as  ALREADY_APPLIED . I changed the harness to generate the request ID instead, and re-ran the in-flight fault with the new code: three episodes, two timeouts each, exactly one refund per order.
Ledger for a re-test order: one refund item, keyed by the harness-generated request ID

The  contract  column says  v2  because the tool only records that a key arrived. From the tool's side, v2 and v3 look the same; they differ only in who created the key.
Both scored zero duplicates in my runs. I'd still ship v3, partly because of that  refund_1  collision. The paper found that every duplicate left after offering keys came from an agent that sent its first attempt without a key or changed the key on retry. With v2, safety depends on the model picking a sensible key every time. With v3 it doesn't depend on the model.
With v3, Nova Pro also started reporting correctly: it timed out, checked the order, retried, checked again, and told the customer  REFUNDED  with exactly one refund in the ledger, in all three episodes.
The full checklist for a tool that changes something in the world:
  1. Accept an idempotency key and enforce it with a conditional write.
  1. Have the harness generate the key per logical request, not the model.
  1. Turn SDK retries off for that tool, or make sure it's idempotent first.
  1. Return a structured error that says the commit status is unknown, so the model doesn't guess.
  1. Give the agent a read-back tool, but don't count on it for in-flight requests.

Proving the stop condition works

I didn't want to trust a stop condition I'd never seen fire, so I tested it.  scripts/stop_condition_test.sh  lowers the budget to $40 a minute, runs the worst case (in-flight fault with SDK retries), and restores the budget afterwards.
bash scripts/stop_condition_test.sh
In the minute starting 19:58 UTC, $399.92 of extra refunds went out, eight duplicate refunds at $49.99. The alarm fired:
{
"oldState": "OK",
"newState": "ALARM",
"stateReason": "Threshold Crossed: 1 datapoint [399.92 (10/11/26 19:58:00)] was greater than the threshold (40.0).",
"threshold": 40.0
}
and FIS stopped the experiment on its own.  aws fis get-experiment  reported the state as  stopped  with the reason  "Experiment halted by stop condition."  The harness noticed and logged it instead of trying to stop it again:
[20:02:07] experiment EXPkAHm3LyiBi7GFpE already stopped: Experiment halted by stop condition.
[20:02:07] summary: CORRECT=6, DUPLICATE_UNKNOWN=2
Two episodes ran with the fault and duplicated. The six after the halt were all correct, which also confirms the fault really was removed.
Over-refunded dollars per minute against the $40 budget

The experiment stopped by its stop condition

Alarm history: OK to In alarm at 19:59:55 UTC

One thing to plan for: the alarm uses a 1-minute period, so it changed state at 19:59:55, almost two minutes after the start of the minute that breached it. A stop condition limits the blast radius. It doesn't prevent it. Size the budget for what can happen in that window.

Gotchas that cost me time

  • Faults take about a minute to start. From idle, the probe needed 66 to 67 seconds before it saw the fault, even with  AWS_FIS_SLOW_POLL_INTERVAL_SECONDS  lowered from the default 60 to 15. If your test starts sending traffic the moment  start-experiment  returns, your first episodes run without any fault and look great. That's why the harness probes first.
  • ...unless an experiment just ended. When I started a new experiment seconds after the previous one, the probe saw the fault in 5 seconds, and in 18 seconds another time. Warm environments keep polling fast for a while after an experiment. Your ramp-up time depends on what ran before, so measure it instead of assuming it.
  • The Lambda timeout has to be longer than the injected delay. If the function times out during the FIS delay, the handler never runs, and you've built a pre-commit fault by accident. I set the tool timeout to 30 seconds and the delay to 8.
  • The FIS extension doesn't support response streaming, and SnapStart can delay fault pickup. Neither applied here, but check before you attach it to a real function.

Taking it past a demo

I ran everything against a throwaway stack. If you point this at a real system, a few things change. I haven't run these variations myself, so treat them as where I'd start, not results.
  • The templates take  invocation_percentage . Against a shared environment I'd start at 10 to 20% and target a dedicated function alias rather than  $LATEST , so only test traffic is affected.
  •  run_experiment.py  writes a  .jsonl  file per run, so a CI job can run the in-flight fault against a staging stack and fail the build if any episode has  duplicate_side_effects > 0 . That keeps the fix from quietly regressing when someone changes the prompt or swaps the model.
  • Set the stop-condition budget to what you'd accept losing in about two minutes, given the alarm lag above, rather than to zero.
  • The FIS extension needs its configuration bucket in the same Region as the function, so a multi-Region setup needs one bucket per Region.
  • Scope the idempotency key to the thing being changed (here the order) so two customers can never collide, as  refund_1  nearly did.

What it cost

Twelve FIS experiments, including the re-test. Adding up each action's start and end time from  aws fis get-experiment , rounded to the minute the way FIS bills, gives 34 action-minutes, or $3.40. The harness stopping experiments early mattered: each template allows 10 minutes, and no run used more than 3.7. Without the early stop, the same experiments would have cost $12.
All 51 episodes together used about 287,000 input tokens and 13,000 output tokens across both Nova models, which is well under a dollar. Lambda, DynamoDB on-demand and S3 were pennies.

Clean up

bash scripts/cleanup.sh
It stops any experiment still running for this stack, then runs  terraform destroy . The FIS config bucket has  force_destroy = true , because an interrupted experiment can leave config objects behind and block deletion. The custom metrics expire on their own. If you added the IAM statements from  iam/operator-policy.json  to your user, remove them too.

What I'd take from this

Testing agents usually means testing the model: better prompts, better evals. This failure lived somewhere else. The model did roughly what a reasonable person would do with a timeout. The refund code was correct. The duplicates came from the contract between them, which said nothing about what a timeout means.
FIS let me test that contract directly, with the real SDK, real timeouts and real Lambda behaviour, and with an alarm that would have stopped the experiment before it got expensive. If your agent can change anything in the world, break its tools on purpose before your network does it for you.
The code, Terraform and scripts are all here:  github.com/Extraordinarytechy/fis-agent-tool-chaos . I'd like to hear what you find if you run it against a different model.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article