Repository navigation
Fixes #33918: [Snowflake] Bound the stored-procedure history scan and isolate its failures - #33919
Conversation
…d one failing the run The stored-procedure history statement scanned the whole lookback window with no upper bound, and our own network_timeout default armed the driver's per-statement cancel timer, so a long queryLogDuration died with 000604 and took the whole run down with it, query lineage included. The read is now bounded at both ends and split in half only when Snowflake cancels it, the socket guard moves to socket_timeout, and a read that still fails is reported against the pipeline instead of raising.
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The changes span recursive retries, timeout semantics, SQL bounds, and failure isolation, warranting final human review.
Review effort: Lite
Findings: None
What changed in this PR
This PR hardens Snowflake stored-procedure lineage ingestion against timeouts and failed history scans.
Changes:
- Bounds and recursively splits history queries.
- Uses
socket_timeoutfor connection protection. - Isolates failures and adds regression tests.
| File | Description |
|---|---|
ingestion/tests/unit/topology/database/test_snowflake_stored_procedure_lineage.py |
Tests Snowflake query bounds and splitting. |
ingestion/tests/unit/source/database/snowflake/test_connection.py |
Tests timeout configuration. |
ingestion/tests/unit/lineage/test_stored_procedure_lineage.py |
Tests failure isolation and retries. |
ingestion/src/metadata/ingestion/source/database/stored_procedures_mixin.py |
Adds retry hooks and failure handling. |
ingestion/src/metadata/ingestion/source/database/snowflake/queries.py |
Bounds scans and removes global sorting. |
ingestion/src/metadata/ingestion/source/database/snowflake/lineage.py |
Implements recursive window splitting. |
ingestion/src/metadata/ingestion/source/database/snowflake/connection.py |
Switches the default guard to socket_timeout. |
ingestion/.basedpyright/baseline.json |
Removes resolved type-check findings. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
✅ Playwright Results — workflow succeededValidated commit ✅ 105 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky PerformanceBlocking targets: ✅ met · Optimization targets: 🟡 in progress Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting. 🕒 Full workflow signal wall (to summary) 52m 58s ⏱️ Max setup 5m 33s · max shard execution 12m 44s · max shard-job elapsed before upload 19m 53s · reporting 3s 🌐 251.43 requests/attempt · 1.82 app boots/UI scenario · 0.00% common-shard skew Optimization targets still in progress:
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
…iling The two-day overlap was Snowflake's default statement timeout, but an account can raise it up to 604800 seconds, so after a split a long CALL near the window boundary could lose the child queries it ran past the overlap. Reaching the hard seven-day ceiling means no CALL on any account can outlive it.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
A zero server-side timeout can allow calls to exceed the fixed seven-day overlap, causing stored-procedure child lineage to be omitted.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
…ATE only - Drop the `socket_timeout` default: the driver already bounds every request read at 60 seconds, and any `network_timeout` default cancels long statements - Treat an error as a cancel only when the server reports SQLSTATE 57014, so a client error that merely mentions 57014 no longer triggers a split - Derive the window cache size from the split depth instead of a fixed number
Code Review ✅ Approved🟡 Medium risk · Snowflake query timeout defaults and lineage retry/failure handling change execution behavior Bounds Snowflake stored-procedure history scans, retries cancelled reads over progressively smaller windows, isolates unrecoverable failures so they no longer abort the run, and removes the client-side statement timeout that was capping queries at ten minutes. No issues found. OptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
main's #33919 (Snowflake stored-procedure history) rewrote the method this branch guards, so the two guards collided on one try block. They guard different failures, and each side has a test asserting the opposite policy for the other's case: - an engine we cannot reach (this branch: VIEW SERVER STATE denied on one database of an ingest-all run) must be skipped with a warning, not recorded, so one denied database does not drag the run's success percentage down; - a statement that fails after connecting (main: Snowflake cancels a scan too large to run) must be retried over a narrower window and otherwise recorded against the pipeline, so a run that silently lost lineage does not report green. Split the single guard in two to keep both. engine.connect() is guarded per engine in yield_stored_procedure_queries and warns-and-skips; _yield_queries_for_statement now takes the live connection and guards conn.execute() only, keeping main's narrowing and status.failed(). Both sides' tests pass unchanged - they raise at different points. Statement building stays outside the connect guard, so a bug in a source's statement builder still surfaces instead of looking like an unreachable engine.
… isolate its failures (#33919) (#37614) * Bound the Snowflake stored-procedure history read and stop a cancelled one failing the run The stored-procedure history statement scanned the whole lookback window with no upper bound, and our own network_timeout default armed the driver's per-statement cancel timer, so a long queryLogDuration died with 000604 and took the whole run down with it, query lineage included. The read is now bounded at both ends and split in half only when Snowflake cancels it, the socket guard moves to socket_timeout, and a read that still fails is reported against the pipeline instead of raising. * Size the stored-procedure overlap to Snowflake's statement timeout ceiling The two-day overlap was Snowflake's default statement timeout, but an account can raise it up to 604800 seconds, so after a split a long CALL near the window boundary could lose the child queries it ran past the overlap. Reaching the hard seven-day ceiling means no CALL on any account can outlive it. * Stop setting a Snowflake client timeout and classify cancels by SQLSTATE only - Drop the `socket_timeout` default: the driver already bounds every request read at 60 seconds, and any `network_timeout` default cancels long statements - Treat an error as a cancel only when the server reports SQLSTATE 57014, so a client error that merely mentions 57014 no longer triggers a split - Derive the window cache size from the split depth instead of a fixed number (cherry picked from commit d389ad6)





Describe your changes:
Fixes #33918
Snowflake lineage ingestion fails the entire run with
000604 (57014): SQL execution was cancelled by the client due to a timeoutwhen stored-procedure lineage runs over a longqueryLogDuration. Three things combine.The history query is unbounded. The stored-procedure history query reads
ACCOUNT_USAGE.QUERY_HISTORYtwice, joins the two halves by session and time overlap, and sorts the whole join. Each half was bounded only by a start time, so a 365-day lookback scanned a year of history twice in one statement. Both halves are now bounded at both ends, and a statement that Snowflake cancels is retried over the two halves of its window, recursively, a capped number of times and never below a one-day window. Only a cancel is retried, identified by the server's SQLSTATE 57014, which Snowflake reports both for its own statement timeout (000630) and for a client cancel (000604). A permission or compilation error would fail identically on every half, so it is reported once instead. The child-query half reaches seven days past its window, which is Snowflake's hard ceiling onSTATEMENT_TIMEOUT_IN_SECONDS, so aCALLthat starts just before the window closes keeps every query it ran after the boundary on any account. The global sort is gone: nothing downstream depends on the order, since the rows are handed to a thread pool.Our own connect argument cancelled it. #28131 set
network_timeout=600on the Snowflake connection to bound a severed socket, but the driver also armsnetwork_timeoutas a client-side cancel timer on every statement it executes, which made it a hard ten-minute cap on every Snowflake statement. The connection no longer sets any client timeout. A severed socket is still bounded, because the driver applies its own 60-second read timeout to every request whensocket_timeoutis unset. Anyone who wants a statement deadline can still passnetwork_timeoutorsocket_timeoutinconnectionArguments.One failed statement failed the run. The stored-procedure history read had no error handling, so the exception escaped the lineage producer and the step aborted as
Unhandled. Stored-procedure lineage runs before query lineage, so a cancelled history read also cost the run its query lineage. A read that fails and cannot be narrowed is now recorded against the pipeline and skipped, and the rest of the run continues.Type of change:
High-level design:
The shared stored-procedure lineage mixin gains two extension points, following the existing per-database engine hook. One yields the statements to read history with and defaults to the connector's single existing statement. The other yields replacement statements for one that failed and defaults to none. The mixin retries a failed statement over whatever replacements the connector offers and reports the failure once there are none. Every other connector keeps the defaults, so its only change is that a failed history read no longer aborts the run.
The Snowflake source reads the whole window in one statement and, on a cancel, offers the two halves of the failed statement's window.
Splitting only on a cancel, rather than up front, is deliberate. Fixed chunking is what the ACCESS_HISTORY path does (#28329) and was the first thing tried here. Measured against a real account, reading a 365-day window in fixed 2-day chunks returned byte-identical rows but took 1737s across 183 statements against 29s for the single statement, because every ACCOUNT_USAGE statement carries a large fixed cost however little it scans. Splitting on demand leaves accounts that can read their window in one go exactly as fast as they are today.
Tests:
Use cases covered
CALLSnowflake allowsUnit tests
Backend integration tests
Ingestion integration tests
Playwright (UI) tests
Manual testing performed
Against a live Snowflake account:
000604whennetwork_timeoutis 10, while a short statement at the same setting and the same statement at 600 both succeed.000630with SQLSTATE 57014 and is classified as a cancel, and thatSTATEMENT_TIMEOUT_IN_SECONDSaccepts at most 604800 seconds (604801 is rejected as out of range).UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.The PR should not merge until the child-query scan preserves lineage for calls allowed to run longer than two days.
Findings
Summary
The PR bounds Snowflake stored-procedure history reads, retries cancelled reads over smaller windows, isolates unrecoverable read failures, and replaces the default statement-wide network timer with a socket timeout.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Read bounded CALL and child-query history] --> B{Statement cancelled?} B -- No --> C[Process returned lineage] B -- Yes --> D{Split limit reached?} D -- No --> E[Retry each half] E --> A D -- Yes --> F[Record failure and continue]Reviews (1) · Last reviewed commit: "Bound the Snowflake stored-procedure his..."