feat: allow caller-supplied Snowpark session in ChatSnowflake - #428
Merged
Conversation
Mirrors the ChatDatabricks workspace_client pattern: when a session is provided, the provider uses it directly and close() leaves it alone; only sessions created by chatlas itself are closed.
cpsievert
marked this pull request as ready for review
September 4, 2026 15:35
cpsievert
added a commit
that referenced
this pull request
Sep 4, 2026
* feat: add Chat.close()/close_async() lifecycle API Chat gains close() and close_async() methods (plus context-manager support) for releasing resources held by the provider: HTTP connection pools, the Snowflake Snowpark session/connection, and (via close_async()) MCP server sessions. This supports long-lived applications like Shiny that create a chat per user session, e.g. session.on_ended(chat.close). - Provider ABC gains no-op close()/close_async() with documented ownership (only provider-created resources are closed) and idempotency rules - Overrides on the OpenAI generic base, Anthropic, Bedrock Converse, Google, and Snowflake providers; all other providers inherit - SnowflakeProvider now retains its Snowpark session so it can be closed - Databricks needs no override (caller-supplied WorkspaceClient is never retained); ownership behavior pinned by test * Address close() lifecycle review feedback - Bump google-genai minimum to >=2.0.0 (Client.close()/aio.aclose() were both added in 2.0.0) and drop the getattr guard. - Document that ChatDatabricks close() leaves a caller-supplied WorkspaceClient open. - Warn in Chat.close() when MCP server sessions are still open. * Remove unused typing.cast import (fixes ruff F401) * feat: allow caller-supplied Snowpark session in ChatSnowflake (#428) * feat: allow caller-supplied Snowpark session in ChatSnowflake Mirrors the ChatDatabricks workspace_client pattern: when a session is provided, the provider uses it directly and close() leaves it alone; only sessions created by chatlas itself are closed. * docs: changelog entry for ChatSnowflake session parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #427.
Summary
ChatSnowflake()gains asessionparameter accepting a caller-suppliedsnowflake.snowpark.Session, mirroring theworkspace_clientpattern inChatDatabricks(). When a session is supplied, the provider uses it directly and records_owns_session = False, soChat.close()leaves it alone — only sessions created by chatlas itself are closed. This lets users share one Snowpark session across multiple chats (e.g., per-session chats in a Shiny app) withoutclose()tearing down the shared connection.Verification
Tests:
test_snowflake_provider_close_ownershipintests/test_close.pyverifies a supplied session is never closed; existing close tests confirm chatlas-created sessions still close (idempotently).