Load the last state
Store the repository ID, branch name, and current commit SHA in your backend. Update this record after each successful state write. When your backend starts a replacement worker, pass the stored values as environment variables.PIERRE_PRIVATE_KEY holds the private key for your Code Storage organization. Keep this key in
trusted server code.
TypeScript
listBranches() and follow nextCursor until you find the branch.
Restore the files
Use an archive when the sandbox only needs a file tree.TypeScript
TypeScript
readUrl, sessionBranch, and tipSha to the new sandbox as READ_URL, SESSION_BRANCH,
and TIP_SHA.
getArchiveStream() for archive filters. See
Connect a Sandbox for the separate push
URL.
Reject stale writes
Write the next state only when the branch still has the tip that you restored.TypeScript
precondition_failed reason. Stop the old
sandbox. Do not retry until your backend assigns a new owner.
For Git pushes, keep no-force-push on the session branch. An old checkout cannot replace the new
commits with a non-fast-forward push.
Record the handoff
StorenextState.commitSha as the current tip. Record which person, agent, and sandbox own the
session.
Use short URL lifetimes. Mint a new write URL for the replacement sandbox. Do not reuse the old
sandbox URL.