Promote newly committed agent version to DEFAULT - #9
Merged
Conversation
ALTER AGENT ... COMMIT creates a version but does not move the DEFAULT
pointer, so the version dbt just deployed was not necessarily the one end
users get. This went unnoticed because Snowflake treats the newest committed
version as default *implicitly* — but only until DEFAULT_VERSION is set
explicitly by anything out-of-band (e.g. Snowsight's Publish button). From
that point the pointer is pinned and never moves again, so every subsequent
dbt run commits a version nobody sees while Snowsight keeps showing an older
version as "In use".
Add snowflake__set_cortex_agent_default_version, issuing
ALTER AGENT ... SET DEFAULT_VERSION = 'LAST' after each commit, behind a new
set_default_version config (defaults to true). Using 'LAST' keeps the
statement idempotent and makes promotion self-healing: an agent whose pointer
was pinned out-of-band is un-stuck by the next dbt run. Note the quotes are
required — the unquoted forms the Snowflake docs show (LAST, VERSION$3) are
rejected with a SQL compilation error.
Also stop ADD LIVE VERSION from failing with 099106 ("There is already a live
version"), the state a prior CREATE OR REPLACE (dbt run --full-refresh)
leaves behind. SHOW VERSIONS is now inspected per row so an existing LIVE
working copy is detected and modified in place instead of re-added, which
un-wedges a versioned run following a full refresh.
Add cortex_agent_versioned_test_default_is_newest asserting the newest
committed version is the default. The existing has_versions test only checks
that versions exist and passes on a stale pointer, which is why CI never
caught this.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Problem
ALTER AGENT ... COMMITcreates a version but does not move theDEFAULTpointer, so the version dbt just deployed was not necessarily the one end users get.This stayed hidden because Snowflake treats the newest committed version as default implicitly — but only until
DEFAULT_VERSIONis set explicitly by anything out-of-band (most likely Snowsight's Publish button). From that moment the pointer is pinned and never moves again: every laterdbt runcommits a version nobody sees, while Snowsight keeps showing an older version as "In use" with history piling up behind it. It never self-corrects.Changes
snowflake__set_cortex_agent_default_version— issuesALTER AGENT ... SET DEFAULT_VERSION = 'LAST'after each commit, behind a newset_default_versionconfig (defaults totrue). Using'LAST'keeps it idempotent and makes promotion self-healing: an agent pinned out-of-band is un-stuck by the nextdbt run.099106fix —ADD LIVE VERSIONno longer fails with "There is already a live version", the state a priorCREATE OR REPLACE(dbt run --full-refresh) leaves behind.SHOW VERSIONSis now inspected per row, so an existing LIVE working copy is detected and modified in place instead of re-added. This un-wedges a versioned run following a full refresh.cortex_agent_versioned_test_default_is_newest— asserts the newest committed version is the default.Reviewer notes
The Snowflake docs are wrong here. The unquoted forms the docs show (
SET DEFAULT_VERSION = LAST,= VERSION$3,= "VERSION$3") all fail with a SQL compilation error. Only the single-quoted string form parses. The first deploy attempt failed on exactly this; caught by testing against a live account rather than trusting the page.Why CI never caught this: the existing
..._has_versionstest only checks that versions exist. On a stale pointer it passes — the new test fails. Verified both ways (see below).Design call worth confirming:
set_default_versiondefaults totruewith an opt-out for teams that promote versions themselves (e.g. staged releases via aliases). Happy to make promotion unconditional and drop the flag if preferred.Verification
All against live Snowflake (
TRAINING_SANDBOX.TEST_QS_INTEGRATION_TESTS):VERSION$1, deploy)VERSION$4committed, pointer stayed on$1VERSION$1, deploy)VERSION$6committed and promotedhas_versionsPASSEDset_default_version=falseopt-out099106wedge (--full-refreshthen plaindbt run)dbt parse+dbt build --select cortex_agent_versioned_test+Both the CI and local test agents are currently aligned (newest == default, no dangling LIVE version).
🤖 Generated with Claude Code