Repository navigation
Commit 1748c37
feat: verified query optimization via altimate_core_rewrite verify_equivalence mode (#918)
* feat: verified-optimize tool — surface only provably-equivalent query rewrites
Composes altimate_core.rewrite + altimate_core.equivalence into one gated
primitive: a rewrite is reported VERIFIED only when equivalence affirmatively
returns equivalent===true; everything else (incl. no-schema) is returned but
labeled 'review before applying'. The core mechanic for one-click verified
query optimization. 15 tests (gate logic + adversarial strict-true + real-engine).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* refactor: fold verified optimization into altimate_core_rewrite (verify_equivalence)
Addresses review feedback: a standalone `altimate_verified_optimize` tool
overlapped with `sql_optimize` and `altimate_core_rewrite`, risking agent
tool-selection confusion (three near-identical "optimize a query" tools).
Instead, verification is now a MODE of the existing rewrite tool:
- `altimate_core_rewrite` gains `verify_equivalence?: boolean` (default false →
existing behavior unchanged). When true, each proposed rewrite is checked
against the original via `altimate_core.equivalence`; only rewrites that
return strict `equivalent === true` are labeled verified-safe, the rest
"review before applying." Conservative gate (no truthy coercion), per-candidate
try/catch, array-guarded differences, null-guarded responses, and specific
unverified reasons (missing-field / non-boolean / not-equivalent).
- Remove the standalone `altimate_verified_optimize` tool + its registration.
- `query-optimize` skill now calls `altimate_core_rewrite` with
`verify_equivalence: true`, folding its old manual rewrite→equivalence steps
(3 + 6) into one verified call.
Tests (18) moved to `altimate-core-rewrite-verify.test.ts`, exercising the verify
mode: gate logic, adversarial strict-true (rejects "true"/1/{}/undefined/null +
missing-field/non-boolean reasons), partial-failure resilience, and a real-engine
integration test.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix: address review on verify_equivalence mode (coderabbit + multi-persona)
Two real findings on altimate-core-rewrite.ts (the current verify-mode file;
most other review comments targeted the now-deleted standalone tool):
- MAJOR (coderabbit): handle `success === false` explicitly. An
`{ success: false, error: "" }` rewrite payload has a falsy error string and
fell through to the success path, misreporting results. Now fails on an
explicit `success === false` regardless of error string.
- MINOR (coderabbit + multi-persona): dedup/no-op normalization lowercased the
full SQL, which could collapse rewrites differing only by a case-sensitive
string literal / quoted identifier into one — dropping a valid candidate before
verification. Normalize whitespace only; no case-folding.
Already-addressed findings (reviewers were looking at the deleted standalone
tool): per-candidate try/catch (equivalence throw fails closed per candidate, not
the whole tool) and strict boolean validation of `equivalent` (=== true + a
typeof-based "non-boolean" reason) are both present in the current code.
Tests (20): + success:false-with-empty-error regression, + case-sensitive-literal
dedup preservation.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 88b7f6f commit 1748c37
3 files changed
Lines changed: 465 additions & 16 deletions
File tree
- .opencode/skills/query-optimize
- packages/opencode
- src/altimate/tools
- test/altimate
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
12 | 19 | | |
13 | | - | |
| 20 | + | |
14 | 21 | | |
15 | | - | |
| 22 | + | |
16 | 23 | | |
17 | 24 | | |
18 | 25 | | |
19 | | - | |
20 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
21 | 41 | | |
22 | 42 | | |
23 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
24 | 49 | | |
25 | 50 | | |
26 | | - | |
| 51 | + | |
27 | 52 | | |
28 | 53 | | |
29 | 54 | | |
| |||
37 | 62 | | |
38 | 63 | | |
39 | 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 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
40 | 201 | | |
41 | 202 | | |
42 | 203 | | |
| |||
0 commit comments