Skip to content

SEA metadata queries emit a redundant CloseStatement DELETE on a statement already returned state=CLOSED (#168) - #183

Merged
vikrantpuppala merged 4 commits into
mainfrom
ai/issue-168
Jul 31, 2026
Merged

vikrantpuppala merged 4 commits into
mainfrom
ai/issue-168

Conversation

@oss-engineer-bot

Copy link
Copy Markdown

Summary

Automated fix for #168 — SEA metadata queries emit a redundant CloseStatement DELETE on a statement already returned state=CLOSED.

Fixed the SEA metadata path in src/metadata_v0.rs to honor status.state==CLOSED from the ExecuteStatement response and skip the redundant CloseStatement DELETE, mirroring the regular-query path. Added a close_id() helper applied at all 8 metadata sites; the two pre-written wiremock tests are now green and the full 703-test suite plus clippy/fmt pass. This bug is client-side RPC-omission behavior anchored in the SEA API contract, so the wiremock tests asserting on wire traffic (expect(0)/expect(1) on the DELETE endpoint) are the correct anchor (offline carve-out).

Root cause & plan

Root cause: The SEA metadata path in src/metadata_v0.rs ignores the terminal StatementStatus returned by the transport. Every Metadata::list_* method does let stmt_id = raw.statement_id.clone(); and unconditionally calls ResultStream::from_reader_with_close(reader, session, stmt_id), which installs a StatementCloseGuard that fires a fire-and-forget DELETE /api/2.0/sql/statements/<id> (CloseStatement) on drop. When the ExecuteStatement response already reported status.state == CLOSED (the common inline/direct-result case where the kernel omits wait_timeout — the server auto-closes and returns state=CLOSED), the statement is already closed server-side, so this DELETE is redundant (server responds 404 STATEMENT_NOT_FOUND, swallowed by best-effort close_statement). The regular-query path (src/statement/mutable.rs:~365) does NOT have this bug: it computes already_closed = result.status.state == StatementState::Closed and pre-sets the shared closed flag so neither the handle nor its Drop fires the redundant CloseStatement. The metadata path simply never consults raw.status. Fix: mirror the regular path — at each metadata site, resolve the close-id to empty when raw.status.state == StatementState::Closed (from_reader_with_close already skips the guard for an empty statement_id).
Files: src/metadata_v0.rs, tests/v0_metadata_wiremock.rs
Planned coverage:

  • Wiremock: stub POST /statements to return an inline metadata result with status.state == CLOSED, mount a scoped DELETE mock on /api/2.0/sql/statements/ with expect(0), drive Session::metadata().list_catalogs() to completion, drop the stream, sleep briefly to let any fire-and-forget close hit the wire, then verify the scoped DELETE mock recorded zero calls. Fails today because the metadata path always installs the close guard regardless of CLOSED state. (Metadata path must skip CloseStatement when ExecuteStatement response already reported state=CLOSED (the reported bug).)
  • Wiremock regression-guard: stub POST /statements to return status.state == SUCCEEDED, mount a DELETE counter on the statement endpoint with expect(1), drive list_catalogs to completion and drop the stream, sleep briefly, verify exactly one DELETE fired. Ensures the fix does not over-correct and reintroduce the server-statement leak that from_reader_with_close was added to prevent for non-CLOSED metadata statements. (Metadata path must STILL fire CloseStatement when the server did not auto-close (state != CLOSED).)

Files changed

  • tests/v0_metadata_wiremock.rs
  • src/metadata_v0.rs

Test plan

  • metadata_closed_response_skips_close_statement — fails (red) against the original code, passes (green) after the fix
  • metadata_succeeded_response_still_closes_statement — fails (red) against the original code, passes (green) after the fix

🤖 Generated by engineer-bot (bug-fix flow) — review before merge.

@oss-engineer-bot oss-engineer-bot Bot added the engineer-bot Apply to an issue to trigger the engineer-bot; on a PR to enable engineer follow-up label Jul 21, 2026

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Low

Looks good — the fix correctly mirrors the established regular-query path (statement/mutable.rs:366): close_id returns an empty id when status.state == Closed, and from_reader_with_close already skips the close guard for an empty id (result_stream.rs:571). Applied uniformly across all 8 metadata sites; two wiremock tests assert the skip and the non-CLOSED regression. One low note on test coverage being limited to list_catalogs.

Comment thread tests/v0_metadata_wiremock.rs Resolved
oss-engineer-bot Bot pushed a commit that referenced this pull request Jul 21, 2026
Addresses:
  - #3626177132 at tests/v0_metadata_wiremock.rs:780

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No issues identified by the review bot.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No issues identified by the review bot.

peco-engineer-bot[bot] and others added 2 commits July 31, 2026 07:05
…ement already returned state=CLOSED (#168)

Signed-off-by: peco-engineer-bot[bot] <3815206+peco-engineer-bot[bot]@users.noreply.github.com>
Addresses:
  - #3626177132 at tests/v0_metadata_wiremock.rs:780

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Low

Clean, correctly-scoped fix. close_id() mirrors the regular-query path in statement/mutable.rs, and both from_reader_with_close and StatementCloseGuard::drop already no-op on an empty id, so the CLOSED-skip is sound at all 8 sites. One low: the wildcard fan-out path (fetch_tables_for_catalog) uses a bespoke close guard that the added tests don't exercise.

Comment thread src/metadata_v0.rs Resolved
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 31, 2026
@vikrantpuppala
vikrantpuppala added this pull request to the merge queue Jul 31, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 31, 2026
Addresses:
  - #3688886958 at src/metadata_v0.rs:688

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Nit

Looks good — clean, minimal fix. close_id() correctly maps a status.state == CLOSED ExecuteResult to an empty statement id, mirroring the established regular-query path (statement/mutable.rs:366); from_reader_with_close already skips the close guard on an empty id, and the fan-out path's explicit close_statement is now gated behind !stmt_id.is_empty(). The helper is applied consistently at all 8 metadata sites and the two new wiremock tests (plus the match-branch and wildcard-fanout regression guards) exercise both the skip and the still-close paths at the right tier. One nit on test-helper duplication.

Other findings

  • ⚪ Nit — The wildcard-fanout test re-implements the poll loop from wait_for_close_delete inline (because that helper hardcodes the stmt-test path and this test asserts on stmt-tables-comp-a). Consider generalizing wait_for_close_delete to take the statement path so all four tests share one polling implementation. Minor test-only duplication — no behavioral impact.

This branch was previously deployed

1 inactive deployment
azure-prod — 880930d4 Deployed Jul 31, 2026 by oss-reviewer-bot[bot] via followup #190
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engineer-bot Apply to an issue to trigger the engineer-bot; on a PR to enable engineer follow-up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants