Skip to content

fix: classify failed results in await_result - #181

Open
agocharbhatia wants to merge 2 commits into
hotdata-dev:mainfrom
agocharbhatia:fix-await-result-failures
Open

agocharbhatia wants to merge 2 commits into
hotdata-dev:mainfrom
agocharbhatia:fix-await-result-failures

Conversation

@agocharbhatia

@agocharbhatia agocharbhatia commented Nov 13, 2026 •

Copy link
Copy Markdown

Summary

await_result should classify HTTP 409 as a failed result, matching the polling path used by query(). Both paths now share the same small error classifier.

- HTTP 409 -> generic API error unless the body parses with status="failed"
+ HTTP 409 -> Failed { requested result_id, optional typed error_message }

The HTTP status is authoritative, including for empty, malformed or non-failed bodies. Other HTTP errors retain their original status, content and classification.

Evidence

  • Three new regression tests fail on the previous PR head and pass with this update. The identical suite also checks typed messages, requested IDs, ready rows, successful-HTTP failures and processing-to-failed polling.
  • A public query_in test exercises the existing auto-follow path across the same 409 shapes and 404/500 controls.
  • All 12 loopback regression tests, 103 library tests and 12 bearer-provider tests pass locally on Rust 1.97.1. Formatting and focused strict Clippy pass.
  • Full-target strict Clippy reports the same seven await_holding_lock errors in unchanged environment-guard tests on both heads. Documentation builds with warnings. Optional Arrow features and live backend tests were not run.

Merge Danger

Door: Two-way.

Blast Radius: Limited to result-error classification. Any result-endpoint 409 now returns AwaitResultError::Failed; the existing query behavior is preserved. Requests, retries and deadlines are unchanged.

@agocharbhatia
agocharbhatia requested a review from a team as a code owner November 13, 2026 05:18
@agocharbhatia
agocharbhatia requested review from zfarrell and removed request for a team November 13, 2026 05:18

@zfarrell zfarrell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @agocharbhatia for the contribution! The bug is real and the tests are thorough. I confirmed the four failed-409 cases fail on main and pass on this branch.

One thing to change: wait_for_result in src/query.rs (used internally by query()) handles the same 409 from get_result, but await_result polls separately and never goes through it. That's why this bug exists. That path treats any 409 as a failed result. It takes error_message from the typed Status409 body when there is one and uses None otherwise. arrow.rs does the same for the Arrow endpoint.

This PR is stricter, since it also requires the body to parse and have status == "failed". That means a 409 with no body or an unexpected body would be Failed from query() but Api from await_result(). The spec only defines one meaning for a 409 on this endpoint, so I'd rather the two paths agree.

Could you:

  • Match the query.rs behaviour: a 409 returns AwaitResultError::Failed directly from the match arm, without passing the body back through ResultStatus::parse.
  • Ideally, move the "409 → failed + optional message" logic into a small shared helper that both await_result and wait_for_result use, so they can't drift apart again.
  • Change the unrelated_or_malformed_errors_keep_http_status_and_body cases so a 409 with a non-failed or malformed body expects Failed { error_message: None }. The 404 and 500 cases stay as they are.

Copy link
Copy Markdown
Author

Thanks for the review, Zac. Both polling paths now share the 409 handling and return Failed directly, with the typed message when available. Added empty/malformed-body cases and a query_in regression. The 404/500 behavior is unchanged.

@zfarrell zfarrell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick turnaround, Agochar.

I appreciate the shared helper, and the new tests are great. I confirmed 8 of the 12 fail against main, and the full suite passes on this branch.

I do have one more request inline. Let me know what you think.

Comment thread src/query.rs

/// HTTP 409 is authoritative even when its body is absent or cannot be decoded.
/// Keep other errors intact so each polling API retains its own error surface.
pub(crate) fn failed_result_message(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One readability request on this helper's shape:

Result<Option<String>, Error> uses Ok to mean "this error was a failed result" and Err to mean "pass it through". At the call sites, the ? inside the Err arm is what sends non-409s back out. It's correct, but it takes a second read to see that a 409 becomes Failed.

The rest of the hand-written layer splits this into a borrowing bool check (is_retryable_submit_error, uploads::is_terminal) and a separate Option extractor (arrow::parse_error_message). Could you follow that pattern? It keeps the 409 rule in one place:

/// A failed result arrives as HTTP 409: the generated client raises on any
/// non-2xx, so "failed" surfaces as an error rather than a status field.
pub(crate) fn is_failed_result(err: &Error<GetResultError>) -> bool {
    matches!(err, Error::ResponseError(rc) if rc.status == StatusCode::CONFLICT)
}

/// The server's message from a failed-result error; best-effort, since the
/// 409 status alone is authoritative.
pub(crate) fn failed_result_message(err: Error<GetResultError>) -> Option<String> {
    match err {
        Error::ResponseError(ResponseContent {
            entity: Some(GetResultError::Status409(r)),
            ..
        }) => r.error_message.flatten(),
        _ => None,
    }
}

and at each call site:

Err(e) if query::is_failed_result(&e) => {
    return Err(AwaitResultError::Failed {
        result_id: result_id.to_owned(),
        error_message: query::failed_result_message(e),
    });
}
Err(e) => return Err(AwaitResultError::Api(e)),

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants