Repository navigation
Commit 00738e9
* fix: [#827] resolve finops_* 100% failure with warehouse-resolver fallback
Telemetry (memory/telemetry-analysis-2026-05-21.md, 2,503 machines, 14 days)
flagged `finops_analyze_credits` (8/8) and `finops_query_history` (1/1) as
100% broken. Every user who tried them hit a dead-end "Credit analysis is
not available for unknown warehouses." error with no path forward.
Unlike `sql.explain` (which auto-falls-back to `warehouses[0]`), the finops
handlers had no resolution logic and returned an unhelpful error whenever
the caller omitted the warehouse name, supplied an unknown one, or supplied
one whose type wasn't supported.
Changes
- New shared helper `finops/warehouse-resolver.ts` with a 4-branch resolution
contract (ok / not configured / unknown name / unsupported type) and
actionable errors that name the available warehouses and suggest
`warehouse_add` when nothing is configured.
- `credit-analyzer.ts` (analyzeCredits, getExpensiveQueries) and
`query-history.ts` (getQueryHistory) wired to the resolver. The dead
`getWhType` helpers removed.
- `warehouse` parameter made optional on the `finops_analyze_credits` and
`finops_query_history` tool schemas; descriptions updated to document
the auto-pick behaviour and the full supported-warehouse list.
- `CreditAnalysisParams`, `ExpensiveQueriesParams`, `QueryHistoryParams`
marked `warehouse?` to match the new optionality contract.
- 12 new unit tests in `test/altimate/finops-warehouse-resolver.test.ts`
pinning every resolution branch including empty-string and
whitespace-only requested values.
Expected impact
- Error rate on `finops_analyze_credits` and `finops_query_history` drops
from 100% to whatever the real operational failure rate is (warehouse
unreachable, ACCOUNT_USAGE permission missing, etc.). The resolver no
longer masks those as "unknown warehouse" — driver errors pass through
with their original message.
- Cost-audit wedge demo now works on any tenant with a Snowflake / BigQuery
/ Databricks warehouse configured, without the LLM needing to guess the
exact warehouse name.
Validation
- `tsgo --noEmit`: pass, zero errors.
- `bun test test/altimate/finops-*`: 37 pass / 0 fail (12 new + 25 existing).
- `bun test test/altimate/finops-*-e2e.test.ts test/altimate/schema-finops-dbt.test.ts test/altimate/finops-role-access.test.ts`: 85 pass / 67 skip (credentials-gated) / 0 fail.
- Marker check: pass — no upstream-shared files touched.
Closes #827
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* fix: [#827] address consensus review — apply resolver to all 5 finops handlers + formatter fix + case-insensitivity
Multi-model consensus review of the original commit identified four
in-scope issues this commit addresses:
1. finops_expensive_queries tool schema not updated (5/6 reviewer consensus)
The handler in credit-analyzer.ts was already wired to the resolver, but
the tool schema still required `warehouse` and the description claimed
"Snowflake only" — leaving the auto-pick fallback unreachable for that
tool. Schema and description updated to match the other two tools.
2. Formatter field-name mismatch in finops-query-history.ts and
finops-expensive-queries.ts (2/6 independent catches, both MAJOR)
The formatters read `summary.avg_execution_time` / `q.execution_time`,
but the native handler returns `_sec`-suffixed keys (`avg_execution_time_sec`
and per-row `execution_time_sec`). Pre-existing silent data loss: average
time line never rendered, per-query exec time always "-". Auto-pick from
the prior commit routes more users through these formatters, expanding
the impact. Both formatters updated to read the correct keys.
3. Other finops handlers had the same dead-end pattern (Gemini CRITICAL,
Kimi MAJOR). warehouse-advisor.ts (adviseWarehouse), unused-resources.ts
(findUnusedResources), role-access.ts (queryGrants, queryRoleHierarchy,
queryUserRoles) all rewired to use resolveFinopsWarehouse. Their tool
schemas (finops-warehouse-advice, finops-unused-resources, three tools
in finops-role-access) made warehouse optional. Type signatures in
native/types.ts updated to match. role-access uses a SNOWFLAKE_ONLY_TYPES
const for queryRoleHierarchy and queryUserRoles.
4. Case-sensitivity bug (DeepSeek unique catch). The driver lookup in
registry.ts uses toLowerCase() via DRIVER_MAP, so configs with
`type: "Snowflake"` (capitalized) get a working driver — but the
resolver's case-sensitive supportedTypes.includes(match.type) failed
them with a spurious "not available for Snowflake" error. Resolver now
normalizes type via toLowerCase() at every comparison, and the returned
`type` field is the lowercased form so downstream SQL-template selectors
continue to compare against "snowflake" / "bigquery" / "databricks".
Plus two cleanup items from the review:
- Removed unused `sanitizeBqRegion` import from query-history.ts (Claude NIT)
- Added a code comment in the resolver documenting the intentional
warehouse-name disclosure in error messages (resolves the disputed
security concern with the synthesis's rationale)
Test changes
- Added 3 new test cases pinning case-insensitive type matching, including
mixed-case (`type: "Snowflake"`), uppercase (`type: "SNOWFLAKE"`), and
auto-pick filtering with mixed-case types.
- Updated two assertions in schema-finops-dbt.test.ts to match the new
"not configured" error message (replacing the less-accurate old
"not available for X" — the warehouse never existed, regardless of type).
Validation
- `tsgo --noEmit`: pass, zero errors.
- `bun test test/altimate/finops-*`: 124 pass / 0 fail / 67 skip (credential-gated).
- `bun test test/altimate/tool-error-propagation.test.ts test/altimate/simulation-suite.test.ts`: 854 pass / 0 fail.
- Marker check: pass — no upstream-shared files touched.
Expected telemetry impact unchanged from prior commit: error rate on
finops_* tools should drop to operational baseline. With this commit, all
five finops handlers benefit, not just the two from the original PR. The
formatter fix recovers two display values that have been silently broken
for all users since these tools shipped.
Closes review feedback from PR #828 multi-model consensus.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* fix: [#827] address consensus review — test determinism + error consistency + formatter completeness
Third-pass on PR #828 after follow-up code review. Three follow-ups
in scope.
1. Test determinism (MINOR per reviewer)
`test/altimate/schema-finops-dbt.test.ts` was reading the warehouse
resolver's error message verbatim ("not configured") to assert the
unknown-warehouse path. That message only appears when the registry
has at least one warehouse configured — if the test ran in a fresh
sandbox or hermetic CI, the resolver would return "...none are set
up..." and the assertion would silently fail. Added a beforeAll /
afterAll block that captures the prior registry state, pins a known
two-warehouse config for the test, and restores afterwards.
2. Error stringification consistency (MINOR)
The first PR commit upgraded most `catch (e) { error: String(e) }`
to `e instanceof Error ? e.message : String(e)`, but role-access.ts
was missed (three handlers). Normalized all three to match the
credit-analyzer / query-history pattern — driver errors now surface
as `"...message..."` rather than `"Error: ...message..."`.
3. Formatter completeness (NIT)
`finops-query-history.ts` formatter surfaced only avg_execution_time
even though the underlying handler emits total_execution_time_sec and
error_count too. Added both: total exec time always shown; error count
shown only when > 0 to avoid cluttering the typical 0-error case.
Validation
- `tsgo --noEmit`: pass.
- `bun test test/altimate/schema-finops-dbt.test.ts
test/altimate/finops-warehouse-resolver.test.ts
test/altimate/finops-recommendations.test.ts`: 95 pass / 0 fail.
- Marker check: pass (no upstream-shared files in these paths).
Reviewer note
- GPT-5.4 second-opinion was unavailable (OpenRouter credit exhaustion).
Single-reviewer Claude analysis.
Deferred to follow-up
- Surface auto-picked warehouse name in handler success metadata
(reviewer NIT — separate ROADMAP item already tracked).
- Restore role-access BigQuery-IAM / Databricks-Unity hints lost in the
resolver rewrite (reviewer NIT — would require per-operation `hint`
field on `ResolveOptions`, separate enhancement).
- Tool-level integration test for the auto-pick path (reviewer suggestion
— requires Dispatcher mock scaffolding).
Closes review feedback for PR #828 (third pass).
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* fix: [#827] address re-review — finops_warehouse_advice formatter + last 2 String(e)
Fourth pass on PR #828. Re-review found one MAJOR formatter bug missed
by the previous formatter audit, plus the last two String(e) instances
that the third pass left behind.
1. MAJOR — formatter field-name mismatch in finops-warehouse-advice
Same class of bug as the one commit ed6f247 fixed for
finops-query-history.ts and finops-expensive-queries.ts — the
formatter read keys the handler never emits:
- Performance summary: read `avg_execution_time`, `avg_queue_time`,
`status`, `health`; handler emits `query_count`, `avg_time_sec`,
`p95_time_sec`, `avg_bytes_scanned`, `total_credits`.
- Load metrics: read `warehouse_size`, `avg_load`, `peak_load`,
`utilization`; handler emits `avg_concurrency`, `avg_queue_load`,
`peak_queue_load`, `sample_count`.
Every value rendered as "-" regardless of input. Auto-pick from the
prior commits expanded the user population hitting this formatter.
Fix: rewrote both table headers and row loops to read the actual
handler keys. Added inline comments pointing back at the previous
instance of this bug pattern so the next reviewer doesn't have to
discover it independently.
2. MINOR — null-guard on result.recommendations
`result.recommendations.length` was read directly. If a future
handler variance or partial success ever dropped the field, the
tool throws a TypeError instead of returning a structured error.
Coalesced to `[]`. Also defensive-defaulted warehouse_load and
warehouse_performance for the same reason.
3. MINOR — last two String(e) call sites
The third pass normalized role-access.ts but missed:
- unused-resources.ts:234
- warehouse-advisor.ts:301
Both fixed in this commit. All five finops handlers now use the
same `e instanceof Error ? e.message : String(e)` pattern, so
driver errors no longer carry "Error:" prefixes inconsistently.
Validation
- `tsgo --noEmit`: pass.
- `bun test test/altimate/finops-*.test.ts test/altimate/schema-finops-dbt.test.ts`:
95 pass / 0 fail / 67 skip (credential-gated).
- Marker check: pass.
Reviewer note
- GPT-5.4 and Kimi K2.5 second-opinions did not produce output this
round either — kilo CLI was preempted by other concurrent jobs on
the same OpenRouter quota. Single-reviewer Claude analysis.
Deferred to follow-up
- Tool-level integration test for each formatter (would have caught
all three formatter bugs at once — tracked as a separate quality
bar enhancement).
- warehouse_filter param silently ignored for BigQuery/Databricks
(description already documents Snowflake-only; tracking as NIT).
Closes review feedback for PR #828 (fourth pass).
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* fix: [#827] address cubic P2 — trim requested warehouse name before matching
Cubic flagged that valid warehouse names with leading/trailing whitespace
were incorrectly reported as unknown. LLMs occasionally surface names with
stray whitespace from prompt copy-paste or YAML/JSON serialization edge
cases — without the trim, " prod_wh" reports as unknown even though
"prod_wh" is configured.
The trim is on the lookup key only; configured names are stored as-is.
Added a 4-variant test that pins the contract (leading-only, trailing-only,
both-sides, tabs+newlines) so a refactor can't silently drop the trim.
15/15 resolver tests pass; marker check clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 476d234 commit 00738e9
15 files changed
Lines changed: 779 additions & 126 deletions
File tree
- packages/opencode
- src/altimate
- native
- finops
- tools
- test/altimate
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| |||
185 | 188 | | |
186 | 189 | | |
187 | 190 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | 191 | | |
195 | 192 | | |
196 | 193 | | |
| |||
302 | 299 | | |
303 | 300 | | |
304 | 301 | | |
305 | | - | |
306 | 302 | | |
307 | 303 | | |
308 | | - | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
309 | 324 | | |
310 | 325 | | |
311 | 326 | | |
312 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
313 | 331 | | |
314 | 332 | | |
315 | 333 | | |
| |||
318 | 336 | | |
319 | 337 | | |
320 | 338 | | |
321 | | - | |
| 339 | + | |
322 | 340 | | |
323 | 341 | | |
324 | 342 | | |
325 | 343 | | |
326 | | - | |
| 344 | + | |
327 | 345 | | |
328 | 346 | | |
329 | 347 | | |
| |||
348 | 366 | | |
349 | 367 | | |
350 | 368 | | |
351 | | - | |
| 369 | + | |
352 | 370 | | |
353 | 371 | | |
354 | 372 | | |
355 | 373 | | |
356 | 374 | | |
357 | | - | |
358 | 375 | | |
359 | 376 | | |
360 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
361 | 395 | | |
362 | 396 | | |
363 | 397 | | |
| |||
366 | 400 | | |
367 | 401 | | |
368 | 402 | | |
369 | | - | |
| 403 | + | |
370 | 404 | | |
371 | 405 | | |
372 | 406 | | |
373 | 407 | | |
374 | | - | |
| 408 | + | |
375 | 409 | | |
376 | 410 | | |
377 | 411 | | |
| |||
387 | 421 | | |
388 | 422 | | |
389 | 423 | | |
390 | | - | |
| 424 | + | |
391 | 425 | | |
392 | 426 | | |
393 | 427 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
11 | 21 | | |
12 | 22 | | |
13 | 23 | | |
| |||
141 | 151 | | |
142 | 152 | | |
143 | 153 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | 154 | | |
151 | 155 | | |
152 | 156 | | |
| |||
210 | 214 | | |
211 | 215 | | |
212 | 216 | | |
213 | | - | |
214 | 217 | | |
215 | 218 | | |
216 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
217 | 236 | | |
218 | 237 | | |
219 | 238 | | |
220 | 239 | | |
221 | 240 | | |
222 | 241 | | |
223 | 242 | | |
224 | | - | |
| 243 | + | |
225 | 244 | | |
226 | 245 | | |
227 | 246 | | |
228 | 247 | | |
229 | | - | |
| 248 | + | |
230 | 249 | | |
231 | 250 | | |
232 | 251 | | |
| |||
261 | 280 | | |
262 | 281 | | |
263 | 282 | | |
264 | | - | |
| 283 | + | |
265 | 284 | | |
266 | 285 | | |
267 | 286 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 111 | + | |
| 112 | + | |
115 | 113 | | |
116 | 114 | | |
117 | 115 | | |
| |||
164 | 162 | | |
165 | 163 | | |
166 | 164 | | |
167 | | - | |
168 | 165 | | |
169 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
170 | 184 | | |
171 | 185 | | |
172 | 186 | | |
| |||
175 | 189 | | |
176 | 190 | | |
177 | 191 | | |
178 | | - | |
| 192 | + | |
179 | 193 | | |
180 | 194 | | |
181 | 195 | | |
182 | 196 | | |
183 | | - | |
| 197 | + | |
184 | 198 | | |
185 | 199 | | |
186 | 200 | | |
| |||
202 | 216 | | |
203 | 217 | | |
204 | 218 | | |
205 | | - | |
| 219 | + | |
206 | 220 | | |
207 | 221 | | |
208 | 222 | | |
209 | 223 | | |
210 | 224 | | |
211 | | - | |
212 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
213 | 231 | | |
214 | 232 | | |
215 | 233 | | |
216 | 234 | | |
217 | | - | |
218 | | - | |
219 | | - | |
| 235 | + | |
220 | 236 | | |
221 | 237 | | |
222 | 238 | | |
223 | 239 | | |
224 | | - | |
| 240 | + | |
225 | 241 | | |
226 | 242 | | |
227 | 243 | | |
| |||
241 | 257 | | |
242 | 258 | | |
243 | 259 | | |
244 | | - | |
| 260 | + | |
245 | 261 | | |
246 | 262 | | |
247 | 263 | | |
248 | 264 | | |
249 | 265 | | |
250 | | - | |
251 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
252 | 272 | | |
253 | 273 | | |
254 | 274 | | |
255 | 275 | | |
256 | | - | |
257 | | - | |
258 | | - | |
| 276 | + | |
259 | 277 | | |
260 | 278 | | |
261 | 279 | | |
262 | 280 | | |
263 | | - | |
| 281 | + | |
264 | 282 | | |
265 | 283 | | |
266 | 284 | | |
| |||
280 | 298 | | |
281 | 299 | | |
282 | 300 | | |
283 | | - | |
| 301 | + | |
284 | 302 | | |
285 | 303 | | |
286 | 304 | | |
| |||
0 commit comments