Paid enhance jobs that can't be queued are refunded on the next sweep
If an x402 payment for POST /api/v1/enhance settles and the job then can't be stored or queued, we now mark the payment failed in the same request — so the refund sweep picks it up on its next pass instead of waiting for the daily watchdog.
For x402 callers, POST /api/v1/enhance settles the USDC payment before it stores your upload and enqueues the job. There is a narrow window between those steps: storage unavailable, a failed write to R2, or the queue binding being down. The endpoint has always answered 503 in that window, but the payment was left pending. The pending-payment watchdog deliberately skips enhance payments — their jobs legitimately stay pending while the queue consumer runs — so the only thing that could pick the row up was the enhance-jobs watchdog on its next daily run: up to about a day before a refund could start.
That gap is closed. Every post-settlement failure — storage or queue unavailable, a failed R2 write, a job row that could not be created, or an Idempotency-Key that cannot be accepted — now marks the payment failed in the same request, so the automatic refund sweep (which runs every ten minutes) submits the refund on its next pass. Where a job row exists it is marked failed too, with the reason; the same reason is recorded on the payment for the refund worklist.
What this means if you hit it: you get a 503 with a short error (Storage unavailable, Could not store input PDF, Queue binding unavailable, or Could not enqueue job). Retry the request — you are not charged twice for the failed attempt, and the USDC for it comes back to the paying wallet automatically. Wallet callers are still polled through the same statusUrl for jobs that were accepted; nothing changes on the success path.