# Append, pending contributions and recovery

`records.append` is the same operation for a standalone authority, a hosted
connection and a retained replica. By default it requires authority confirmation.
An online replica submits to its configured authority; stale local contracts or
missing contract-inspection permission do not veto authoritative validation.

```python
result = client.records.append(ledger_id=ledger_id, payload={"your": "record"})
```

Every invocation without `operation_id` creates a distinct operation. Supply a
stable ID when your application needs to retry a known intent. The supplied
client saves its operation ID, request, issuer-qualified principal, destination
binding and dispatch knowledge before sending. Credentials are not stored in
this delivery state. Another principal or edited endpoint cannot inherit it;
renewing credentials for the same verified identity is supported.

## Offline preparation

For an online check before append, use `records limits` and
`records validate --payload @contribution.json` (SDK `client.records.limits` and
`client.records.validate`, MCP `op_sys_records_limits` and
`op_sys_records_validate`, HTTP `GET .../records/limits` and
`POST .../records/validate`). These inspect the current authority and create no
delivery intent or acceptance. `valid` is advisory and may be null when service
bounds are unknown. `not_checked` identifies the remaining append checks.
Attached bytes must already be available to check their contract and size rules.

The permission `records.prepare` below controls offline preparation through
append; it is not a separate command. Online preflight uses `records.append`
permission and `files.read` when files are attached.

Use `confirmation="allow_pending"` to permit preparation while the authority is
unreachable. This is an explicit opt-in, not acceptance:

```python
result = client.records.append(
    ledger_id=ledger_id, operation_id="my-application-operation",
    payload={"your": "record"}, confirmation="allow_pending",
)
# accepted: authoritative acceptance metadata
# pending: operation_id, context_id and selected contract
# uncertain: operation_id and check_outcome recovery guidance
```

The replica needs previously authorized validation context obtained by clone or
synchronize. Its verified principal must have both `records.append` and
`records.prepare` in the observed ledger policy, plus `contracts.read` and the
actual selected schema. Known invalid payloads, retired contracts, denied rights,
archived/deleted ledgers and missing validation context fail before storage.
`records.prepare` does not grant admission, payload reading or governance.
New ledger owners receive it with their other initial rights; administrators may
exclude it from any contributor's policy.

The original default selector and its resolved contract are separate. Supplied
clients preserve the latter in `resolved_contract`; HTTP integrations can also
supply this field when replaying prepared work. Omit it for ordinary online
appends. It does not change an omitted selector into an explicit selector.
Authorities enforce the selected contract's admission and immutable retry
binding. An accepted replay resolves before applying new-admission retirement
or revision checks. Changing the original payload, explicit selector or principal
under the same ID conflicts. A contradictory resolved contract also conflicts.

Pending contributions are private to the client context. They never appear in
record list/get results or accepted-history replication. They do not become
accepted when connectivity returns. Run synchronization explicitly:

```sh
op-sys ledgers sync --ledger-id LEDGER
op-sys ledgers status --ledger-id LEDGER
op-sys contributions status --ledger-id LEDGER --context-id default --operation-id OPERATION
op-sys records outcome --ledger-id LEDGER --operation-id OPERATION
op-sys contributions withdraw --ledger-id LEDGER --context-id default --operation-id OPERATION
```

The same operations are available as `client.ledgers.sync/status`,
`client.contributions.status/withdraw`, `client.records.outcome`, and the
corresponding `op_sys_...` MCP tools. Use `context_id` on append, file preparation,
status, outcome and synchronization when using a named context instead of
`default`. Direct HTTP clients use append with a stable operation ID and the
read-only outcome endpoint; a service cannot inspect or withdraw another
device's private work. No local API server is required.

## Files and delivery

On an online replica, `files.upload` submits to the authority. When unreachable,
it can prepare bounded local bytes using the observed `files.upload` and
`records.prepare` permissions. Files remain subject to the ledger
contract when attached to a record. A prepared contribution retains its required
local bytes independently of replaceable read caches. Synchronization uploads
missing required files before submitting the record, using the original verified
identity. Referencing an existing authority file still requires the authority's
file permissions. A File's local availability is not record acceptance.

Each explicit synchronization attempts at most 100 eligible contributions. It
then continues the existing bounded accepted-history/file synchronization.
Delivery-only clients can also synchronize saved attempts without cloning history.
Their status explicitly describes client contribution coverage, not a complete
record snapshot. Retained unresolved work is bounded to 1,000 contributions and
128 MiB of encoded private state per ledger. Status returns at most 1,000 entries,
prioritizing unresolved work and rejections; individual status remains available
by ID. A dispatch claim lasts 30 seconds before another explicit synchronization
may retry it with the identical identity and request. This is not a background
retry timer.

## Uncertainty and withdrawal

A successful withdrawal applies only to work this client has never dispatched.
An atomic storage claim decides whether withdrawal or dispatch wins. Once a
request may have left the client, withdrawal only checks its outcome. An absent,
unavailable, erased or expired outcome never certifies cancellation: an earlier
in-flight request could still commit. Status and outcome checks never append,
retry or schedule anything.

Authoritative rejection stops automatic delivery and retains a stable diagnostic.
An identical append retry returns that saved rejection without dispatching again,
including after restart or restoration of access. Reusing its ID with changed
input returns `operation_conflict`. Correct the input or make another attempt as
a new explicit contribution with a new ID. A transient
failure retains uncertainty; retry or synchronize with the original identity.
Accepted, rejected and withdrawn entries minimize private payload/byte copies,
retaining identity and diagnostics. Unresolved intent survives ledger deletion
and snapshot replacement; neither action silently withdraws it. Local state
remains under the consumer's own storage/backup retention policy.

When a replica can read records, a confirmed append can be retained for immediate
get-by-ID. This convenience does not advance list snapshots or change checkpoints
past unseen records. Current authority checks still control payload disclosure.
If local persistence fails after authority acceptance, the result remains
`accepted` with `local_availability="not_retained"`; use outcome and synchronize
to recover. Read-after-append never grants an append-only principal record reads.

## Local state and updates

Delivery state belongs to the current client and its verified identity. Back it up
with the private state root when needed. Obsolete record/batch formats are not
translated into replayable contributions. Existing stores are never reset merely
to install a new package; see [installation](/docs/raw/manuals/installation.md) and the recovery
boundaries in [self-hosting](/docs/raw/manuals/self-hosting.md).
