Skip to content

Commit 2a1c5ac

Browse files
Merge branch 'main' into fix/datamate-stdio-local-transport
2 parents c2a5541 + fd9d7c7 commit 2a1c5ac

30 files changed

Lines changed: 2219 additions & 98 deletions

‎.opencode/skills/query-optimize/SKILL.md‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: Analyze and optimize SQL queries for better performance
77

88
## Requirements
99
**Agent:** any (read-only analysis)
10-
**Tools used:** sql_optimize, sql_analyze, sql_explain, altimate_core_equivalence, read, glob, schema_inspect, warehouse_list
10+
**Tools used:** altimate_core_rewrite (with `verify_equivalence: true`), sql_analyze, sql_explain, read, glob, schema_inspect, warehouse_list
1111

1212
Analyze SQL queries for performance issues and suggest concrete optimizations including rewritten SQL.
1313

@@ -20,9 +20,9 @@ Analyze SQL queries for performance issues and suggest concrete optimizations in
2020

2121
2. **Determine the dialect** -- Default to `snowflake`. If the user specifies a dialect (postgres, bigquery, duckdb, etc.), use that instead. Check the project for warehouse connections using `warehouse_list` if unsure.
2222

23-
3. **Run the optimizer**:
24-
- Call `sql_optimize` with the SQL, dialect, and schema context if available
25-
- If the user has a warehouse connection, first call `schema_inspect` on the relevant tables to build schema context for better optimization (e.g., SELECT * expansion)
23+
3. **Run the verified optimizer**:
24+
- If the user has a warehouse connection, first call `schema_inspect` on the relevant tables to build schema context (needed both for better rewrites — e.g. SELECT * expansion — and to verify equivalence)
25+
- Call `altimate_core_rewrite` with the SQL, schema context, and **`verify_equivalence: true`**. This proposes rewrites AND proves each one returns the same results as the original in a single step. The result is partitioned into **verified-equivalent** rewrites (safe to apply) and **unverified** rewrites (review before applying), so you never recommend a rewrite that silently changes semantics.
2626

2727
4. **Run detailed analysis**:
2828
- Call `sql_analyze` with the same SQL and dialect to get the full anti-pattern breakdown with recommendations
@@ -32,10 +32,10 @@ Analyze SQL queries for performance issues and suggest concrete optimizations in
3232
- Look for: full table scans, sort operations on large datasets, inefficient join strategies, missing partition pruning
3333
- Include key findings in the report under "Execution Plan Insights"
3434

35-
6. **Verify rewrites preserve correctness**:
36-
- If `sql_optimize` produced a rewritten query, call `altimate_core_equivalence` to verify the original and optimized queries produce the same result set
37-
- If not equivalent, flag the difference and present both versions for the user to decide
38-
- This prevents "optimization" that silently changes query semantics
35+
6. **Equivalence verification is built into step 3** (`verify_equivalence: true`):
36+
- Present the **verified-equivalent** rewrites as safe to apply.
37+
- Present **unverified** rewrites separately with their reason ("review before applying") — do not recommend applying these without manual review.
38+
- If no schema was available, all rewrites come back unverified; say so and recommend supplying a schema (or a warehouse connection) to enable verification.
3939

4040
7. **Present findings** in a structured format:
4141

@@ -83,4 +83,4 @@ The user invokes this skill with SQL or a file path:
8383
- `/query-optimize models/staging/stg_orders.sql` -- Optimize SQL from a file
8484
- `/query-optimize` -- Optimize the most recently discussed SQL in the conversation
8585

86-
Use the tools: `sql_optimize`, `sql_analyze`, `sql_explain` (execution plans), `altimate_core_equivalence` (rewrite verification), `read` (for file-based SQL), `glob` (to find SQL files), `schema_inspect` (for schema context), `warehouse_list` (to check connections).
86+
Use the tools: `altimate_core_rewrite` with `verify_equivalence: true` (proposes rewrites AND proves they preserve results in one step), `sql_analyze`, `sql_explain` (execution plans), `read` (for file-based SQL), `glob` (to find SQL files), `schema_inspect` (for schema context), `warehouse_list` (to check connections).

