33.8 When Claude Code gets it wrong
- Approved by
- Panaversity ·
In everyday life. An experienced editor knows which mistakes each writer makes. One writer always confuses "its" and "it's". Another always makes the second chapter too long. The editor reads for those first.
What you will learn. The five mistakes to look for first when you review a durable worker that Claude Code built, what each looks like in the code, and the question that finds it.
Why it matters. Tests check what you thought of. Review finds what you did not. These five mistakes can all pass a weak test suite.
1. A Pi API that does not exist
What it looks like. harness.run(...), new Harness(...), tool.retry, api.checkpoint(). They sound right. None of them is in Pi Durable 1.6.
Why it happens. Pi Durable is new and changes in minor releases. A model trained before the current release may remember an older API, or blend Pi with another framework it knows better.
How to catch it. The build usually fails. Sometimes it does not, because the code is behind an any type. Then ask: "For each Pi call in this file, show me the line in node_modules/@earendil-works/pi-durable where it is defined." A call with no line is invented. The rule in CLAUDE.md, never guess a Pi API from memory, prevents most of these.
2. A side effect in a tool marked safe
What it looks like.
replay: "safe",
async execute({ invoice }) {
await ledger().post(crypto.randomUUID(), invoice); // new key every runor a key saved with api.memo() after the call, or a key made from the time (Date.now()), which also changes on every run.
Why it happens. Claude Code marks tools safe because the docs show safe tools, and because the tests pass. Only a crash at the right moment shows the difference.
How to catch it. For each tool marked replay: "safe", ask two questions. Does it change anything outside? If yes, is its key saved with api.memo() before the outside call, and sent with it? Test 1 catches this for post_invoice. Review catches it for the next tool someone adds.
3. Code that keeps the object awake
What it looks like.
while (!(await approvals.isAnswered(id))) {
await new Promise((r) => setTimeout(r, 60_000)); // check every minute
}or a setInterval, or a WebSocket accepted without the hibernation API (Cloudflare's way to keep a connection open while the object sleeps), or a tool that awaits a promise that settles only when a person answers.
Why it happens. Polling is the first way most code waits, and it works in a test that answers in one second.
How to catch it. Search the code for setTimeout, setInterval, while ( and await new Promise. A durable worker waits by returning { kind: "sleep", ... } from a tool, and by nothing else. Then deploy and watch the active time while one approval waits, as in 33.6.
4. Trusting a signal
What it looks like. An endpoint that takes { taskId, approved, by } from the request body and passes it straight to harness.signal.
Why it happens. The docs show harness.signal with exactly those values, and Pi accepts any answer of the right shape.
How to catch it. Ask: "Where does the value of by come from?" It must come from a token your Worker signed, not from the request. Ask: "What stops a second click?" There must be a one-time claim on the token.
5. Shared state between conversations
What it looks like. const registry = createRegistry() at the top of the file. A cache of invoices in a module variable. A let currentClient outside the class.
Why it happens. It is the shortest code, and in a test with one conversation it works.
How to catch it. Every variable at module scope is shared by every object in the same process. Ask Claude Code to list them, and to explain why each is safe to share. The registry never is.
A review checklist
Use this after every build step in this part. Copy it into your lab folder as REVIEW.md.
- Every Pi call exists in the installed version.
- Every tool marked
replay: "safe"changes nothing, or saves its key withapi.memo()before its outside call. - Nothing waits by looping, sleeping or holding a promise open.
- Every signal is checked: who, what, still valid, used once.
- Nothing about a conversation lives at module scope.
- No secret is in a file.
- Each post carries the release it was made by.
When you find one, do not fix the code yourself. Tell Claude Code what is wrong and ask for a test that would have caught it, then the fix. The test stays, so the mistake cannot come back.
The invariant. Passing tests show the code does what you thought of. Review is for what you did not think of.
Check yourself. Claude Code's approval tool returns sleep correctly, but the code that sends Ana the email is inside the same tool, after approvals.record. Tests pass. What is wrong? (The email is a side effect in a tool marked safe, with no key. If the object dies after the email but before the sleep is saved, the tool runs again and Ana gets a second email. Move the email to its own step, or save a key and let the mail service drop repeats.)
- Owner
- Panaversity