Commit 1ca5618
fix: BigQuery finops UX — surface bq_region, actionable errors, warehouse_add warning
Partial resolution of #754, focused on the four BigQuery UX/visibility items
that naturally cluster. Three behavioural deferrals (#5 throw-on-invalid,
#6 options-object refactor, #7 e2e silent-skip) remain open in #754.
## Changes
1. `bq_region` surfaced in every BigQuery finops tool response.
`QueryHistoryResult`, `CreditAnalysisResult`, `ExpensiveQueriesResult`,
`WarehouseAdvisorResult`, `UnusedResourcesResult`, and `RoleGrantsResult`
gain an optional `bq_region?: string` field. All five finops modules
compute `sanitisedBqRegion = sanitizeBqRegion(bqRegion)` once at entry
and thread it through success and error returns. Non-BigQuery warehouses
omit the field. Lets the agent (and humans inspecting tool output) see
which region was actually queried after the silent `us` fallback shipped
in v0.6.1 (#739).
2. `augmentBqError(error, region)` helper in `bq-utils.ts`.
Appends a region hint to BigQuery errors that look region-related,
anchored to `region-<x>.INFORMATION_SCHEMA` references and "Not found"
lines so unrelated text (`region-based routing`, `multi-region-aware`)
does not trigger. Idempotent — safe under nested catch wrapping.
Wired into all five finops `catch` blocks.
3. `isBqPermissionError(error)` helper in `bq-utils.ts`.
Detects the `INFORMATION_SCHEMA.TABLE_STORAGE` 403 pattern that
`finops_unused_resources` hits routinely on project-scoped service
accounts. Word-boundary `\b403\b` check so `4031`, `40322`, `port 4030`
do not false-positive. `unused-resources.ts` produces an actionable
message naming `bigquery.resourceAdmin` (org-level requirement) when
this fires.
4. `warehouse_add` non-fatal warning when a BigQuery connection is
registered without a `location` field. Catches whitespace-only values
too — `sanitizeBqRegion` trims at query time and falls back to "us",
so `location: " "` would otherwise pass a truthy-only guard but
silently query the wrong region.
## Review notes
Reviewed via `/consensus:code-review` with eight external models
(GPT 5.4, Gemini 3.1 Pro, Kimi K2.5, MiniMax M2.7, GLM-5, Qwen 3.6 Plus,
DeepSeek V3.2, MiMo-V2-Pro) plus Claude. 7 of 8 converged in round 1;
Qwen's CLI did not return in time. Convergence corrected three accuracy
issues from the initial draft:
- Original draft claimed `includes("accessdenied")` was redundant after
`.toLowerCase()`. MiniMax retracted this on second look — Google's
BigQuery SDKs emit `AccessDenied` (camelCase), which lowercases to
`accessdenied` (no space) and would not be caught by the
`access denied` substring check. Both checks are kept.
- Original draft attributed dead `?? "us"` to two locations. Verified by
grep — only `unused-resources.ts:212` had it. Single fix applied.
- Original draft listed several BigQuery `location` aliases
(`Location`, `projectLocation`, `locationId`) as "auto-normalized" but
`BIGQUERY_ALIASES` in `packages/drivers/src/normalize.ts` does not
include any `location` alias. The check on `args.config.location` is
correct for current aliases. The remaining real concern (whitespace
trim) was downgraded and addressed.
## Tests
8 new tests in `finops-bq-visibility.test.ts` for the convergence-driven
guards: `region-based routing`, `multi-region-aware`, bare `region-`,
canonical INFORMATION_SCHEMA shapes, numeric-prefix `403` negative cases,
canonical 403 surfaces, whitespace-only and null `location` warnings.
30/30 in this file pass; full altimate + skill suite 3236/3236.
Verified:
- `bun turbo typecheck`: 5/5 green
- `bun run script/upstream/analyze.ts --markers --base main --strict`: clean
- 3236 pass / 491 skipped (env-gated) / 0 fail across altimate + skill
Closes #755
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 941c8ca commit 1ca5618
9 files changed
Lines changed: 563 additions & 13 deletions
File tree
- packages/opencode
- src/altimate
- native
- finops
- tools
- test/altimate
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| 309 | + | |
309 | 310 | | |
310 | 311 | | |
311 | 312 | | |
| |||
319 | 320 | | |
320 | 321 | | |
321 | 322 | | |
| 323 | + | |
322 | 324 | | |
323 | 325 | | |
324 | 326 | | |
| |||
339 | 341 | | |
340 | 342 | | |
341 | 343 | | |
| 344 | + | |
342 | 345 | | |
343 | 346 | | |
344 | 347 | | |
| |||
348 | 351 | | |
349 | 352 | | |
350 | 353 | | |
351 | | - | |
| 354 | + | |
| 355 | + | |
352 | 356 | | |
353 | 357 | | |
354 | 358 | | |
| |||
358 | 362 | | |
359 | 363 | | |
360 | 364 | | |
| 365 | + | |
361 | 366 | | |
362 | 367 | | |
363 | 368 | | |
| |||
367 | 372 | | |
368 | 373 | | |
369 | 374 | | |
| 375 | + | |
370 | 376 | | |
371 | 377 | | |
372 | 378 | | |
| |||
380 | 386 | | |
381 | 387 | | |
382 | 388 | | |
| 389 | + | |
383 | 390 | | |
384 | 391 | | |
385 | 392 | | |
386 | 393 | | |
387 | 394 | | |
388 | 395 | | |
389 | 396 | | |
390 | | - | |
| 397 | + | |
| 398 | + | |
391 | 399 | | |
392 | 400 | | |
393 | 401 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| 217 | + | |
217 | 218 | | |
218 | 219 | | |
219 | 220 | | |
| |||
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
| 226 | + | |
225 | 227 | | |
226 | 228 | | |
227 | 229 | | |
| |||
255 | 257 | | |
256 | 258 | | |
257 | 259 | | |
| 260 | + | |
258 | 261 | | |
259 | 262 | | |
260 | 263 | | |
261 | 264 | | |
262 | 265 | | |
263 | 266 | | |
264 | | - | |
| 267 | + | |
| 268 | + | |
265 | 269 | | |
266 | 270 | | |
267 | 271 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
| |||
176 | 177 | | |
177 | 178 | | |
178 | 179 | | |
| 180 | + | |
179 | 181 | | |
180 | 182 | | |
181 | 183 | | |
| |||
195 | 197 | | |
196 | 198 | | |
197 | 199 | | |
| 200 | + | |
198 | 201 | | |
199 | 202 | | |
200 | 203 | | |
201 | 204 | | |
202 | 205 | | |
203 | 206 | | |
204 | 207 | | |
205 | | - | |
| 208 | + | |
| 209 | + | |
206 | 210 | | |
207 | 211 | | |
208 | 212 | | |
| |||
Lines changed: 25 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
9 | 15 | | |
10 | 16 | | |
11 | 17 | | |
| |||
145 | 151 | | |
146 | 152 | | |
147 | 153 | | |
| 154 | + | |
| 155 | + | |
148 | 156 | | |
149 | 157 | | |
150 | 158 | | |
| |||
187 | 195 | | |
188 | 196 | | |
189 | 197 | | |
190 | | - | |
| 198 | + | |
191 | 199 | | |
192 | 200 | | |
193 | 201 | | |
194 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
195 | 214 | | |
196 | 215 | | |
197 | 216 | | |
| |||
220 | 239 | | |
221 | 240 | | |
222 | 241 | | |
| 242 | + | |
223 | 243 | | |
224 | 244 | | |
225 | 245 | | |
| |||
228 | 248 | | |
229 | 249 | | |
230 | 250 | | |
231 | | - | |
| 251 | + | |
| 252 | + | |
232 | 253 | | |
233 | 254 | | |
234 | 255 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| 226 | + | |
226 | 227 | | |
227 | 228 | | |
228 | 229 | | |
| |||
235 | 236 | | |
236 | 237 | | |
237 | 238 | | |
| 239 | + | |
238 | 240 | | |
239 | 241 | | |
240 | 242 | | |
| |||
276 | 278 | | |
277 | 279 | | |
278 | 280 | | |
| 281 | + | |
279 | 282 | | |
280 | 283 | | |
281 | 284 | | |
| |||
284 | 287 | | |
285 | 288 | | |
286 | 289 | | |
287 | | - | |
| 290 | + | |
| 291 | + | |
288 | 292 | | |
289 | 293 | | |
290 | 294 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
| 537 | + | |
| 538 | + | |
537 | 539 | | |
538 | 540 | | |
539 | 541 | | |
| |||
553 | 555 | | |
554 | 556 | | |
555 | 557 | | |
| 558 | + | |
| 559 | + | |
556 | 560 | | |
557 | 561 | | |
558 | 562 | | |
| |||
569 | 573 | | |
570 | 574 | | |
571 | 575 | | |
| 576 | + | |
| 577 | + | |
572 | 578 | | |
573 | 579 | | |
574 | 580 | | |
| |||
585 | 591 | | |
586 | 592 | | |
587 | 593 | | |
| 594 | + | |
| 595 | + | |
588 | 596 | | |
589 | 597 | | |
590 | 598 | | |
| |||
602 | 610 | | |
603 | 611 | | |
604 | 612 | | |
| 613 | + | |
| 614 | + | |
605 | 615 | | |
606 | 616 | | |
607 | 617 | | |
| |||
619 | 629 | | |
620 | 630 | | |
621 | 631 | | |
| 632 | + | |
| 633 | + | |
622 | 634 | | |
623 | 635 | | |
624 | 636 | | |
| |||
0 commit comments