---
title: "Agent Write Timeouts and Interruptions: Which Half Can pi-durable Protect? | XingKaiXin's Upside Down"
description: "In UndoBench, naive retries on timeouts caused duplicate side effects in 54% of failure trials. pi-durable can guard against crash-and-rerun with unsafe replay and api.memo, but it cannot catch HTTP timeouts while the process stays alive."
canonical: "https://xingkaixin.me/en/posts/agent-timeout-retry/"
language: "en"
---

# Agent Write Timeouts and Interruptions: Which Half Can pi-durable Protect?

In UndoBench, naive retries on timeouts caused duplicate side effects in 54% of failure trials. pi-durable can guard against crash-and-rerun with unsafe replay and api.memo, but it cannot catch HTTP timeouts while the process stays alive.

2026年12月1日·1,033 words·5 min read[Read Chinese original](https://xingkaixin.me/posts/agent-timeout-retry/)

[Agent](https://xingkaixin.me/tags/Agent/)pi-durable幂等性运行时

![Agent Write Timeouts and Interruptions: Which Half Can pi-durable Protect?](https://xingkaixin.me/cover/agent-timeout-retry-800.2d3f9046.webp)

AI TranslationAI-translated from Chinese · Site UI stays in English.

The server had already created ticket 781, but the confirmation receipt headed back to the Agent got lost on the wire. The Agent waited until it timed out, submitted the creation request again, and ended up with an extra ticket for the exact same task.

This is the example Tanmay Sah and Dolly Sah used in their November 11, 2026 [talk](https://ai.engineer/code/2026/talks/online-undo-button) at the AI Engineer Code Summit. Their UndoBench benchmark ran 2,880 trials: under normal conditions, the success rate was around 84%, but when faults were injected into tasks the Agent could otherwise finish, only about 47% recovered successfully. Those two percentages have different denominators and cannot be subtracted directly, yet treating timeouts as failures and retrying blindly produced duplicate side effects in **54%** of the failure trials.

The problem is that a timeout itself gives no verdict. When a call times out, the request might never have reached the server, might still be processing, or might have already succeeded with only the receipt dropped. As long as the tool response carries no clue to check against, the model’s only way to move the task forward is usually to call the endpoint again.

Increasing the timeout threshold only helps when the server is genuinely slow; waiting longer still won’t bring back a lost receipt. Writing “verify before retrying” into the prompt doesn’t help either—without a query tool to check state, the model can only reread the same error message.

Broken code can be rolled back with `git revert`, but a created ticket or a sent notification cannot be unsent. [RFC 9110 Section 9.2.2](https://www.rfc-editor.org/rfc/rfc9110.html#section-9.2.2) states that a client should not automatically retry a non-idempotent request unless it knows the endpoint allows safe repetition or that the original request was never executed.

## pi-durable Guards Against Process Interruptions First

When running an interactive Coding Agent like `pi` in a terminal, hitting Ctrl+C twice mid-tool treats that call as if it never happened; a human reopens the session, types `continue`, and picks right back up.

In his November 10, 2026 [talk](https://www.youtube.com/watch?v=EreOxs9Vvrg), Mario Zechner contrasted that with another setting: putting an Agent inside a long-lived Slack bot, or deploying it on Cloudflare Durable Objects where V8 isolates are forcibly recycled every 15 minutes and no developer sits in front of a terminal to type `continue`. To handle that, the Pi team extracted the durable runtime [`@earendil-works/pi-durable`](https://github.com/earendil-works/pi/tree/747c217b81980206063a89e46645b362de7ac8b1/packages/durable).

At the message ingress layer, duplicate Slack deliveries are deduplicated by [`requestId`](https://github.com/earendil-works/pi/blob/747c217b81980206063a89e46645b362de7ac8b1/packages/durable/src/harness/submissions.ts#L229-L237) (referred to informally in the talk as an idempotency key), returning the handle of the existing submission without kicking off a second run.

At the tool execution layer, the scheduling policy is much more conservative. Before calling `tool.execute()`, [`ToolTask`](https://github.com/earendil-works/pi/blob/747c217b81980206063a89e46645b362de7ac8b1/packages/durable/src/harness/tool.ts#L204-L205) calls `commitIntent()` to persist `checkpoint: { phase: "execute" }` to storage and defaults the replay policy `replay` to `"unsafe"`.

In the source code, not even the five built-in coding tools—`read`, `write`, `edit`, `bash`, and `powershell`—are marked `"safe"`; across the whole package, only `tool_search` and `codemode` are.

After a process crash or host eviction, `harness.resume()` sees the task stopped in the `execute` phase with an `"unsafe"` policy, refuses to rerun it silently, and writes `"Tool <name> was interrupted and may have partially run"` back into the context (see the [interruption handling source](https://github.com/earendil-works/pi/blob/747c217b81980206063a89e46645b362de7ac8b1/packages/durable/src/harness/tool.ts#L259-L263)), handing the unknown side effect honestly to the model or human to resolve.

## To Rerun After a Crash, the Idempotency Key Must Be Persisted First

If a write tool genuinely needs to rerun automatically after a crash, it must pin an idempotency key to the local task record before sending the remote request. The [official example](https://github.com/earendil-works/pi/blob/747c217b81980206063a89e46645b362de7ac8b1/packages/durable/test/examples/40-tool-waits-for-webhook.ts#L101-L104) takes just two core lines:

```
const runId = await api.memo("ci.run", crypto.randomUUID(), ctx);
const build = await ci.trigger({ ref, idempotencyKey: runId });
```

[`api.memo`](https://github.com/earendil-works/pi/blob/747c217b81980206063a89e46645b362de7ac8b1/packages/durable/src/harness/scheduler.ts#L2866-L2881) uses a first-writer-wins strategy to persist the initially generated key in `TaskRecord.memos`. Even if the tool crashes after triggering CI and reruns, `api.memo` reads back the old value instead of generating a new UUID.

The same creation or send action must reuse the exact same key on retry so the server can recognize it as the same request.

Marking `replay: "safe"` without storing the key via `api.memo` will generate a fresh key when rerunning from scratch after a crash, causing the remote server to create another ticket anyway. Conversely, if the client records the key properly but the server doesn’t validate it—or if parameters change on retry or the key expires—passing the key accomplishes nothing.

## When the Process Stays Alive and HTTP Times Out, the Runtime Cannot Stop It

Even when a write tool wires up `api.memo` and sets `replay: "safe"`, `pi-durable` still cannot save every ticket 781. `GenerationTask` has built-in exponential backoff retries for model requests, but `ToolTask`’s `replay` branch only triggers when recovering `phase: "execute"` after a process crash or isolate eviction.

When the host process is still alive and an HTTP request inside a tool times out and throws, `ToolTask` catches the exception and settles the task directly as [`tool_error`](https://github.com/earendil-works/pi/blob/747c217b81980206063a89e46645b362de7ac8b1/packages/durable/src/harness/tool.ts#L571-L581); the tool itself has no built-in retry loop.

If the model reads the error on the next turn and calls the ticket-creation tool again, it generates a brand-new `ToolCall` and `taskId`. Because `TaskRecord.memos` is scoped to a single task record, `api.memo` inside the new task generates a different key, and the remote server still creates a second ticket.

**A durable runtime can block blind reruns after a process restart, but it cannot replace idempotency-key propagation and remote state lookup at the tool layer for unresolved timeouts.**

![With replay allowed and a stored key, resuming the same task reads back K1; calling again after an HTTP timeout creates a new task, which generates K2 if the key is not passed across tasks](https://xingkaixin.me/posts/images/agent-timeout-retry/agent-timeout-retry-01.db5dc116.webp)

## The Other Half of the Defense at the Tool Layer

To complete the other half of the defense, the tool layer still needs to do three things well. On a timeout, don’t just throw a generic error—return an explicit “outcome unconfirmed” status along with a checkable identifier or a cross-turn idempotency key.

At the same time, equip the Agent with a read-only lookup tool. Keep in mind that a single “not found” result doesn’t prove the original request never ran; it might still be queued on the server or not yet visible, and resending immediately will still cause a duplicate write.

When the state genuinely cannot be determined, stop and wait for human confirmation. On `pi-durable`’s `main` branch (`Unreleased`), tools can already use `ToolPark` and `defineSignal` to actively park a task, release the process, and resume once an external signal or human confirmation arrives.

Until cross-turn and cross-restart idempotency keys and remote lookups are wired up, keeping write tools at the default `replay: "unsafe"` is the safer choice. Before shipping, test two specific failure modes: dropping the response after the server finishes writing, and killing the process mid-tool, verifying that neither the next turn nor a restart recovery writes a second record.

文中链接

1.  talkhttps://ai.engineer/code/2026/talks/online-undo-button
2.  RFC 9110 Section 9.2.2https://www.rfc-editor.org/rfc/rfc9110.html#section-9.2.2
3.  talkhttps://www.youtube.com/watch?v=EreOxs9Vvrg
4.  @earendil-works/pi-durablehttps://github.com/earendil-works/pi/tree/747c217b81980206063a89e46645b362de7ac8b1/packages/durable
5.  requestIdhttps://github.com/earendil-works/pi/blob/747c217b81980206063a89e46645b362de7ac8b1/packages/durable/src/harness/submissions.ts#L229-L237
6.  ToolTaskhttps://github.com/earendil-works/pi/blob/747c217b81980206063a89e46645b362de7ac8b1/packages/durable/src/harness/tool.ts#L204-L205
7.  interruption handling sourcehttps://github.com/earendil-works/pi/blob/747c217b81980206063a89e46645b362de7ac8b1/packages/durable/src/harness/tool.ts#L259-L263
8.  official examplehttps://github.com/earendil-works/pi/blob/747c217b81980206063a89e46645b362de7ac8b1/packages/durable/test/examples/40-tool-waits-for-webhook.ts#L101-L104
9.  api.memohttps://github.com/earendil-works/pi/blob/747c217b81980206063a89e46645b362de7ac8b1/packages/durable/src/harness/scheduler.ts#L2866-L2881
10.  tool\_errorhttps://github.com/earendil-works/pi/blob/747c217b81980206063a89e46645b362de7ac8b1/packages/durable/src/harness/tool.ts#L571-L581

Zoomed illustration

## Copyright

Author

XingKaiXin

Title

Agent Write Timeouts and Interruptions: Which Half Can pi-durable Protect?

Published

2026年12月1日

Permalink

[https://xingkaixin.me/en/posts/agent-timeout-retry/](https://xingkaixin.me/en/posts/agent-timeout-retry/)

Licensed under [CC BY-NC-ND 4.0 DEED](https://creativecommons.org/licenses/by-nc-nd/4.0/deed.en).

XingKaiXin

Highlights · 0

Contents

Highlights · 0

## Contents

Highlights · 0
