Skip to content
Français

Recover work

Inspect retained worktrees and transfers before restoring or cleaning them up.

When a run stops before its changes can be integrated, inspect the work Outpost retained. Use the recovery inventory to locate worktrees, downloaded transfers and backups before restoring or removing anything.

WhatWhereKept when
Worktree.outpost/workspaces/The run failed, integration conflicted, or the worktree is dirty, detached or holds ignored files (node_modules, copies).
Remote transfer.outpost/recovery/Changes from a cloud sandbox could not be applied to your checkout.
Conversation.outpost/conversations/ or the agent’s own storeAfter each turn and on failure. See Conversations.
Workflow progress.outpost/storage/ or your transportAfter each finished task. See Durable runs.

A retained worktree is an ordinary Git worktree on its branch: open it, commit what you keep and merge the branch.

recoveryDetails() returns what Outpost attached to the error: branch, directory, commits, transcript and logReference when available.

import {
  dispatch,
  OutpostError,
  recoveryDetails,
} from "@elie-laloum/outpost/core";
import { coder, repository, sandboxProvider } from "./outpost.config.ts";

try {
  const result = await dispatch({
    repository,
    sandboxProvider,
    agent: coder,
    branch: { mode: "named", name: "outpost/upgrade-deps" },
    brief: { text: "Upgrade the test dependencies and commit the change." },
  });
  if (result.retainedDirectory) console.log("Kept:", result.retainedDirectory);
  // Example output: Kept: /project/.outpost/workspaces/…
} catch (error) {
  console.error(recoveryDetails(error));
  if (error instanceof OutpostError) console.error(error.code, error.details);
  throw error;
}

Two failures also name their location in error.details. Errors lists every code.

API reference: recoveryDetails.

When the run itself also failed, the synchronization error arrives inside an AggregateError.

A transfer holds two sides: previous, your checkout before the sandbox’s changes, and incoming, the sandbox’s changes. Restore one side into a new directory, never over your checkout.

  1. Inspect and verify. List retained work, then check the transfer’s files, checksums and Git history. These operations change nothing.
  2. Restore separately. Preview the recovery plan, then use --apply to create a detached checkout in a new directory.
  3. Review and integrate. Compare it with your repository, then commit, cherry-pick or merge only the work you decide to keep.
npx outpost recovery inspect --repository /projects/app --git --locks --resources

API reference: RecoveryInspectionOptions.

The command exits with status 1 when the inventory is incomplete.

npx outpost recovery transfer verify --path "$TRANSFER" --checksums --restorability --repository /projects/app

$TRANSFER is the directory from details.recovery. --checksums compares each file with the transfer’s manifest; --max-bytes bounds the bytes hashed. --restorability rebuilds the commits and patches in a temporary clone of --repository. The command exits with status 1 when a check fails.

npx outpost recovery transfer restore --path "$TRANSFER" --repository /projects/app \
  --destination /projects/app-recovered --side incoming

This prints the plan. Run it again with --apply to create the checkout: a clone of your repository detached at the restored commit, with the side’s patches and files applied and no origin remote.

API reference: RecoveryRestoreOptions.

The destination must not exist and must be outside the repository, its Git metadata and the transfer. The transfer stays in place.

git -C /projects/app-recovered status
git -C /projects/app-recovered switch -c recovered
git -C /projects/app-recovered add -A
git -C /projects/app-recovered commit -m "Recover sandbox changes"
git -C /projects/app fetch /projects/app-recovered recovered:outpost/recovered

The work is now the outpost/recovered branch of your repository. Review it and merge it like any other branch.

Each command has a function. planRecoveryRestore() returns the plan; restoreRecoveryTransfer() checks that nothing changed since and applies it.

export const repository = "/projects/app";
export const transfer = process.env.TRANSFER!;
import {
  inspectRecovery,
  verifyRecoveryTransfer,
} from "@elie-laloum/outpost/recovery";
import { repository, transfer } from "./recovery-target.ts";

export async function verifyTransfer() {
  const inventory = await inspectRecovery({
    repository,
    git: true,
    locks: true,
  });
  console.log(inventory.git?.workspaces);
  // Example output: [ { branch: "outpost/fix-tests", … } ]
  const verification = await verifyRecoveryTransfer(transfer, {
    checksums: true,
    restorability: true,
    repository,
  });
  if (!verification.complete)
    throw new Error("The transfer failed verification");
}
import { verifyTransfer } from "./verify-transfer.ts";
import {
  planRecoveryRestore,
  restoreRecoveryTransfer,
} from "@elie-laloum/outpost/recovery";
import { transfer, repository } from "./recovery-target.ts";

await verifyTransfer();
export const plan = await planRecoveryRestore({
  directory: transfer,
  repository,
  destination: "/projects/app-recovered",
  side: "incoming",
});
export const restored = await restoreRecoveryTransfer(plan);
console.log(restored.directory, restored.commit);
// Example output: /project/.outpost/workspaces/… 8f3a21c…

inspectRecovery({ transporter }) lists the objects of a transport instead of a local repository.

archiveRecovery() verifies a transfer and uploads it through a transport. materializeRecoveryArchive() downloads it on any machine and checks its checksums again.

import {
  archiveRecovery,
  materializeRecoveryArchive,
} from "@elie-laloum/outpost/recovery";
import { createLocalTransport } from "@elie-laloum/outpost/core";
const transporter = createLocalTransport({ directory: "/mnt/shared/outpost" });
const reference = await archiveRecovery({
  transporter,
  directory: process.env.TRANSFER!,
});
const staging = await materializeRecoveryArchive({
  transporter,
  reference,
  destination: "/projects/transfer-copy",
});
console.log(staging);
// Example output: /project/.outpost/recovery/run-1

Keep reference (a key and a revision) to find the archive. Pass staging as --directory to outpost recovery transfer restore, with a clone of the source repository.

A crashed workflow or candidate race keeps ownership of its checkpoint. After stopping the old process, release it with recoverWorkflowCheckpoint() (Durable runs) or recoverSpeculation() (Competing candidates).

An empty lock, an orphan .reclaim file, or an owner whose identity cannot be established on macOS or Windows requires explicit recovery. First stop every process using that lock directory, including other recovery commands. The operation does not stop processes for you. Inspect one filename from the lock inventory:

npx outpost recovery unlock --directory /projects/app/.outpost/locks --lock 0123456789abcdef0123.json --json

Use the returned revision to apply recovery. Changed files and confirmed active owners are refused. For an orphan reclamation guard, inspect and recover the .json.reclaim filename first, then inspect the main lock again. Empty or malformed files can be recovered through the same flow. Recovery removes only that lock file and retains workspaces and branches.

npx outpost recovery unlock --directory /projects/app/.outpost/locks --lock 0123456789abcdef0123.json --revision INSPECTED_REVISION --processes-stopped --apply

Local Transport locks use the same command with --directory /projects/app/.outpost/storage/.outpost/locks, or the corresponding custom Transport directory. Recovery is an offline operation: filesystem unlink is not a compare-and-swap operation, so the inspected revision does not replace the requirement to stop all writers and serialize recovery. Automatic acquisition still refuses unknown ownership.

For directory and ephemeral resources, inspect recovery inspect --runtime-directory PATH. Publication inspect, finish and rollback operate on their own journal without rerunning workflow tasks. Writable mount effects remain immediate and have no publication rollback. See file recovery.

  • Checksums detect damage against an unsigned manifest; they do not prove who produced the transfer.
  • Restorability covers commits, the bundle and patches, not submodules or external dependencies.
  • A transfer is restorable only once the host backup ran: a synchronization that failed during download or validation leaves no state.json, and the restore plan rejects it.
  • A lock PID or recorded activity is an observation. It does not prove that a remote process has stopped.
  • A worktree reported clean can still hold ignored files, such as copies or node_modules.
  • An archive holds recovery files, not the repository: restoring still needs the source repository.

API: recoveryDetails · inspectRecovery · verifyRecoveryTransfer · planRecoveryRestore · restoreRecoveryTransfer · archiveRecovery · materializeRecoveryArchive.