← All papers
First page of When Can Agents Safely Checkpoint, Fork, Restore, and Merge? Exact Checking for Execution Edits

When Can Agents Safely Checkpoint, Fork, Restore, and Merge? Exact Checking for Execution Edits

Yusheng Zheng, Xiaoyu Song, Yanpeng Hu, Lebin Cheng, Yuxi Huang, Wei Zhang

cs.PL Aug 24, 2026 · v1 cs.CR
Lean mechanizes the finite checker and runtime invariant for deciding safety of agent execution edits.
Agent runtimes can Checkpoint an execution, Fork it, Restore a checkpoint, or Merge branches without restarting a task. We call these operations execution edits, with Checkpoint recording the current execution for later use and Fork, Restore, and Merge changing what the Agent will do next. An execution edit cannot undo an earlier authorization or a tool request already sent. An unsafe edit can therefore authorize the same tool action twice, discard a result the task still requires, or conflict with a call that began before the edit. The Agent is untrusted, so the runtime uses its execution record to determine which past actions an edit must account for and which required results it must preserve to keep the subsequent execution safe. Yet existing Agent systems support such operations without deriving what each edit must preserve from the running execution, whereas prior methods for computing safe behavior take that requirement as input. We give an algorithm that decides exactly whether an edit is safe. It returns all safe ways to continue, or proves that none exists. To make this decision, the algorithm lists every way the task can finish without violating policy. It removes any way that could make a still-required result impossible to finish later. If none remain, it returns a checkable proof that no safe implementation exists. Otherwise, the remaining ways describe exactly what the runtime may allow. Our formal results cover Checkpoint and the six forms of Fork, Restore, and Merge, together with extensions, atomic enforcement, and the information every exact checker needs. Lean mechanizes the finite checker and runtime invariant, and tests validate all six edit forms. The source code, Lean proofs, and executable tests are available in the public GitHub repository at https://github.com/eunomia-bpf/agent-check-restore-safety.

Agent runtimes support execution edits (Checkpoint, Fork, Restore, Merge) that can create unsafe states, such as authorizing a tool action twice or discarding a still-required result. Existing systems perform these operations without deriving what each edit must preserve from the running execution.

An algorithm decides exactly whether an execution edit is safe, returning all safe ways to continue or a checkable proof that none exists. It enumerates every way the task can finish without violating policy, removes options that could make a still-required result impossible, and reports the remaining safe continuations. Formal results cover Checkpoint and the six forms of Fork, Restore, and Merge, plus extensions and atomic enforcement.

Lean mechanizes the finite checker and the runtime invariant, and executable tests validate all six edit forms. Source code, Lean proofs, and tests are publicly available.