‎CHANGELOG.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.8.7] - 2026-06-10
9+
10+
### Added
11+
12+
- **Verified query optimization — `altimate_core_rewrite` now proves a rewrite is safe before suggesting it.** A new `verify_equivalence` mode composes the rewrite engine with the equivalence checker: a candidate rewrite is labeled **VERIFIED** only when the engine affirmatively returns `equivalent === true`; everything else (including the no-schema case) is still returned but labeled "review before applying." This is the gated core for one-click verified query optimization, so an optimization that silently changes results is never presented as safe. (#918)
13+
- **Per-turn tool retrieval trims the tool-definition context flood.** Three flag-gated, default-off agent-loop reliability features: a per-turn tool subset (always-on core tools + lexical top-k, never dropping a tool referenced mid-trajectory) that cuts the ~78-tool definition payload sent each turn; grammar/JSON-Schema constrained decoding for local models (vLLM/LM Studio/llama.cpp); and a pluggable pre-execution critic gate for side-effecting tools. All default off, so the existing agent path is unchanged unless explicitly enabled. (#858)
14+
15+
### Changed
16+
17+
- **Upgraded the SQL engine `@altimateai/altimate-core` `0.4.0` → `0.5.1` and wired its new equivalence capabilities into the dbt PR reviewer.** The reviewer now forwards the project's SQL **dialect** hint to the equivalence engine, so dialect-specific compiled warehouse SQL (e.g. Snowflake semi-structured `col:field`) parses and the comparison is decided instead of abstaining on a syntax error, and it honors the engine's new authoritative **`decidable`** flag — abstaining when the engine itself says it could not decide, rather than guessing. An empty/auto-detect dialect is coerced to "no hint" so the engine is never handed an unknown dialect. (#925, #928)
18+
19+
### Fixed
20+
21+
- **The dbt PR reviewer is more reliable and less noisy.** Demo-parity hardening: tighter PII-review precision, reduced safe-refactor review noise, schema YAML catalog rules now run in review, and added DuckDB data-diff end-to-end coverage. (#919)
22+
- **dbt review no longer misclassifies YAML files.** Schema/property YAML files are classified correctly so the right rules apply to them. (#920)
23+
- **The `release-v0.8.5` adversarial test gate is pinned to a constant version** so it stops breaking on every subsequent release. (#923)
24+
25+
### Internal
26+
27+
- **Centralized code-review dispatch on PR ready.** A gated loop dispatches a centralized OCR/Gemini review when a pull request is marked ready for review. (#914)
28+
829
## [0.8.6] - 2026-06-08
930

1031
### Added

‎bun.lock‎

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/docs/configure/tools/config.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,21 @@ When [LSP servers](../lsp.md) are configured, the `lsp` tool provides:
5252
- Go-to-definition
5353
- Hover information
5454
- Completions
55+
56+
### Tool Retrieval
57+
58+
With the full data-engineering toolset (~78 tools), sending every tool definition on every turn floods the context window and adds distractors that hurt the model's tool selection. **Tool retrieval** trims the exposed set per turn to a relevant subset, cutting input tokens substantially at the same task quality.
59+
60+
It is **off by default** and enabled with an environment variable:
61+
62+
```bash
63+
ALTIMATE_TOOL_RETRIEVAL=1 altimate-code run "..."
64+
```
65+
66+
When enabled, each turn exposes:
67+
68+
- an always-on **core** set of essentials that are never trimmed (`bash`, `read`, `write`, `edit`, `glob`, `grep`, `list`, `task`, `todowrite`, `skill`),
69+
- any tool already **referenced by an in-flight tool call** (so a mid-trajectory tool is never dropped), and
70+
- the highest-scoring remaining tools by a deterministic lexical match against the turn's request, up to a fixed budget.
71+
72+
Selection is deterministic and dependency-free; small tool sets are left untouched (nothing to gain). In internal benchmarks this cut input tokens by ~50% at an identical task-resolution rate.

‎packages/drivers/src/duckdb.ts‎

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,57 @@ export async function connect(config: ConnectionConfig): Promise<Connector> {
5656
new Promise<any>((resolve, reject) => {
5757
let resolved = false
5858
let timeout: ReturnType<typeof setTimeout> | undefined
59+
let instance: any
60+
// Sentinel for an open callback that fired synchronously (before
61+
// `instance` was assigned): `undefined` = not yet fired, `null` =
62+
// fired with success, `Error` = fired with failure. Replayed once
63+
// `instance` exists.
64+
let pendingOpen: Error | null | undefined
5965
const opts = accessMode ? { access_mode: accessMode } : undefined
60-
const instance = new duckdb.Database(
61-
dbPath,
62-
opts,
63-
(err: Error | null) => {
64-
if (resolved) { if (instance && typeof instance.close === "function") instance.close(); return }
65-
resolved = true
66-
if (timeout) clearTimeout(timeout)
67-
if (err) {
68-
const msg = err.message || String(err)
69-
if (msg.toLowerCase().includes("locked") || msg.includes("SQLITE_BUSY") || msg.includes("DUCKDB_LOCKED")) {
70-
reject(new Error("DUCKDB_LOCKED"))
71-
} else {
72-
reject(err)
73-
}
66+
const closeQuietly = () => {
67+
try {
68+
if (instance && typeof instance.close === "function") instance.close()
69+
} catch {
70+
// best-effort cleanup of a half-open handle
71+
}
72+
}
73+
const onOpen = (err: Error | null) => {
74+
if (!instance) {
75+
pendingOpen = err
76+
return
77+
}
78+
if (resolved) {
79+
closeQuietly()
80+
return
81+
}
82+
resolved = true
83+
if (timeout) clearTimeout(timeout)
84+
if (err) {
85+
// Open failed — release the half-open handle so it doesn't leak.
86+
closeQuietly()
87+
const msg = err.message || String(err)
88+
if (msg.toLowerCase().includes("locked") || msg.includes("SQLITE_BUSY") || msg.includes("DUCKDB_LOCKED")) {
89+
reject(new Error("DUCKDB_LOCKED"))
7490
} else {
75-
resolve(instance)
91+
reject(err)
7692
}
77-
},
78-
)
79-
// Bun: native callback may not fire; fall back after 2s
93+
} else {
94+
resolve(instance)
95+
}
96+
}
97+
instance = opts
98+
? new duckdb.Database(dbPath, opts, onOpen)
99+
: new duckdb.Database(dbPath, onOpen)
100+
// Bun: native callback may not fire; fall back after 2s. Arm the timer
101+
// BEFORE replaying a synchronous callback so a sync resolve/reject can
102+
// actually clear it (otherwise it lingers ~2s and delays process exit).
80103
timeout = setTimeout(() => {
81104
if (!resolved) {
82105
resolved = true
83106
reject(new Error(`Timed out opening DuckDB database "${dbPath}"`))
84107
}
85108
}, 2000)
109+
if (pendingOpen !== undefined) onOpen(pendingOpen)
86110
})
87111

88112
try {

0 commit comments

Comments
 (0)