fix: [#827] finops_* 100% failure — add warehouse-resolver fallback

Merged
AN
5mo ago
+779-126

What does this PR do?

Fixes the finops_* tools that telemetry showed at 100% error rate across the last 14 days (memory/telemetry-analysis-2026-05-21.md, 2,503 machines). Specifically:

  • finops_analyze_credits: 8/8 calls fail
  • finops_query_history: 1/1 call fails

The dominant failure mode was the LLM either omitting warehouse or passing an unknown / unsupported name, and getting back a dead-end "Credit analysis is not available for unknown warehouses." error with no path forward.

This PR adds a shared resolveFinopsWarehouse helper that:

  1. Auto-picks the first compatible warehouse when the caller omits warehouse (matches the pattern already used by sql.explain)
  2. Returns actionable errors when resolution fails — naming the available warehouses, suggesting warehouse_add, listing the supported types
  3. Centralizes the per-operation type constraints (Snowflake/BigQuery/Databricks for credits; broader for query history)

warehouse is now an optional parameter on both tool schemas, so the LLM can call them without guessing a name.

This is on the critical path for the cost-audit wedge use-case — the workflow cannot complete without these tools working.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Issue for this PR

Closes #827

How did you verify your code works?

  • tsgo --noEmit: pass, zero errors
  • New test/altimate/finops-warehouse-resolver.test.ts: 12 tests covering every resolution branch (ok / unknown name / unsupported type / no config / empty string / whitespace-only / auto-pick / per-operation type lists / operation-name surfacing)
  • bun test test/altimate/finops-*: 37 pass / 0 fail (12 new + 25 existing)
  • bun test on the credentials-gated e2e suites (finops-snowflake-e2e, finops-bigquery-e2e, finops-databricks-e2e, schema-finops-dbt, finops-role-access): 85 pass / 67 skip (credential-gated) / 0 fail — no regressions
  • Marker check (bun run script/upstream/analyze.ts --markers --base main --strict): pass — no upstream-shared files touched

Checklist

  • My code follows the project's code style
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes
  • Marker check passes
  • Linked to issue #827
  • /consensus:code-review — deferred until reviewer requests; this is a small, well-tested fix

Files changed (7):

  • packages/opencode/src/altimate/native/finops/warehouse-resolver.ts (new)
  • packages/opencode/src/altimate/native/finops/credit-analyzer.ts
  • packages/opencode/src/altimate/native/finops/query-history.ts
  • packages/opencode/src/altimate/native/types.ts (warehouse made optional in 3 param interfaces)
  • packages/opencode/src/altimate/tools/finops-analyze-credits.ts
  • packages/opencode/src/altimate/tools/finops-query-history.ts
  • packages/opencode/test/altimate/finops-warehouse-resolver.test.ts (new)

Expected telemetry impact: error rate on finops_analyze_credits and finops_query_history should drop from 100% to whatever the real operational failure rate is (warehouse unreachable, ACCOUNT_USAGE permissions missing, etc.). The resolver no longer masks driver errors as "unknown warehouse" — they pass through with their original message.


Summary by cubic

Adds a shared warehouse resolver across all finops_* tools to auto-pick a compatible warehouse, trim whitespace in requested names, and return clear, actionable errors; makes warehouse optional and fixes formatter/output issues so timings and driver messages are correct. Fixes #827.

  • Bug Fixes
    • Applied resolveFinopsWarehouse to credits, expensive queries, query history, role/access, warehouse advice, and unused resources; auto-picks when omitted, trims requested names, matches types case-insensitively, and returns clear errors with available names and supported types (credits/expensive/unused/advice: Snowflake/BigQuery/Databricks; history: +Postgres/+ClickHouse; role hierarchy/user roles: Snowflake only).
    • Made warehouse optional in native params and tool schemas; descriptions updated to document fallback.
    • Formatter fixes: expensive queries accept query_preview and use execution_time_sec; query history reads avg_execution_time_sec, total_execution_time_sec, and error_count; warehouse advice uses real fields (avg_time_sec, p95_time_sec, avg_concurrency, avg_queue_load, peak_queue_load, sample_count) and guards nulls.
    • Normalized error handling to surface driver e.message across all handlers; internal template-missing paths report clear “internal error” messages instead of unsupported-type text.
    • Tests: added resolver suite (auto-pick, unknown/unsupported, case-insensitive, whitespace trim) and stabilized schema-finops-dbt with a pinned registry. Expected impact: finops error rates drop to real operational failures (permissions/connectivity) with original driver messages preserved.

Summary by CodeRabbit

  • New Features

    • Warehouse parameter is now optional for FinOps operations—omitting it auto-selects the first compatible warehouse.
  • Improvements

    • Centralized warehouse resolution with clearer, actionable error messages and normalized failure responses.
    • Tools broadened to Snowflake, BigQuery, Databricks; execution-time fields now use *_sec variants and query previews are preferred when available.
    • Defensive output handling to avoid errors on partial results; clarified role-tool defaulting for Snowflake.
  • Tests

    • Added resolver tests for resolution, auto-pick, trimming/case-insensitivity, and error scenarios.

Review Change Stack