Skip to content

fix: pass warehouse dialect to altimate-core tools instead of hardcoding snowflake#550

Open
VJ-yadav wants to merge 5 commits intoAltimateAI:mainfrom
VJ-yadav:fix/hardcoded-snowflake-dialect
Open

fix: pass warehouse dialect to altimate-core tools instead of hardcoding snowflake#550
VJ-yadav wants to merge 5 commits intoAltimateAI:mainfrom
VJ-yadav:fix/hardcoded-snowflake-dialect

Conversation

@VJ-yadav
Copy link
Copy Markdown
Contributor

@VJ-yadav VJ-yadav commented Mar 28, 2026

Summary

Fixes #455 — Adds optional dialect parameter (default: "snowflake") to all 8 altimate-core tools that were hardcoding it:

  • altimate-core-validate.ts, fix.ts, correct.ts, semantics.ts, equivalence.ts, policy.ts, check.ts
  • impact-analysis.ts

Each tool now accepts dialect via zod schema, passes it to the Dispatcher call, and includes it in telemetry metadata. Follows the pattern already established in sql-analyze.ts, sql-optimize.ts, and schema-diff.ts.

Type interfaces updated in types.ts. Tests updated to pass dialect explicitly.

Test Plan

  • bun turbo typecheck — 5/5 packages pass
  • bun test test/altimate/schema-finops-dbt.test.ts — 56 pass
  • bun test test/altimate/tool-error-propagation.test.ts — 22 pass
  • Manual: run tools with dialect: "postgres" and verify it reaches telemetry

Checklist

  • Follows existing pattern from sql-analyze/optimize/schema-diff
  • Default value preserves backward compatibility
  • No breaking changes
  • Tests updated

Summary by CodeRabbit

  • New Features

    • Altimate tools (validate, check, fix, correct, policy, semantics, equivalence) accept an optional dialect parameter (default "snowflake").
    • Tool responses/metadata now include the provided dialect for all outcomes (success, failure, and error paths).
    • Schema resolution fallback parsing now respects the provided dialect for consistent SQL parsing/validation.
  • Tests

    • Tests updated to include and assert dialect handling across affected tools.

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is missing the required 'PINEAPPLE' identifier that must be included at the top for AI-generated contributions per the template. Add 'PINEAPPLE' at the very beginning of the PR description before the Summary section.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: adding dialect parameter support to altimate-core tools instead of hardcoding snowflake.
Linked Issues check ✅ Passed All primary objectives from issue #455 are addressed: dialect parameter added to 8 tools, passed to Dispatcher calls, included in metadata, with default 'snowflake' for backward compatibility.
Out of Scope Changes check ✅ Passed All changes are directly related to adding dialect parameter support to the eight specified tools; no unrelated modifications detected in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@dev-punia-altimate
Copy link
Copy Markdown

🤖 Behavioral Analysis — 4 Finding(s)

🟡 Warnings (3)

  • FINDING-001 packages/opencode/src/altimate/tools/altimate-core-validate.ts:20 [logic_error]
    The early-return 'NO SCHEMA' path (the if (noSchema) guard before the try block) returns metadata without the dialect field, while all other return paths in this file are updated to include dialect. When noSchema is true the function returns metadata: { success: false, valid: false, has_schema: false, error } — omitting dialect. This is inconsistent with the PR's goal of including dialect in all telemetry metadata; the most common early-failure case (no schema provided) will have dialect missing.

  • FINDING-002 packages/opencode/src/altimate/tools/altimate-core-semantics.ts:21 [logic_error]
    Same issue as FINDING-001: the early-return 'NO SCHEMA' path (if (!hasSchema) guard before the try block) returns metadata without dialect. The PR only adds dialect to the Dispatcher.call, success, and catch paths. The early-return returns metadata: { success: false, valid: false, issue_count: 0, has_schema: false, error } — missing dialect.

  • FINDING-003 packages/opencode/src/altimate/tools/altimate-core-equivalence.ts:22 [logic_error]
    Same issue: the early-return 'NO SCHEMA' path returns metadata without dialect. The if (!hasSchema) guard returns metadata: { success: false, equivalent: false, has_schema: false, error } — missing dialect. The PR adds dialect to the other paths but misses this one.

🔵 Nits (1)

  • FINDING-004 packages/opencode/src/altimate/tools/impact-analysis.ts:38 [consistency]
    The two operational early-return paths in impact-analysis.ts — 'NO MANIFEST' (when manifest is empty) and 'MODEL NOT FOUND' (when target model is not found in the DAG) — return bare metadata: { success: false } objects without dialect or other telemetry fields. The PR adds dialect to the success and catch paths but does not update these early returns. Low severity since these are configuration errors rather than SQL analysis failures, but inconsistent with the PR's intent.

Analysis run | Powered by QA Autopilot

@dev-punia-altimate
Copy link
Copy Markdown

Auto-fixed 4 finding(s)

  • FINDING-001
  • FINDING-002
  • FINDING-003
  • FINDING-004

@gitguardian
Copy link
Copy Markdown

gitguardian bot commented Mar 31, 2026

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/opencode/src/altimate/tools/altimate-core-correct.ts`:
- Around line 22-27: The six native handlers drop the dialect despite it being
passed in params; update altimate_core.validate, altimate_core.check,
altimate_core.fix, altimate_core.semantics, altimate_core.equivalence, and
altimate_core.correct so their core calls include the dialect (use
params.dialect || undefined) when invoking core.validate, core.fix,
core.checkSemantics, core.checkEquivalence, and core.correct respectively;
ensure each call signature matches the core function's dialect parameter
position and propagate params.dialect in the same pattern used by other handlers
(e.g., formatSql, extractMetadata, compareQueries).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 46aff016-36ac-4072-a604-a460e3a35cc1

📥 Commits

Reviewing files that changed from the base of the PR and between 5d0ada3 and 3ff930e.

📒 Files selected for processing (11)
  • packages/opencode/src/altimate/native/types.ts
  • packages/opencode/src/altimate/tools/altimate-core-check.ts
  • packages/opencode/src/altimate/tools/altimate-core-correct.ts
  • packages/opencode/src/altimate/tools/altimate-core-equivalence.ts
  • packages/opencode/src/altimate/tools/altimate-core-fix.ts
  • packages/opencode/src/altimate/tools/altimate-core-policy.ts
  • packages/opencode/src/altimate/tools/altimate-core-semantics.ts
  • packages/opencode/src/altimate/tools/altimate-core-validate.ts
  • packages/opencode/src/altimate/tools/impact-analysis.ts
  • packages/opencode/test/altimate/e2e-tool-errors.ts
  • packages/opencode/test/altimate/tool-error-propagation.test.ts

@VJ-yadav VJ-yadav force-pushed the fix/hardcoded-snowflake-dialect branch from 3ff930e to 6edf2e5 Compare April 3, 2026 06:15
@dev-punia-altimate
Copy link
Copy Markdown

❌ Tests — Failures Detected

TypeScript — 15 failure(s)

  • connection_refused [2.80ms]
  • timeout [2.60ms]
  • permission_denied [2.82ms]
  • parse_error [2.38ms]
  • oom [2.70ms]
  • network_error [2.46ms]
  • auth_failure [2.69ms]
  • rate_limit [2.87ms]
  • internal_error [2.76ms]
  • empty_error [0.24ms]
  • connection_refused [0.15ms]
  • timeout [0.08ms]
  • permission_denied [0.08ms]
  • parse_error [0.08ms]
  • oom [0.07ms]

cc @VJ-yadav
Tested at 6edf2e59 | Run log | Powered by QA Autopilot

@anandgupta42
Copy link
Copy Markdown
Contributor

Review — Ready for merge

Scope: Fixes #455 — replaces hardcoded dialect: "snowflake" across 8 altimate-core tools with an explicit parameter (default "snowflake" for backward compat). Follows the established pattern from sql-analyze.ts/sql-optimize.ts/schema-diff.ts.

Analysis

  • Tools updated: altimate-core-{validate,fix,correct,semantics,equivalence,policy,check}.ts + impact-analysis.ts
  • Each tool now: (1) zod schema accepts optional dialect, (2) Dispatcher call passes it, (3) telemetry metadata includes it for sql_quality event completeness
  • Type interfaces in types.ts updated accordingly
  • Default "snowflake" preserves backward compat — no breaking change
  • 4 review findings from the dev-punia-altimate behavioral analyzer were auto-fixed (FINDING-001…004, including the noSchema early-return path that originally missed the dialect field in metadata)

Files changed: 13 files, +108 −46

CI status (commit 6edf2e59)

  • ✅ TypeScript, anti-slop, check-standards, check-compliance, Marker Guard, GitGuardian — all green
  • ✅ CodeRabbit: "No actionable comments" after auto-fixes
  • ⚠️ centralized-test-results — same pre-existing 15-failure flakiness as every other open PR in this batch

Recommendation
Ready for merge — rebase on main (BEHIND). This unblocks sql_quality telemetry dialect attribution for 8 tools that were silently mis-reporting as Snowflake. Fixes a clean observability gap.

cc @anandgupta42 — ready for /release once rebased.

@anandgupta42 anandgupta42 force-pushed the fix/hardcoded-snowflake-dialect branch from aaa1816 to 4ceea83 Compare April 5, 2026 06:41
anandgupta42 pushed a commit to VJ-yadav/altimate-code that referenced this pull request Apr 5, 2026
Code review (Gemini 3.1 Pro) caught a missed handler in the
dialect-threading migration: 'altimate_core.policy' (altimate-core.ts:200)
called schemaOrEmpty() without params.dialect, while the 6 other policy-
family handlers (validate, check, fix, semantics, equivalence, correct,
explain) all pass it through.

AltimateCorePolicyParams already declares 'dialect?: string' in types.ts
and the tool definition plumbs it into Dispatcher.call(), so the param
was reaching the handler but being silently discarded at the schema
resolution step — meaning the fallback empty schema was always built
with the default (Snowflake) dialect instead of the user-selected one,
defeating the purpose of PR AltimateAI#550 for policy checks specifically.

1-line fix brings the policy handler into line with its 6 siblings.
@anandgupta42
Copy link
Copy Markdown
Contributor

Consensus code-review applied — fix pushed

Ran a 4-participant consensus review (Claude + GPT 5.4 + Gemini 3.1 Pro + self-review).

Real bug found and fixed

CRITICAL — altimate_core.policy handler ignored dialect (Gemini)

The dialect parameter was correctly plumbed through the tool → Dispatcher → type definition, but the native handler at packages/opencode/src/altimate/native/altimate-core.ts:200 called schemaOrEmpty(params.schema_path, params.schema_context) without params.dialect, while the 6 sibling handlers (validate, check, fix, semantics, equivalence, correct, explain) all pass it through.

Effect: policy checks with a user-provided dialect would silently build the fallback empty schema with the default (Snowflake) dialect instead of the user-selected one — defeating the purpose of this PR for policy checks specifically.

1-line fix brings the policy handler into line with its siblings.

Scope discussion

Gemini also flagged that the PR doesn't migrate dialect into the ~20 OTHER altimate_core handlers (rewrite, testgen, grade, prune_schema, etc.). That's intentionally out of scope — issue #455 explicitly lists the 8 tools this PR targets. The remaining handlers can get dialect as a follow-up if needed; no silent-fallback bug exists for tools that aren't updated (they don't accept dialect at the tool level yet).

Test coverage

29 existing altimate-core-native tests continue to pass. No new tests added because schemaOrEmpty's dialect parameter only affects the fallback empty-schema path (which is exercised via integration tests, not easily isolated for unit assertions without a real policy JSON + altimate-core binary).

Pushed as d2ad6ac846. Ready for merge.

@VJ-yadav
Copy link
Copy Markdown
Contributor Author

Hi @anandgupta42 — you mentioned this is ready for merge after the consensus review + policy handler fix (d2ad6ac). There are merge conflicts now though — I'll rebase and resolve. Once CI is green again, ready to merge.

VJ-yadav added a commit to VJ-yadav/altimate-code that referenced this pull request Apr 13, 2026
Code review (Gemini 3.1 Pro) caught a missed handler in the
dialect-threading migration: 'altimate_core.policy' (altimate-core.ts:200)
called schemaOrEmpty() without params.dialect, while the 6 other policy-
family handlers (validate, check, fix, semantics, equivalence, correct,
explain) all pass it through.

AltimateCorePolicyParams already declares 'dialect?: string' in types.ts
and the tool definition plumbs it into Dispatcher.call(), so the param
was reaching the handler but being silently discarded at the schema
resolution step — meaning the fallback empty schema was always built
with the default (Snowflake) dialect instead of the user-selected one,
defeating the purpose of PR AltimateAI#550 for policy checks specifically.

1-line fix brings the policy handler into line with its 6 siblings.
@VJ-yadav VJ-yadav force-pushed the fix/hardcoded-snowflake-dialect branch from 0ae637d to 758b8e5 Compare April 13, 2026 20:09
VJ-yadav and others added 5 commits April 13, 2026 20:27
…ing snowflake

Add optional `dialect` parameter (default: "snowflake") to all 8
altimate-core tools that were missing it:

- altimate-core-validate, fix, correct, semantics,
  equivalence, policy, check, and impact-analysis

Each tool now:
1. Accepts `dialect` via its zod parameter schema
2. Passes it through to the Dispatcher call
3. Includes it in telemetry metadata

Follows the pattern established in sql-analyze.ts, sql-optimize.ts,
and schema-diff.ts. Type interfaces updated in types.ts.
Tests updated to pass dialect explicitly.

Fixes AltimateAI#455

Co-Authored-By: Vijay Yadav <vijay@studentsucceed.com>
Address behavioral analysis findings: the NO SCHEMA early returns in
validate, semantics, and equivalence tools, plus the NO MANIFEST and
MODEL NOT FOUND early returns in impact-analysis, were missing the
dialect field in their metadata. All return paths now consistently
include dialect for telemetry.

Co-Authored-By: Vijay Yadav <vijay@studentsucceed.com>
The dialect parameter was passed through the tool layer but dropped at
the schema resolution step. Six native handlers (validate, check, fix,
semantics, equivalence, correct) called schemaOrEmpty() without dialect,
so the fallback empty schema always used the default dialect.

Fix: add optional dialect param to schemaOrEmpty() and pass it to
Schema.fromDdl(). Update all six handlers to forward params.dialect.

Co-Authored-By: Vijay Yadav <vjyadav194@gmail.com>
Code review (Gemini 3.1 Pro) caught a missed handler in the
dialect-threading migration: 'altimate_core.policy' (altimate-core.ts:200)
called schemaOrEmpty() without params.dialect, while the 6 other policy-
family handlers (validate, check, fix, semantics, equivalence, correct,
explain) all pass it through.

AltimateCorePolicyParams already declares 'dialect?: string' in types.ts
and the tool definition plumbs it into Dispatcher.call(), so the param
was reaching the handler but being silently discarded at the schema
resolution step — meaning the fallback empty schema was always built
with the default (Snowflake) dialect instead of the user-selected one,
defeating the purpose of PR AltimateAI#550 for policy checks specifically.

1-line fix brings the policy handler into line with its 6 siblings.
The upstream altimate-core-validate tests (PR AltimateAI#693) call execute()
without dialect, but our PR made dialect a required field in the
zod output type. Add explicit dialect: 'snowflake' to all test calls.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@VJ-yadav VJ-yadav force-pushed the fix/hardcoded-snowflake-dialect branch from 758b8e5 to 82af0f7 Compare April 14, 2026 00:34
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
packages/opencode/test/altimate/tools/altimate-core-validate.test.ts (2)

305-317: Consider verifying dialect is passed to Dispatcher.

This test already spies on Dispatcher.call — adding an assertion on the call arguments would validate that the dialect is correctly propagated to the backend.

♻️ Proposed enhancement
     const tool = await AltimateCoreValidateTool.init()
     await tool.execute({ sql: "SELECT 1", dialect: "snowflake" }, ctx as any)

     expect(spy).toHaveBeenCalledTimes(1)
+    expect(spy.mock.calls[0][0]).toBe("altimate_core.validate")
+    expect(spy.mock.calls[0][1]).toMatchObject({ dialect: "snowflake" })
     spy.mockRestore()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/altimate/tools/altimate-core-validate.test.ts` around
lines 305 - 317, Add an assertion to the existing spy on Dispatcher.call to
verify that the dialect argument is forwarded to the dispatcher: after calling
AltimateCoreValidateTool.init() and tool.execute(...), inspect the spy's most
recent call (Dispatcher.call) and assert that the payload includes dialect:
"snowflake" (or that the second/appropriate arg contains the dialect), then
restore the spy; this change touches the test around the spyOn(Dispatcher,
"call") block in altimate-core-validate.test.ts to ensure dialect propagation.

172-178: Consider adding test coverage for a non-snowflake dialect.

All test cases use dialect: "snowflake". Since the PR enables multi-dialect support, adding at least one test with a different dialect (e.g., "postgres") would provide automated regression protection and verify the dialect parameter is correctly passed through the entire flow.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/altimate/tools/altimate-core-validate.test.ts` around
lines 172 - 178, Add a new unit test that mirrors the existing
AltimateCoreValidateTool.execute tests but uses a non-snowflake dialect (e.g.,
"postgres") to verify dialect propagation; specifically, create a test that
instantiates AltimateCoreValidateTool.execute (or the same test helper used in
this file), sets dialect: "postgres" in the input, spies on the
dispatcherSpy/spyOn target used by other tests, invokes the tool, and asserts
the dispatcher was called with the expected payload containing dialect:
"postgres" (and any downstream fields that should reflect the dialect) to ensure
the dialect parameter is passed through the flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/opencode/test/altimate/tools/altimate-core-validate.test.ts`:
- Around line 305-317: Add an assertion to the existing spy on Dispatcher.call
to verify that the dialect argument is forwarded to the dispatcher: after
calling AltimateCoreValidateTool.init() and tool.execute(...), inspect the spy's
most recent call (Dispatcher.call) and assert that the payload includes dialect:
"snowflake" (or that the second/appropriate arg contains the dialect), then
restore the spy; this change touches the test around the spyOn(Dispatcher,
"call") block in altimate-core-validate.test.ts to ensure dialect propagation.
- Around line 172-178: Add a new unit test that mirrors the existing
AltimateCoreValidateTool.execute tests but uses a non-snowflake dialect (e.g.,
"postgres") to verify dialect propagation; specifically, create a test that
instantiates AltimateCoreValidateTool.execute (or the same test helper used in
this file), sets dialect: "postgres" in the input, spies on the
dispatcherSpy/spyOn target used by other tests, invokes the tool, and asserts
the dispatcher was called with the expected payload containing dialect:
"postgres" (and any downstream fields that should reflect the dialect) to ensure
the dialect parameter is passed through the flow.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: da3518f0-c951-4ae3-aa1a-9ebde771109a

