Skip to content

feat(core): support native Snowflake Cortex authentication - #47156

Merged
rekram1-node merged 6 commits into
v2from
snowflake-native
Sep 8, 2026
Merged

rekram1-node merged 6 commits into
v2from
snowflake-native

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Supersedes #47135, #47139, and #47151. Changes only the existing Snowflake plugin and its tests. Updated against the latest v2, including the @opencode package names and current session request API.

  • Use the existing OpenAI-compatible-to-native mapping and compatibility.maxTokensField, removing Snowflake's AI SDK hook/fetch wrapper and redundant package overrides. The native stream parser already supports empty delta roles, so stream-role rewriting is unnecessary.
  • Add browser OAuth with account/role prompts, PKCE, a scoped loopback callback, and token refresh. Add an account prompt for manual PATs and construct account-specific endpoints from environment, saved credentials, or configuration.
  • Register only SNOWFLAKE_CORTEX_TOKEN and SNOWFLAKE_CORTEX_PAT as credential environment variables. SNOWFLAKE_ACCOUNT configures the endpoint and is never an API key.
  • Use session HTTP hooks for environment-token overrides and Cortex's conversation-complete response. Let normal model resolution supply and proactively refresh stored credentials; refresh once on an initial 401 and let the session runner retry.
  • Keep valid environment-token overrides usable even if an expired saved OAuth login has a revoked refresh token. Preserve the saved OAuth credential for when the override is removed.

Verification

The cleanup pass removes 28 lines: the plugin is 264 lines and its tests are 290. It removes redundant refresh-token arguments and callback wrappers, and shares expired-credential fixtures, stop-response assertions, and polling setup. All six Snowflake tests and their 42 assertions are retained.

Six focused Snowflake integration tests cover:

  • Browser OAuth/PKCE, refresh-on-401, and native retry credentials.
  • Manual PAT account selection, native max-token serialization, and empty-role SSE parsing.
  • Forged-state rejection before token exchange.
  • Environment token precedence over PAT/account values and expired stored OAuth.
  • Env-only PAT setup, account-only setup having no credential, and unrelated 400 errors remaining errors.
  • Automatic refresh during native model resolution, including refresh-token rotation and persistence.

Token/model responses are scripted at the HTTP-client boundary; browser callbacks use a real loopback listener. Requests run through the actual model resolver, session request preparation, and native LLM stream.

Checks:

  • bun typecheck in packages/core — passed.
  • bun test test/plugin/provider-snowflake-cortex.test.ts test/integration.test.ts test/model-resolver.test.ts test/session-model-request.test.ts in packages/core — 67 pass.
  • Focused type-aware lint — passed.
  • git diff --check — passed.

No live Snowflake account authorization was performed.

@rekram1-node
rekram1-node merged commit e817723 into v2 Sep 8, 2026
10 checks passed
@rekram1-node
rekram1-node deleted the snowflake-native branch September 8, 2026 03:50
@rekram1-node

Copy link
Copy Markdown
Collaborator Author

Follow-up: investigate shared OAuth refresh and authentication retry behavior across providers. Consolidate expiry-based and forced refresh into one per-credential operation that coalesces concurrent refreshes and persists the result once. Replace Snowflake’s attempt === 2 guard with an explicit bounded authentication-recovery policy, deciding the allowance boundary against V1 behavior. Cover concurrent requests, refresh-token rotation, 503 → 401 → recovery, and repeated 401 termination. Keep this separate from the remaining provider ports (Poe browser OAuth; GitLab OAuth and workflow discovery).

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.

1 participant