Skip to content

Promote newly committed agent version to DEFAULT - #9

Merged
paulnarup merged 1 commit into
masterfrom
feature/agent-default-version
Aug 10, 2026
Merged

Promote newly committed agent version to DEFAULT#9
paulnarup merged 1 commit into
masterfrom
feature/agent-default-version

Conversation

@quinnsebso

Copy link
Copy Markdown
Collaborator

Problem

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 stayed hidden because Snowflake treats the newest committed version as default implicitly — but only until DEFAULT_VERSION is 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 later dbt run commits 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

  • New macro snowflake__set_cortex_agent_default_version — issues ALTER AGENT ... SET DEFAULT_VERSION = 'LAST' after each commit, behind a new set_default_version config (defaults to true). Using 'LAST' keeps it idempotent and makes promotion self-healing: an agent pinned out-of-band is un-stuck by the next dbt run.
  • 099106 fixADD LIVE VERSION no longer fails with "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. This un-wedges a versioned run following a full refresh.
  • New test cortex_agent_versioned_test_default_is_newest — asserts the newest committed version is the default.
  • README — documents the new option, the promotion step, and the quoting gotcha below.

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_versions test 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_version defaults to true with 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):

Check Result
Bug reproduced on unfixed code (pin VERSION$1, deploy) VERSION$4 committed, pointer stayed on $1
Fix promotes + self-heals (pin VERSION$1, deploy) VERSION$6 committed and promoted
New test has teeth (stale pointer) FAIL, while has_versions PASSED
set_default_version=false opt-out version committed, pointer deliberately untouched
099106 wedge (--full-refresh then plain dbt run) both succeed
dbt parse + dbt build --select cortex_agent_versioned_test+ clean, PASS=4

Both the CI and local test agents are currently aligned (newest == default, no dangling LIVE version).

🤖 Generated with Claude Code

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>
@paulnarup
paulnarup merged commit c30f35d into master Aug 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants