← Back to Pull requests

Core: Treat a lost REST commit response as an unknown commit state #18903

Open
gardenia opened this pull request with 378 lines diff across 6 files
View on GitHub
gardenia gardenia commented on Nov 11, 2026 23:04 UTC
Author

When a REST commit request fails after it may have reached the server (no response, a connection reset, a read timeout), HTTPClient reports a plain RESTException, so an applied commit is treated as failed and a retry can apply it twice. HTTPClient now tracks every attempt, including automatic retries, and throws UnknownRequestOutcomeException when any attempt may have been received. That is still a RESTException, so other callers are unaffected, which was the concern in #6778; only table and multi-table commits turn it into CommitStateUnknownException, so snapshot-add-only commits get the existing 5xx reconciliation. Create and replace transactions (CTAS/RTAS) aren't reconciled, so a lost response to them now raises CommitStateUnknownException instead of RESTException.

Fixes #18902

Test plan:

  • Keyed POST whose reply is lost, then the retry is refused: unknown outcome (the gap found in review).

  • Keyed POST that gets a 503, then the retry is refused: unknown outcome.

  • Read timeout and malformed response: unknown outcome.

  • Refused first attempt: stays a plain RESTException, since nothing was sent.

  • Through the catalog: a lost append response is reconciled and succeeds; lost table-commit and transaction responses raise CommitStateUnknownException.

  • End to end: Spark 3.5 against apache/iceberg-rest-fixture with a proxy that forwards one commit and drops the connection; the INSERT succeeds and the row is committed once.
  • ---
    AI Disclosure

  • Model: Claude Opus 5.5

  • Platform/Tool: Claude Code

  • Human Oversight: [unknown - human to fill in]

  • Prompt Summary: Reproduce a lost REST commit response found by fault-injection testing, fix it so a commit request that may have reached the server is reported as an unknown commit state, and address review feedback about automatic HTTP retries.
  • Diff: 378 lines (+369 / -9) across 6 files Reviewer: developer-rpai Review duration: 28577m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.46) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 378 lines diff across 6 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.96 · 3 substantive comment(s)
    0.96
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    89%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.355
    Real PR Conversation Timeline
    7 items
    developer-rpai developer-rpai commented on Nov 15, 2026 15:50 UTC
    Reviewer

    Nice, a lost response really should go through the same reconciliation as a 5xx, and keeping it to commit requests addresses the concern from #6778.

    1. In RESTTableOperations.commitRequest (around L261), ConnectException is the only "never sent" case. With HttpClient 5, ConnectTimeoutException extends SocketTimeoutException, and it also covers waiting for a connection from the pool, so a connect or lease timeout would now be reported as unknown even though nothing was sent. UnknownHostException and an SSL handshake failure are the same. Could those be excluded too, or the check flipped to the cases that can happen after the request is written?
    2. For create and replace transactions commit() only reconciles SIMPLE updates, so a lost response there now surfaces as CommitStateUnknownException instead of RESTException. Probably the right call, but worth a line in the description since callers that retried on RESTException will now stop.
    3. A test with ConnectTimeoutException next to testCommitThatCannotConnectIsNotCommitStateUnknown would pin down point 1.

    gardenia gardenia commented on Nov 16, 2026 12:06 UTC
    Author

    Thanks @developer-rpai , good catches.

    1. Agreed. ConnectTimeoutException is a SocketTimeoutException, so it was being reported as unknown. One correction: in HttpClient 5.6 waiting for a pooled connection throws ConnectionRequestTimeoutException (an InterruptedIOException), not ConnectTimeoutException. Both are now treated as never sent, along with UnknownHostException, NoRouteToHostException and SSLHandshakeException. I kept the default as unknown rather than flipping to an allow-list of after-send failures. Missing a pre-send case only reports a harmless failure as unknown, which can leave orphan files. Missing a post-send case (a reset, a broken pipe, a TLS error mid-stream, a proxy closing the connection) would bring this bug back. The pre-send list is the shorter and better-defined one.
    2. Added to the description.
    3. Done: testCommitThatWasNeverSentIsNotCommitStateUnknown is parameterized over all six, and testLostCommitResponseIsCommitStateUnknown over a read timeout, no response and a connection reset. The pre-send test calls commitRequest directly, because Tasks treats a ConnectionRequestTimeoutException as an interruption and sets the caller's interrupt flag. That's existing behaviour, noted in the description.
    4. Strictly, the two HttpClient 5 checks belong in HTTPClient, so that each RESTClient implementation can decide this for itself. That felt like too wide a change for this fix, so I've left them in RESTTableOperations. Other clients never throw those two types, so the checks are simply never triggered for them, and their connect timeouts fall back to the safe default of unknown. Happy to move them if you'd prefer.

    developer-rpai developer-rpai approved these changes on Nov 17, 2026 07:25 UTC
    Approved Reviewer

    Thanks, this looks good. Keeping unknown as the default makes sense to me, a missed pre send case only costs an orphan file while a missed post send case brings the bug back. Fine with leaving the two HttpClient checks in RESTTableOperations for now, moving them into HTTPClient feels like its own follow up. LGTM.

    timothyw553 timothyw553 commented on code on Nov 28, 2026 01:22 UTC
    Code Review
    core/src/main/java/org/apache/iceberg/rest/RESTTableOperations.java:1
    @@ -240,6 +252,38 @@ public void commit(TableMetadata base, TableMetadata metadata) {
         updateCurrentMetadata(response);
       }
     
    +  /**
    +   * Sends a commit request, reporting a transport failure as an unknown commit state.
    +   *
    +   * <p>If the connection fails once the request may have been sent (no response, a reset, a read
    +   * timeout), the server may have applied the commit, so the outcome is unknown just as for a 5xx
    +   * response. Failures that happen before anything is sent stay ordinary failures. Any other
    +   * transport failure is treated as unknown: reporting a commit that was applied as failed invites
    +   * a retry that applies it twice, while reporting one that wasn't as unknown at worst leaves
    +   * orphan files.
    +   */
    +  static <T> T commitRequest(Supplier<T> request) {
    +    try {
    +      return request.get();
    +    } catch (RESTException e) {
    +      if (e.getCause() instanceof IOException && !failedBeforeSending(e.getCause())) {

    doesn't this only inspect the last http attempt? if a keyed post reaches the server, loses the response, and then fails to connect on an automatic retry, the final connection error makes failedBeforeSending return true and throws RESTException instead of CommitStateUnknownException. could we track attempt history on the request's HttpContext and pass it from HTTPClient (or drop !failedBeforeSending as a fallback), and add a real HTTPClient test for a lost keyed-post reply followed by connection refusal?

    timothyw553 timothyw553 commented on Nov 28, 2026 01:22 UTC
    Reviewer

    overall the direction makes sense, i left one comment. main concern is that an http retry can mask an earlier attempt that already reached the server.

    gardenia gardenia commented on code on Nov 28, 2026 14:39 UTC
    Code Review
    core/src/main/java/org/apache/iceberg/rest/RESTTableOperations.java:1
    @@ -240,6 +252,38 @@ public void commit(TableMetadata base, TableMetadata metadata) {
         updateCurrentMetadata(response);
       }
     
    +  /**
    +   * Sends a commit request, reporting a transport failure as an unknown commit state.
    +   *
    +   * <p>If the connection fails once the request may have been sent (no response, a reset, a read
    +   * timeout), the server may have applied the commit, so the outcome is unknown just as for a 5xx
    +   * response. Failures that happen before anything is sent stay ordinary failures. Any other
    +   * transport failure is treated as unknown: reporting a commit that was applied as failed invites
    +   * a retry that applies it twice, while reporting one that wasn't as unknown at worst leaves
    +   * orphan files.
    +   */
    +  static <T> T commitRequest(Supplier<T> request) {
    +    try {
    +      return request.get();
    +    } catch (RESTException e) {
    +      if (e.getCause() instanceof IOException && !failedBeforeSending(e.getCause())) {

    @timothyw553 - Good catch, that case wasn't handled. The same applied to a keyed POST that got a 503, was retried, and then had the connection refused.

    I've moved the tracking into HTTPClient as you suggested. It now uses an HttpClient interceptor that tracks how each attempt ended, so if any attempt may have reached the server, the final error says so, whatever happened on the last try. RESTTableOperations then only has to turn that into a CommitStateUnknownException, without digging through exception causes.

    I added real HTTPClient tests for a lost keyed-POST reply followed by connection refusal, a 503 followed by connection refusal, a read timeout, a malformed response, and a refused first attempt (which stays an ordinary failure).

    @developer-rpai this also moves the "never sent" checks into HTTPClient, including the two HttpClient 5 ones. That's the follow-up we discussed, but it made more sense to do it here given @timothyw553's suggestion. It's a bit different from the version you approved, so worth another look if you have time.

    Assignees
    gardenia gardenia
    Labels
    risk: low confidence: 89.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.8% (MEDIUM) · Higher = larger blast radius
    45.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 89.6% · Lower = rushed or shallow review
    89.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.7% · Safe to merge
    4.7%
    Repository