# Archive, erasure and deletion

These operations are implemented in the source checkout through CLI, SDK, MCP
and hosted HTTP. They are not a release availability announcement. Select the
connection and ledger as for any other core operation.

| Operation | Permission | Effect |
| --- | --- | --- |
| `ledgers.archive` | `ledger.archive` | Stops new contributions; keeps retained history. |
| `ledgers.reopen` | `ledger.archive` | Allows new contributions under current rules. |
| `records.erase` | `records.erase` | Removes one accepted record representation. |
| `files.erase` | `files.erase` | Removes one file's bytes and descriptor. |
| `ledgers.delete` | `ledger.delete` | Removes all retained records, files, contracts and descriptive metadata. |

Every operation requires the current ledger `expected_revision`. A stale revision
returns `revision_conflict` and applies nothing. Inspect again and decide whether
the same change is still appropriate; clients never blindly revise a destructive
request. Archive/reopen/delete increment the definition revision when they change
state. Record/file erasure does not edit the definition. Repeating an already
applied transition at the current revision is a no-op, still subject to permission
and hosted legal-hold checks.

## Archive and reopen

```sh
op-sys --output json ledgers get --ledger-id <ledger-id>
op-sys --output json ledgers archive --ledger-id <ledger-id> --expected-revision 1
# Assuming no intervening definition changes:
op-sys --output json ledgers reopen --ledger-id <ledger-id> --expected-revision 2
```

An archived ledger permits authorized reads, access administration, resolution of
already accepted operations and retention/erasure. It rejects new records, file
uploads, contract publication, metadata/admission changes and state-changing record contributions.
A configuration containing only a policy change remains allowed; mixing it with
a blocked change rejects the whole configuration. Authority fencing still applies.
Existing-history replication remains subject to its own permissions and authority
checks; archive never grants replication rights by itself.

## Irreversible removal

```python
# client uses its selected local or hosted connection.
current = client.ledgers.get(ledger_id=ledger_id)
client.records.erase(ledger_id=ledger_id, record_id=record_id,
                     expected_revision=current['revision'])
client.files.erase(ledger_id=ledger_id, file_id=file_id,
                   expected_revision=current['revision'])
```

The corresponding native MCP tools are `op_sys_records_erase` and
`op_sys_files_erase`; they declare destructive effects. HTTP uses
`DELETE /v1/ledgers/{ledger_id}/records/{record_id}` or
`DELETE /v1/ledgers/{ledger_id}/files/{file_id}`, with `expected_revision` in the JSON
body. Ledger archive/reopen/delete use POST to their respective ledger subpaths.

An erased record returns `record_erased` to a currently authorized reader; a
reader without permission receives `permission_denied`. Its operation can report
`erased` under the caller's current outcome permissions, but cannot be appended
again using the same operation identity. Acceptance detail and contract references
in retry facts are minimized. The non-reuse reservation retains the operation and
record IDs, original principal and intent digest; it does not retain the payload.
Lists contain only retained records. Missing items in a partial list never prove
removal, and a view cannot be reconstructed from erased history.

An erased file reports `availability: erased` with only its ledger/file identity.
Accepted attachments keep pointing to that identity; replacement bytes need a new
File. Erasing a record does not implicitly erase its files, which may be shared by
other records. Explicit ledger deletion erases both.

Deleted ledgers cannot be reopened. The authority retains a minimal identity,
revision, authority and access-policy reservation for authorized inspection and
non-resurrection. Public deleted-ledger projections have a null name/default
contract and empty metadata/admission lists. Other resource operations return
`ledger_deleted`; outcome resolution remains subject to its original permissions.

## Retention, holds and restoration

Hosted legal holds take precedence over record/file erasure and ledger deletion.
All use the same tenant transaction lock as contribution admission, hold changes,
retention and tenant deletion. Archive itself is allowed under a hold. Retention
uses the same removal positions and retry minimization as explicit erasure.
Erasure does not refund past accepted usage or release lifetime admission limits.
Tenant deletion still runs in bounded, restartable batches and removes operation,
removal and file state before completing its existing key-destruction procedure.

Standalone local storage has no hosted legal-hold service. Its operator controls
the device, backups and applicable retention obligations. Ordinary supported
operations preserve tombstones; they cannot prevent an operator from manually
replacing the whole storage directory or accessing a copy already downloaded.

Removal facts currently remain for the ledger lifetime; they are not pruned by
record retention. No full-payload change log is retained. Later change-token
support must require resnapshot whenever its coverage is unavailable, and future
compaction must preserve identity reservations.

Storage restore refuses a backup that would discard known removals with
`ledger_removal_conflict`, before changing the live store. Use a newer snapshot
that contains those removals. A current snapshot round-trips minimal reservations.
This check uses the target's retained knowledge: it cannot discover removals absent
from both the target and the backup. The later replication/import patches handle
reconciliation with a reachable authority. Old external backups and downloaded
files remain the operator's responsibility; deleting a ledger does not remotely
erase them. Separate pending client intent is not silently canceled or deleted.
