Unit 06.04: Recording what the tool actually did
After an incident, the question is whether the action happened once, twice, or not at all.
Attempt, outcome, external id
A complete tool-call record.
The code prints one.
import json
record = {
"request_id": "r-8841",
"tool": "issue_refund",
"arguments": {"account": "ACC-1187", "amount": 120.0},
"validated": True,
"confirmed_by": "operator-3",
"idempotency_key": "req-8841:refund",
"attempt": 2,
"outcome": "already issued",
"external_id": "rcpt-1",
"duration_ms": 240,
}
print(json.dumps(record, indent=2))
print("\n`attempt` + `outcome` answer: did this happen once, twice, or not at all?")
# `external_id` is what lets you reconcile against the other system. Without
# it your log says a refund was issued and theirs says which refunds exist, and
# nothing joins the two.
attempt: 2 with outcome: already issued answers the question completely: it ran twice and acted once, which is the idempotency guard working. Neither field alone establishes that.
external_id is what lets you reconcile. Without it your log says a refund was issued and the payment system says which refunds exist, and nothing joins the two.
The mistake this prevents
The mistake is logging the call before it returns, which is the natural place. You then have a record of every attempt and none of any outcome, so a call that timed out after succeeding looks identical to one that never ran.
Takeaway
Log the attempt number, the outcome and the external system's id, after the call returns. Those three answer whether the action happened.
