fix: [#827] finops_* 100% failure — add warehouse-resolver fallback
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 failfinops_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:
- Auto-picks the first compatible warehouse when the caller omits
warehouse(matches the pattern already used bysql.explain) - Returns actionable errors when resolution fails — naming the available warehouses, suggesting
warehouse_add, listing the supported types - 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 teston 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.tspackages/opencode/src/altimate/native/finops/query-history.tspackages/opencode/src/altimate/native/types.ts(warehousemade optional in 3 param interfaces)packages/opencode/src/altimate/tools/finops-analyze-credits.tspackages/opencode/src/altimate/tools/finops-query-history.tspackages/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
resolveFinopsWarehouseto 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
warehouseoptional in native params and tool schemas; descriptions updated to document fallback. - Formatter fixes: expensive queries accept
query_previewand useexecution_time_sec; query history readsavg_execution_time_sec,total_execution_time_sec, anderror_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.messageacross 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-dbtwith a pinned registry. Expected impact: finops error rates drop to real operational failures (permissions/connectivity) with original driver messages preserved.
- Applied
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.