feat(proof-gen-api): return 422 for BlockNotReady#889
feat(proof-gen-api): return 422 for BlockNotReady#889DylanVerstraete wants to merge 1 commit intousc-devfrom
Conversation
PR SummaryMedium Risk Overview API documentation is updated so all proof endpoints advertise the new Tests increase the Swagger JSON response size limit (10 KiB → 32 KiB) to accommodate the expanded OpenAPI document. Reviewed by Cursor Bugbot for commit 40c2720. Bugbot is set up for automated code reviews on this repo. Configure here. |
Block exists but the requested block is not yet attested. The request is well-formed; it just can't be processed in the current state. 404 conflated this with "the block/tx will never exist" and forced clients to inspect the body to tell the two apart. Map BlockNotReady to 422 Unprocessable Entity so clients (e.g. the traffic simulator and SDK) can distinguish "keep waiting" from "give up" by status code alone, instead of pattern-matching on a 500 or 404 body. - errors.rs: BlockNotReady -> UNPROCESSABLE_ENTITY (other NOT_FOUND cases unchanged). - continuity routes: add 422 to utoipa response specs so OpenAPI/ Swagger reflects the new status. - README: document the 422 status alongside the example body. - tests: bump swagger-json body cap to 32 KiB so future response additions don't trip the LengthLimitError again. Requested by Dave.
1666a9b to
40c2720
Compare
There was a problem hiding this comment.
This pr doesn't actually do the thing we need it to. We need to discover why the following edge case produces error code 500. Then we need to change the error handling so that it gives code 422 instead.
Edge case:
- An attestation was just committed on-chain which covers our target block
- That attestation hasn't been finalized yet at the time when the proof gen api receives its proving request
Original message:
Dave wanted me to flag this issue. Basically, we get a really opaque error message when we wait until a block is attested but request a proof from the proof gen server before the attestation is finalized:
Error: Failed to generate proof: Failed to generate proof via API: Error: Failed to fetch proof: AxiosError: Request failed with status code 500
Error code 500 covers quite a few error cases, so I haven't hunted down which one we're hitting. Dave requested this as an alternative error code in this case: 422 Unprocessable Entity
What
Map
BlockNotReadyfrom the proof-gen API to HTTP 422 Unprocessable Entity instead of 404.Requested by Dave: when a client waits until a block is attested but asks for a proof before the attestation is finalized, the server returned an opaque error. On the client side this surfaced as a generic 500 (because the SDK retry/wrap path didn't preserve the underlying status), which covers too many failure modes. 422 makes it cleanly distinguishable from "the tx/block will never exist" (404) and "transient infra failure" (5xx).
Why 422?
retriable: truein the body still tells clients to wait.Changes
proof-gen-api-server/src/services/errors.rsServiceError::BlockNotReady→StatusCode::UNPROCESSABLE_ENTITYTxHashNotFoundandBlockNotOnSourceChainstay on404(they're genuinely "not found").proof-gen-api-server/src/networking/routes/continuity.rs(status = 422, …)to the utoiparesponses(...)on all four proof endpoints so the generated OpenAPI/Swagger spec advertises it.proof-gen-api-server/README.mdBlockNotReadybody.proof-gen-api-server/tests/route_tests.rsto_bytescap from 10 KiB to 32 KiB. The four extra response variants pushed the doc past the old limit and broketest_swagger_json_route_should_return_valid_jsonwith aLengthLimitError. 32 KiB gives headroom for future endpoints.Client impact
The traffic simulator and the SDK already retry on
retriable || status >= 500, andBlockNotReadyisretriable: true, so existing waiters keep retrying as before. The only behavioral change is callers that key off the HTTP status now get a stable, accurate code instead of a 500/404 grab-bag.Verification
cargo fmt -p proof-gen-api-server✅cargo clippy -p proof-gen-api-server --all-targets -- -D warnings✅cargo test -p proof-gen-api-server✅ (27 + 14 tests, all green)