DIM · Dagon Inference Marketplace

Recovery after a restart

The SDK writes every hold, every HTTP outcome and every voucher to a durable journal before it acts on them. After a crash or restart you build the same client again, call reattach() before any new work, and it restores your channels, Mandates, lane counters, unpaid receipts and any half-sent voucher. Receipts for requests that reached the seller are recovered and paid exactly once; requests that never got a 2xx are never paid.

The code on this page assumes the sdk and routes from the buyer quickstart.

The journal

  • With SolanaChannelBackend, the default journal is a single-writer, fsynced file under ~/.im-sdk, scoped to the cluster, program, vault and authority.
  • Choose a location with store: new FileWalletStore(path), plug in your own durable WalletStore, or opt out with store: null. Without a journal, nothing survives a restart.
  • The journal never stores keys, salts or request bodies. On Solana, channel session keys are re-derived from your authority key, so they need no storage either.
  • Only one process may write a journal. Do not delete a live lock to force it open, and do not share the file across hosts.

Restarting

sdk.setRoutes(routes);                 // install the same verified routes first
const channels = await sdk.reattach(); // before any new request or channel open
console.log("restored", channels.length, "channels");

for (const pending of sdk.pendingReceipts()) {
  await sdk.recoverReceipt(pending.channel, pending.requestId);
}
await sdk.flushVouchers();

reattach looks up the vault's open and closing channels and Mandates on-chain, restores lane counters and reservations, revalidates the stored public evidence and restores the exact voucher batch that was in flight. A wallet with stored channels refuses to open new ones until you reattach.

What happens to an interrupted request

Where the crash hit After restart
Before the hold was journaled Nothing was sent. Nothing is owed.
After the hold, before any HTTP status The cap stays reserved. If the seller later produces signed zero-charge evidence, the cap is released; otherwise it stays reserved until the channel closes. Nothing is paid without a valid receipt.
After a non-2xx status Unbillable. A later positive receipt for it is kept as evidence and never paid.
After a 2xx status Billable. The SDK looks the receipt up on the seller (GET /im/v1/requests/{id}/receipt), verifies it and pays it.
During a voucher POST The SDK resends the exact same signed voucher until the seller acknowledges it, so it is never paid twice.
During a channel open The open intent is journaled first. reattach reconciles it with the chain before allowing new funding, so a lost reply never funds a second channel.

sdk.pendingReceipts() lists receipts still owed for 2xx requests; recoverReceipt(channel, requestId) tries one again and resolves true once it is verified. sdk.equivocations() lists signed receipts that contradict an outcome you recorded. One caveat from the SDK: a contradiction after a transport failure is not proof of seller misbehavior, because the seller may have sent a billable response just as your connection broke.

Receipts are local today

Your verified receipts live in your journal and with the seller, which can return a receipt for a request ID you already know. There is no public buyer ledger, and no service yet that syncs receipts across your devices; encrypted private delivery is a planned design, not shipped.