You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SEA metadata queries emit a redundant CloseStatement DELETE on a statement already returned state=CLOSED #168
The kernel's SEA metadata path (Metadata::list_catalogs / list_schemas / list_tables / list_columns) issues a redundant DELETE /api/2.0/sql/statements/<id> (CloseStatement) on a statement that the ExecuteStatement response already reported status.state == CLOSED. The kernel's regular-query path correctly recognizes CLOSED and skips the close; the metadata path does not.
Both responses carry status.state = CLOSED. Per the SEA API contract, CLOSED means "execution successful, and statement closed; result no longer available for fetch" — so once the response is CLOSED, the statement is already closed server-side and must not be closed again.
Expected
The metadata result path should honor status.state == CLOSED from the ExecuteStatement response and skip the follow-up CloseStatement, matching the regular-query path (and matching the databricks-jdbc SEA metadata path, which runs metadata fully-sync via the x-databricks-sea-can-run-fully-sync header and emits no separate close).
Impact
Redundant server round-trip per metadata call. It also surfaced as a non-deterministic replay failure in the databricks-driver-test Python proxy suite: on a connection shared across tests, the close is deferred to the next metadata call and its DELETE bleeds into the next test's recording context. (Worked around in that repo with a per-test connection; this issue tracks the underlying kernel behavior.)
Found via the databricks-driver-test kernel proxy fan-out.
Additional evidence: request-shape difference vs C# ADBC (which does NOT hit this)
Comparing the metadata ExecuteStatement the kernel sends against the C# ADBC SEA client's, on the same warehouse, both disposition=INLINE_OR_EXTERNAL_LINKS, format=ARROW_STREAM:
C# ADBC SEA (metadata request):
body includes on_wait_timeout: "CONTINUE"
header x-databricks-sea-can-run-fully-sync: true
response status.state = SUCCEEDED → statement is still open → C# then sends CloseStatement (correct, non-redundant)
So the kernel's metadata request omits both the on_wait_timeout=CONTINUE field and the x-databricks-sea-can-run-fully-sync header that C#/JDBC send. Regardless of the exact server-side reason the kernel's response comes back CLOSED, the defect is clear: when the ExecuteStatement response reports status.state == CLOSED, the metadata path should skip the follow-up CloseStatement — exactly as the kernel's regular-query path already does. (The C# path legitimately closes because its statements come back SUCCEEDED, not CLOSED.)
Two possible fixes, either resolves the redundant DELETE:
Skip CloseStatement when the response already reported state == CLOSED (minimal; mirrors the regular-query path).
Align the metadata request with C#/JDBC (on_wait_timeout=CONTINUE + x-databricks-sea-can-run-fully-sync) so behavior is consistent across SEA clients.
Correction / clarification after live curl testing
I tried to reproduce the CLOSED-vs-SUCCEEDED difference with raw curl against POST /api/2.0/sql/statements and want to correct my previous comment, which over-attributed the state difference to the header/on_wait_timeout alone:
On the dispositions the public REST endpoint accepts (INLINE / JSON_ARRAY, EXTERNAL_LINKS / ARROW_STREAM), every combination of {x-databricks-sea-can-run-fully-sync header, on_wait_timeout=CONTINUE, default/30s wait} returned SUCCEEDED — I could not produce CLOSED with the header or on_wait_timeout alone. (wait_timeout=0s → PENDING, as expected.)
The public endpoint rejects disposition=INLINE_OR_EXTERNAL_LINKS (INVALID_PARAMETER_VALUE: … is not a supported disposition), which is exactly the disposition both drivers use — so I could not exercise the server path that yields CLOSED via plain curl.
So the precise trigger for CLOSED couldn't be isolated externally. What the recordings do establish (same warehouse, identical disposition=INLINE_OR_EXTERNAL_LINKS + format=ARROW_STREAM):
client
on_wait_timeout
x-databricks-sea-can-run-fully-sync
resp status.state
redundant CloseStatement?
C# ADBC SEA
CONTINUE
true
SUCCEEDED
no (statement open → close is correct)
kernel
absent
absent
CLOSED
yes (already closed)
The core defect is unchanged and does not depend on why the state differs: when the ExecuteStatement response reports status.state == CLOSED, the kernel's metadata path should not send a follow-up CloseStatement — the kernel's own regular-query path already skips it. Aligning the metadata request with C#/JDBC (on_wait_timeout=CONTINUE + the fully-sync header) is a plausible secondary fix, but I have NOT proven those flags are what flips the state — treat that as a hypothesis, not a confirmed cause.
Live curl testing overturns the "kernel differs from C#" framing — please re-scope this issue
Correcting my earlier comments. Using a real driver User-Agent (the public REST endpoint rejects INLINE_OR_EXTERNAL_LINKS without one — thanks to the reviewer who pointed this out), I re-ran the metadata ExecuteStatement live against the warehouse and isolated every axis:
With disposition=INLINE_OR_EXTERNAL_LINKS, format=ARROW_STREAM, the response is status.state = CLOSED in ALL cases:
kernel UA vs C# ADBC UA → both CLOSED
with vs without x-databricks-sea-can-run-fully-sync: true → both CLOSED
with vs without on_wait_timeout=CONTINUE → both CLOSED
SHOW SCHEMAS, SELECT CURRENT_CATALOG() (C#'s exact metadata statement), SELECT 1 → all CLOSED
So the header / on_wait_timeout / user-agent do NOT drive the state, and the kernel is not sending a materially different request. My earlier hypothesis was wrong.
The SUCCEEDED seen in the C# ADBC recording is stale: that tape was captured 2026-07-08. The server's behavior for this disposition has since changed to return CLOSED for inline/small results. A fresh C# re-record today would also get CLOSED and would also emit the same follow-up CloseStatement.
Re-scoped issue (still valid, but not kernel-vs-C#): the server now reports status.state == CLOSED on the ExecuteStatement response for hybrid-disposition metadata queries, meaning the statement is already closed server-side. The kernel's metadata result path still issues a redundant DELETE /statements/<id> on it — whereas the kernel's own regular-query path already skips the close when the result arrives CLOSED. So the ask is a small optimization: honor state == CLOSED in the metadata path too and skip the redundant CloseStatement, matching the regular-query path. It is NOT a behavioral divergence from other SEA clients (they'd all do the same today).
(This surfaced only as a replay-ordering artifact in databricks-driver-test, already fixed there by using a per-test connection so the close records in-context; no functional impact live, since closing an already-closed statement returns 200.)
Confirmed via C# ADBC driver source: this IS a real divergence — C#/JDBC skip the close, the kernel doesn't
I inspected the C# ADBC SEA driver (StatementExecutionStatement.cs) directly. It explicitly handles state == CLOSED and skips the redundant close:
// Set when the server returns state=CLOSED (direct-result delivery): the result is already// in-hand and the statement is closed server-side, so Dispose must NOT re-close it.privatebool_statementClosedByServer;...// CLOSED = execution succeeded and the statement is already closed server-side; ... remember// it's closed so Dispose skips the redundant CloseStatement. Matches databricks-jdbc, which// treats CLOSED == SUCCEEDED.if(state=="CLOSED"){..._statementClosedByServer=true;}
The CloseStatement DELETE on dispose is then gated on _statementClosedByServer — when the server already reported CLOSED, C# does not send it. (They even reset the flag per-execution so a later genuinely-open SUCCEEDED statement still gets its legitimate close.)
So my previous "all SEA clients would do the same today" comment was wrong. The correct picture:
client
sees state == CLOSED
sends redundant CloseStatement?
C# ADBC
yes
no — _statementClosedByServer guard skips it (matches JDBC: CLOSED == SUCCEEDED)
databricks-jdbc
yes
no
kernel
yes
yes ← the bug
(The SUCCEEDED in the older adbc-csharp recording is just stale tape from before the server started returning CLOSED; the C# driver code checks the live state, so it handles today's CLOSED correctly.)
Fix: the kernel's metadata (and any) result path should set an equivalent "already closed server-side" flag when the ExecuteStatement response reports state == CLOSED, and skip the follow-up DELETE /statements/<id> — matching C# ADBC and databricks-jdbc.
Cross-driver comparison: C# ADBC and JDBC both close SYNCHRONOUSLY and skip the redundant close — the kernel does neither
Confirmed the close behavior in the two reference SEA drivers vs the kernel:
C# ADBC (StatementExecutionStatement.cs):
if(!alreadyClosed){// Close statement synchronously during dispose_client.CloseStatementAsync(_currentStatementId,CancellationToken.None).GetAwaiter().GetResult();}
→ synchronous (blocks on the DELETE) AND guarded by !alreadyClosed.
JDBC (DatabricksStatement.close()):
// Skip server-side close if operation was already closed:// - directResultsReceived: server closed it (inline results)// - serverOperationClosed: client proactively closed it (results consumed or RS closed)if (!directResultsReceived && !serverOperationClosed) {
...getDatabricksClient().closeStatement(statementId);
}
→ synchronous (closeStatement runs apiClient.execute(req) inline) AND skips when the server already closed it.
→ detached fire-and-forget task (async) AND fires unconditionally (no state==CLOSED guard).
So the kernel diverges from BOTH reference drivers on TWO axes:
Async vs sync close. C#/JDBC block on the close during dispose, so it always lands in order relative to subsequent requests. The kernel runtime.spawns it detached, so the DELETE /statements/<id>races the connector's next request — non-deterministic wire ordering. Proven behaviorally: the identical proxy recording replays fail/pass/pass across 3 back-to-back runs (the DELETE sometimes lands before, sometimes after, the next ExecuteStatement).
No skip-when-already-closed. As above — C# uses !alreadyClosed, JDBC uses !directResultsReceived && !serverOperationClosed. The kernel has no equivalent, so it redundantly closes statements the ExecuteStatement response already reported state=CLOSED.
Fixing (2) alone (skip the close when the response is CLOSED, matching JDBC's directResultsReceived) removes the redundant close for all metadata queries and eliminates the observed non-determinism there, since no close would be spawned. Fixing (1) — making the close synchronous like C#/JDBC, or at least ordering it before the next request — addresses the broader latent race for the cases where a close IS needed (e.g. cloud-fetch/large results).
Extends this issue: the redundant CloseStatement also fires on the inline direct-results path (regular query), not just metadata.
This issue's summary notes the regular-query path correctly recognizes state=CLOSED and skips the close, scoping the bug to metadata. But conformance test CLOUDFETCH-013 (databricks-driver-test) shows a plain SELECT 1 — delivered inline via direct results with status.state == CLOSED — still gets a redundant DELETE /api/2.0/sql/statements/{id} on ExecutedStatement::close():
The test asserts CloseStatement == 0 on the inline path and currently fails (committed as an xfail tripwire). So the redundant-close applies to at least: (1) metadata queries, and (2) inline direct-results regular queries. The fix should suppress the close whenever the ExecuteStatement response already reported state=CLOSED, regardless of path.
(No action needed from the kernel side beyond what's already planned — just flagging the broader trigger so the fix covers the inline path too. The conformance suite tracks this cell against THIS issue.)
Activity
eric-wang-1990 commentedon Jul 16, 2026
Additional evidence: request-shape difference vs C# ADBC (which does NOT hit this)
Comparing the metadata
ExecuteStatementthe kernel sends against the C# ADBC SEA client's, on the same warehouse, bothdisposition=INLINE_OR_EXTERNAL_LINKS, format=ARROW_STREAM:C# ADBC SEA (metadata request):
on_wait_timeout: "CONTINUE"x-databricks-sea-can-run-fully-sync: truestatus.state = SUCCEEDED→ statement is still open → C# then sends CloseStatement (correct, non-redundant)Kernel (metadata request):
on_wait_timeoutx-databricks-sea-can-run-fully-syncheaderstatus.state = CLOSED→ statement already closed server-side → kernel still sends CloseStatement (redundant)So the kernel's metadata request omits both the
on_wait_timeout=CONTINUEfield and thex-databricks-sea-can-run-fully-syncheader that C#/JDBC send. Regardless of the exact server-side reason the kernel's response comes backCLOSED, the defect is clear: when the ExecuteStatement response reportsstatus.state == CLOSED, the metadata path should skip the follow-up CloseStatement — exactly as the kernel's regular-query path already does. (The C# path legitimately closes because its statements come backSUCCEEDED, notCLOSED.)Two possible fixes, either resolves the redundant DELETE:
state == CLOSED(minimal; mirrors the regular-query path).on_wait_timeout=CONTINUE+x-databricks-sea-can-run-fully-sync) so behavior is consistent across SEA clients.eric-wang-1990 commentedon Jul 16, 2026
Correction / clarification after live curl testing
I tried to reproduce the
CLOSED-vs-SUCCEEDEDdifference with rawcurlagainstPOST /api/2.0/sql/statementsand want to correct my previous comment, which over-attributed the state difference to the header/on_wait_timeoutalone:INLINE/JSON_ARRAY,EXTERNAL_LINKS/ARROW_STREAM), every combination of{x-databricks-sea-can-run-fully-sync header, on_wait_timeout=CONTINUE, default/30s wait}returnedSUCCEEDED— I could not produceCLOSEDwith the header oron_wait_timeoutalone. (wait_timeout=0s→PENDING, as expected.)disposition=INLINE_OR_EXTERNAL_LINKS(INVALID_PARAMETER_VALUE: … is not a supported disposition), which is exactly the disposition both drivers use — so I could not exercise the server path that yieldsCLOSEDvia plain curl.So the precise trigger for
CLOSEDcouldn't be isolated externally. What the recordings do establish (same warehouse, identicaldisposition=INLINE_OR_EXTERNAL_LINKS+format=ARROW_STREAM):on_wait_timeoutx-databricks-sea-can-run-fully-syncstatus.stateCONTINUEtrueThe core defect is unchanged and does not depend on why the state differs: when the ExecuteStatement response reports
status.state == CLOSED, the kernel's metadata path should not send a follow-up CloseStatement — the kernel's own regular-query path already skips it. Aligning the metadata request with C#/JDBC (on_wait_timeout=CONTINUE+ the fully-sync header) is a plausible secondary fix, but I have NOT proven those flags are what flips the state — treat that as a hypothesis, not a confirmed cause.eric-wang-1990 commentedon Jul 16, 2026
Live curl testing overturns the "kernel differs from C#" framing — please re-scope this issue
Correcting my earlier comments. Using a real driver User-Agent (the public REST endpoint rejects
INLINE_OR_EXTERNAL_LINKSwithout one — thanks to the reviewer who pointed this out), I re-ran the metadataExecuteStatementlive against the warehouse and isolated every axis:With
disposition=INLINE_OR_EXTERNAL_LINKS,format=ARROW_STREAM, the response isstatus.state = CLOSEDin ALL cases:CLOSEDx-databricks-sea-can-run-fully-sync: true→ bothCLOSEDon_wait_timeout=CONTINUE→ bothCLOSEDSHOW SCHEMAS,SELECT CURRENT_CATALOG()(C#'s exact metadata statement),SELECT 1→ allCLOSEDSo the header /
on_wait_timeout/ user-agent do NOT drive the state, and the kernel is not sending a materially different request. My earlier hypothesis was wrong.The
SUCCEEDEDseen in the C# ADBC recording is stale: that tape was captured 2026-07-08. The server's behavior for this disposition has since changed to returnCLOSEDfor inline/small results. A fresh C# re-record today would also getCLOSEDand would also emit the same follow-up CloseStatement.Re-scoped issue (still valid, but not kernel-vs-C#): the server now reports
status.state == CLOSEDon the ExecuteStatement response for hybrid-disposition metadata queries, meaning the statement is already closed server-side. The kernel's metadata result path still issues a redundantDELETE /statements/<id>on it — whereas the kernel's own regular-query path already skips the close when the result arrivesCLOSED. So the ask is a small optimization: honorstate == CLOSEDin the metadata path too and skip the redundant CloseStatement, matching the regular-query path. It is NOT a behavioral divergence from other SEA clients (they'd all do the same today).(This surfaced only as a replay-ordering artifact in databricks-driver-test, already fixed there by using a per-test connection so the close records in-context; no functional impact live, since closing an already-closed statement returns 200.)
eric-wang-1990 commentedon Jul 16, 2026
Confirmed via C# ADBC driver source: this IS a real divergence — C#/JDBC skip the close, the kernel doesn't
I inspected the C# ADBC SEA driver (
StatementExecutionStatement.cs) directly. It explicitly handlesstate == CLOSEDand skips the redundant close:The CloseStatement DELETE on dispose is then gated on
_statementClosedByServer— when the server already reported CLOSED, C# does not send it. (They even reset the flag per-execution so a later genuinely-openSUCCEEDEDstatement still gets its legitimate close.)So my previous "all SEA clients would do the same today" comment was wrong. The correct picture:
state == CLOSED_statementClosedByServerguard skips it (matches JDBC: CLOSED == SUCCEEDED)(The
SUCCEEDEDin the older adbc-csharp recording is just stale tape from before the server started returningCLOSED; the C# driver code checks the live state, so it handles today'sCLOSEDcorrectly.)Fix: the kernel's metadata (and any) result path should set an equivalent "already closed server-side" flag when the ExecuteStatement response reports
state == CLOSED, and skip the follow-upDELETE /statements/<id>— matching C# ADBC and databricks-jdbc.eric-wang-1990 commentedon Jul 16, 2026
Cross-driver comparison: C# ADBC and JDBC both close SYNCHRONOUSLY and skip the redundant close — the kernel does neither
Confirmed the close behavior in the two reference SEA drivers vs the kernel:
C# ADBC (
StatementExecutionStatement.cs):→ synchronous (blocks on the DELETE) AND guarded by
!alreadyClosed.JDBC (
DatabricksStatement.close()):→ synchronous (
closeStatementrunsapiClient.execute(req)inline) AND skips when the server already closed it.Kernel (
src/statement/executed.rs::spawn_close_if_open,src/result_stream.rs::StatementCloseGuard::drop):→ detached fire-and-forget task (async) AND fires unconditionally (no
state==CLOSEDguard).So the kernel diverges from BOTH reference drivers on TWO axes:
Async vs sync close. C#/JDBC block on the close during dispose, so it always lands in order relative to subsequent requests. The kernel
runtime.spawns it detached, so theDELETE /statements/<id>races the connector's next request — non-deterministic wire ordering. Proven behaviorally: the identical proxy recording replays fail/pass/pass across 3 back-to-back runs (the DELETE sometimes lands before, sometimes after, the next ExecuteStatement).No skip-when-already-closed. As above — C# uses
!alreadyClosed, JDBC uses!directResultsReceived && !serverOperationClosed. The kernel has no equivalent, so it redundantly closes statements the ExecuteStatement response already reportedstate=CLOSED.Fixing (2) alone (skip the close when the response is
CLOSED, matching JDBC'sdirectResultsReceived) removes the redundant close for all metadata queries and eliminates the observed non-determinism there, since no close would be spawned. Fixing (1) — making the close synchronous like C#/JDBC, or at least ordering it before the next request — addresses the broader latent race for the cases where a close IS needed (e.g. cloud-fetch/large results).oss-engineer-bot commentedon Jul 21, 2026
🤖 engineer-bot opened a fix PR: #183
Review before merge.
eric-wang-1990 commentedon Jul 24, 2026
Extends this issue: the redundant CloseStatement also fires on the inline direct-results path (regular query), not just metadata.
This issue's summary notes the regular-query path correctly recognizes
state=CLOSEDand skips the close, scoping the bug to metadata. But conformance test CLOUDFETCH-013 (databricks-driver-test) shows a plainSELECT 1— delivered inline via direct results withstatus.state == CLOSED— still gets a redundantDELETE /api/2.0/sql/statements/{id}onExecutedStatement::close():The test asserts
CloseStatement == 0on the inline path and currently fails (committed as an xfail tripwire). So the redundant-close applies to at least: (1) metadata queries, and (2) inline direct-results regular queries. The fix should suppress the close whenever theExecuteStatementresponse already reportedstate=CLOSED, regardless of path.(No action needed from the kernel side beyond what's already planned — just flagging the broader trigger so the fix covers the inline path too. The conformance suite tracks this cell against THIS issue.)
[posted via the driver-test conformance workflow]
SEA metadata queries emit a redundant CloseStatement DELETE on a stat…
SEA metadata queries emit a redundant CloseStatement DELETE on a stat…
fix(statement): skip redundant CloseStatement when async result is CL…