Remote / foldkit-remote-domain
Handle a View that lags behind its write
After a command commits, mutate reads the View at the command's receipt:
| Outcome | What Remote receives |
|---|---|
| Command committed, View caught up | MutationSucceeded with the View's current row |
| Command committed, View still behind | MutationSucceeded with written(reply, input) and after receipt token |
Rejection mapped with refuse | RemoteMutationError carrying the mutation's Refusal |
Rejection mapped with forbid / unauthenticated / fail | RemoteForbidden, RemoteUnauthenticated, or RemoteMutationError |
| Middleware error | RemoteUnauthenticated or RemoteForbidden (via denied) |
| Transport failure or dropped response | RemoteUnreachable; Remote retries with the same operation id |
A committed write is never reported as failed, and an older View row never overwrites it. Remote stores active floors in its Model (surviving persistence restores) and surfaces waiting rows under Data.inspect(model).floors with reason ReadAfter.
Idempotency and derived command ids
Each Remote write carries a stable operation id across retries. The adapter derives Domain's commandId as ${mutation}:${operation}:${digest}, where digest hashes [principal, target, keys, input]:
| Scenario | SQLite ledgered writer | Raw Domain | Through foldkit-remote-domain |
|---|---|---|---|
| Retry with same input and principal | Returns recorded reply | Returns first receipt | Returns first receipt |
| Same operation, different input | Refused | Silently returns first receipt | New command, decided independently |
| Same operation, different principal | Decided in new scope | Skips decide, returns first receipt | New command, decided afresh |
Requests without an operation id fail with RemoteMutationError (Data.mutate always generates one). Lowered writes (Lower.write) enforce the full ledger rule on the aggregate side.