📥 Commits

Reviewing files that changed from the base of the PR and between 758b8e5 and 82af0f7.

📒 Files selected for processing (14)
  • packages/opencode/src/altimate/native/altimate-core.ts
  • packages/opencode/src/altimate/native/schema-resolver.ts
  • packages/opencode/src/altimate/native/types.ts
  • packages/opencode/src/altimate/tools/altimate-core-check.ts
  • packages/opencode/src/altimate/tools/altimate-core-correct.ts
  • packages/opencode/src/altimate/tools/altimate-core-equivalence.ts
  • packages/opencode/src/altimate/tools/altimate-core-fix.ts
  • packages/opencode/src/altimate/tools/altimate-core-policy.ts
  • packages/opencode/src/altimate/tools/altimate-core-semantics.ts
  • packages/opencode/src/altimate/tools/altimate-core-validate.ts
  • packages/opencode/src/altimate/tools/impact-analysis.ts
  • packages/opencode/test/altimate/e2e-tool-errors.ts
  • packages/opencode/test/altimate/tool-error-propagation.test.ts
  • packages/opencode/test/altimate/tools/altimate-core-validate.test.ts
✅ Files skipped from review due to trivial changes (3)
  • packages/opencode/src/altimate/native/altimate-core.ts
  • packages/opencode/src/altimate/native/types.ts
  • packages/opencode/test/altimate/tool-error-propagation.test.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • packages/opencode/src/altimate/tools/altimate-core-validate.ts
  • packages/opencode/src/altimate/tools/altimate-core-correct.ts
  • packages/opencode/src/altimate/native/schema-resolver.ts
  • packages/opencode/src/altimate/tools/altimate-core-semantics.ts
  • packages/opencode/src/altimate/tools/altimate-core-check.ts
  • packages/opencode/src/altimate/tools/altimate-core-policy.ts
  • packages/opencode/test/altimate/e2e-tool-errors.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hardcoded dialect: "snowflake" across altimate-core tools

3 participants