Commit 4ce1014
`sql_explain` and `altimate_core_validate` produced high failure rates and
unhelpful errors because their input validation did not match the parameter
contracts they advertised.
**`sql_explain`**
- Reject empty, whitespace-only, and placeholder-only SQL (`?`, `:var`, `$1`)
before hitting the warehouse. Verbatim driver errors like "SQL compilation
error: syntax error line 1 at position 8 unexpected ?." are unrecoverable
for LLM callers — catch the common cases early with actionable guidance.
- Reject empty / placeholder warehouse names (`?`, `:wh`, `""`) with a
pointer to `warehouse_list` rather than letting the Registry emit
"Connection ? not found. Available: (none)".
- Introduce `buildExplainPlan()` that returns `{prefix, actuallyAnalyzed}`
so the handler can pick dialect-correct syntax AND report the true plan
mode. Fixes the previous lie where Snowflake users who asked for ANALYZE
saw `analyzed: true` in metadata even though we silently sent plain
`EXPLAIN USING TEXT`.
- Warehouse coverage is now explicit: Snowflake (`EXPLAIN USING TEXT`),
PostgreSQL (`EXPLAIN (ANALYZE, BUFFERS)`), Redshift (plain `EXPLAIN` —
does NOT support ANALYZE), MySQL / MariaDB / DuckDB (`EXPLAIN ANALYZE`),
Databricks / Spark (`EXPLAIN FORMATTED`), ClickHouse (`EXPLAIN`).
BigQuery, Oracle, and SQL Server return an empty prefix and a clear
"not supported via statement prefix — this warehouse needs a different
plan mechanism" error instead of issuing a broken statement.
- New `translateExplainError()` helper rewrites common driver errors into
actionable messages: connection-not-found becomes "Available warehouses:
a, b, c", unsubstituted-`?` compile errors become "inline the literal
value", permission denials call out role grants, etc.
- Intentional non-change: we do NOT scan mid-query for stray `?` because
PostgreSQL JSONB uses `?`, `?|`, `?&` as legitimate operators. Only the
bare-placeholder check runs, which has no false positives.
**`altimate_core_validate`**
- Remove the hard-gate that returned "No schema provided..." before the
engine ran. The parameter schema already declared `schema_path` and
`schema_context` as optional, and the Rust core (`altimate-core`) has
accepted empty schemas for a long time via the existing `schemaOrEmpty`
helper — the hard-gate was gratuitous and every call without schema
failed identically with no recovery path.
- When schema is absent, the engine still runs so syntax / dialect findings
come through, and the tool surfaces a clear warning in the output and
`has_schema: false` in metadata so callers can distinguish full validation
from schema-less runs. Title becomes `Validate: VALID (no schema)` for
unambiguous signaling.
- Errors thrown by the engine are now classified as `error_class:
engine_failure` to keep them distinct from user-input problems.
**Tests**
- New `test/altimate/tools/sql-explain.test.ts`: input validation (empty,
placeholder, short), warehouse-name validation, full `buildExplainPlan`
matrix (including the Redshift / BigQuery / Oracle regressions above),
error translation paths, and Tool.execute integration with a mocked
dispatcher.
- New `test/altimate/tools/altimate-core-validate.test.ts`: schema
resolution (none / `schema_context` / `schema_path` / empty object),
validation error classification, output formatting, and a regression
guard asserting the dispatcher is called even when no schema is given.
- Updated `test/altimate/tool-error-propagation.test.ts` to reflect the
new contract: the validate tool now runs the engine without schema and
returns `success: true` with a warning, instead of early-returning an
error. The regression fixture keeps telemetry coverage.
Closes #691
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f030bf8 commit 4ce1014
6 files changed
Lines changed: 1070 additions & 37 deletions
File tree
- packages/opencode
- src/altimate
- native/connections
- tools
- test/altimate
- tools
Lines changed: 168 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
185 | 326 | | |
186 | 327 | | |
187 | 328 | | |
| |||
261 | 402 | | |
262 | 403 | | |
263 | 404 | | |
| 405 | + | |
| 406 | + | |
264 | 407 | | |
265 | | - | |
| 408 | + | |
266 | 409 | | |
267 | | - | |
268 | 410 | | |
269 | 411 | | |
270 | 412 | | |
| |||
276 | 418 | | |
277 | 419 | | |
278 | 420 | | |
| 421 | + | |
279 | 422 | | |
280 | 423 | | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
286 | 440 | | |
287 | 441 | | |
288 | 442 | | |
| |||
295 | 449 | | |
296 | 450 | | |
297 | 451 | | |
298 | | - | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
299 | 456 | | |
300 | 457 | | |
| 458 | + | |
301 | 459 | | |
302 | 460 | | |
303 | 461 | | |
304 | | - | |
| 462 | + | |
| 463 | + | |
305 | 464 | | |
306 | 465 | | |
307 | 466 | | |
| |||
Lines changed: 20 additions & 17 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 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | 16 | | |
27 | 17 | | |
28 | 18 | | |
| |||
38 | 28 | | |
39 | 29 | | |
40 | 30 | | |
41 | | - | |
| 31 | + | |
42 | 32 | | |
43 | 33 | | |
44 | 34 | | |
45 | 35 | | |
46 | 36 | | |
47 | 37 | | |
48 | 38 | | |
49 | | - | |
| 39 | + | |
50 | 40 | | |
51 | 41 | | |
52 | 42 | | |
53 | 43 | | |
54 | 44 | | |
55 | | - | |
| 45 | + | |
56 | 46 | | |
57 | 47 | | |
58 | 48 | | |
59 | 49 | | |
60 | 50 | | |
61 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
62 | 59 | | |
63 | 60 | | |
64 | 61 | | |
| |||
77 | 74 | | |
78 | 75 | | |
79 | 76 | | |
80 | | - | |
| 77 | + | |
81 | 78 | | |
82 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
| 91 | + | |
89 | 92 | | |
90 | 93 | | |
0 commit comments