ClawRouter icon indicating copy to clipboard operation
ClawRouter copied to clipboard

Attach x402 settlement receipt to paid-usage log entries for reconciliation

Open GentechLabs opened this issue 3 months ago • 0 comments

Summary

logUsage() writes each paid request as a JSONL line with the estimated cost / requestCost (resolved locally via resolvePhoneTelemetryCost / getActualPaymentUsd). But the actual x402 settlement receipt — the payment/settlement hash and proof-of-settlement that the facilitator returns when a paid request is honored — is never captured or attached to that usage entry.

For a router whose whole model is "pay-per-call via x402", an agent can therefore only see what the router estimated it spent, not what it actually settled on-chain. There is no way today to reconcile the local spend log (usage-YYYY-MM-DD.jsonl) against real chain settlement.

Why it matters

  • Reconciliation: SpendRecord (spend-control) enforces how much to allow; the receipt is the only ground truth of what was actually paid. Without it, an over-counted estimate or a settlement that partially failed can silently diverge from spending.json / the JSONL trail.
  • Agent bookkeeping / GTA treasuries: agents that keep their own accounting (we run x402 agent treasuries at GenTech) need a verifiable proof-of-payment per hop to reconcile against their wallet.
  • Audit / disputes: a settlement receipt is the cryptographic evidence an agent can present if a paid hop's upstream response is disputed.

Proposal

When a paid x402 hop settles successfully, capture the settlement receipt (the payment_hash / settlement tx / returned proof from the facilitator — whatever the x402 SDK exposes post-settlement) and attach it to the logUsage entry, e.g. a settlement?: { txHash, network, receipt } field. Failures to settle should also be recorded distinctly (rather than leaving only an estimated cost) so the trail is honest.

Happy to implement — this mirrors the settlement-receipt handling we ship in our x402 gateway (GenTech / Haustorium12 gold-402).

GentechLabs avatar Aug 28 '26 17:08 GentechLabs