Commit d3a93d7
authored
feat(databases-on-aws): add query-plan-explainability workflow to dsql skill (#141)
* feat(databases-on-aws): add query-plan-explainability workflow to dsql skill
Adds Workflow 8 to the dsql skill: a phased diagnostic pipeline that captures
an EXPLAIN ANALYZE VERBOSE plan, interrogates pg_class / pg_stats / pg_indexes
for cardinality and index evidence, optionally runs GUC experiments (gated on
execution time ≤30s), and produces a structured Markdown diagnostic report.
When the aurora-dsql MCP server is unavailable, the workflow falls back to
raw psql with a generated IAM token — multi-statement heredoc, exit-code
checked — supporting GUC experiments and BEGIN/ROLLBACK wrappers. Four
supporting references live under `references/query-plan/`
(plan-interpretation, catalog-queries, guc-experiments, report-format) so the
entry file stays under the 300-line guidance.
DML safety. Plan capture is exclusively `readonly_query`; write-mode
`transact` bypasses all MCP safety checks and is never used in Phase 1.
INSERT, pl/pgsql, DO blocks, and functions are rejected outright (no
meaningful plan). UPDATE and DELETE are rewritten to the equivalent SELECT
(same join chain + WHERE) before EXPLAIN — the optimizer picks the same
plan shape for the SELECT. The Experiment 2 GUC path still needs `transact`
(readonly_query blocks multi-statement), but caller-side guard rails
require the statement be verified-SELECT, passed as a single list element
(no string concat that could smuggle a second statement), and halt-on-error
without recovery chaining. SET LOCAL scopes GUC changes to the transaction.
Adds a functional eval harness under tools/evals/databases-on-aws/ with 5
prompts / 42 assertions, a Python runner driving claude -p via stream-json,
and an MCP warmup that retries once and aborts on repeated failure so evals
never run against a cold MCP. Tool-required assertions accept both MCP tool
calls and the psql fallback (Bash invoking psql against a DSQL endpoint).
Other assertions match against agent output text only to avoid false
positives from prompt echo. Per-eval diagnostic.json persists reference
loads, MCP calls, and malformed-JSON counts for post-hoc triage. Eval 4's
DML-recognition grader accepts DML → SELECT rewrite, INSERT rejection, or
the legacy ROLLBACK-wrapping form.
Also extends trigger_evals.json with three should-trigger explainability
queries and three should-not-trigger PostgreSQL/RDS/Redshift EXPLAIN variants
to confirm the skill stays DSQL-specific, and scopes the Bandit security
scan to skip ./.tmp and ./node_modules so per-developer scratch code under
.tmp/ doesn't break the build.
Co-authored-by: anwesham-lab <64298192+anwesham-lab@users.noreply.github.com>
* feat(databases-on-aws): harden Phase 1, add Phase 5 reassessment loop
Three related skill hardenings for Workflow 8 query-plan-explainability:
1. Phase 1 hardening. ALWAYS run readonly_query(EXPLAIN ANALYZE VERBOSE …) on
the user's query verbatim and capture a fresh plan from the cluster — even
when the user describes the plan or reports an anomaly, because findings
and the support template need real cluster data. Schema pre-checks via
get_schema / information_schema are permitted (MAY). When EXPLAIN errors
(relation does not exist, column does not exist), MUST report the error
verbatim; MUST NOT invent DSQL-specific semantics (e.g., case sensitivity,
identifier quoting) as the root cause. PostgreSQL/DSQL auto-lowercase
unquoted identifiers so "case sensitivity" is not a valid DSQL-specific
diagnosis in the first place. This preempts the class of failure where
the agent substitutes a plausible-sounding theory for evidence when a
diagnostic tool returns ambiguous empty results.
2. Workflow-opening reframe: "The structured Markdown diagnostic report is
the deliverable, not a conversational answer — run the workflow end-to-end
before answering." Fixes the pattern where the agent narrates causes in
prose instead of running the workflow.
3. Phase 5 — Reassess after change. Workflow now ends with a Next Steps block
inviting the user to signal "reassess" after applying any recommendation.
When they do, the agent re-runs Phase 1–2 and appends an "Addendum:
After-Change Performance" section (before/after comparison table with
match-vs-expected-impact verdict) to the original report rather than
producing a new one. Template for both lives in report-format.md so the
structure is enforced.
All normative statements use RFC 2119 keywords (MUST, MUST NOT, MAY) plus the
repo's ALWAYS convention.
Co-authored-by: anwesham-lab <64298192+anwesham-lab@users.noreply.github.com>
* feat(databases-on-aws): add outcome-oriented evals 6-9 + grader enhancements
Four new functional evals target outcome quality rather than workflow execution,
covering failure modes the existing 1-5 miss:
- Eval 6 (Phase 5 reassessment): agent re-runs EXPLAIN after the user applies
a recommendation, appends an Addendum to the prior report rather than
producing a fresh report, and compares observed improvement against the
originally stated Expected Impact.
- Eval 7 (mixed-case identifiers): SELECT FROM UserAccount resolves via PG
auto-lowercasing. Agent MUST NOT invent "DSQL is case-sensitive" as a root
cause. Guards against the real-user hallucination where get_schema returning
empty got fabricated into a DSQL-specific rule.
- Eval 8 (unknown table): agent surfaces relation does not exist verbatim,
does NOT fabricate a diagnostic report for a query it could not EXPLAIN.
- Eval 9 (stale pg_class.reltuples): real DSQL pattern where plan looks fine
but stats lag reality. Agent MUST query both pg_class and COUNT(*), detect
divergence, and recommend ANALYZE / note the auto-analyze schedule.
Three grader enhancements support the new assertions (ordered before the
fallback keyword matcher):
- Grader (b) — Expected Impact contains concrete numbers. Extracts the
Summary section, requires at least one x-factor, percentage, or ms/s value.
Rejects hedging prose ("should improve", "significant reduction").
- Grader (c) — Addendum appended, not fresh report. Counts top-level H1s
and requires Addendum header present. Fails when agent restarts with a
new Diagnostic Report title on reassessment.
- Grader (d) — No hallucinated DSQL-specific semantics. Regex blacklist
for "DSQL is case-sensitive", "you must lowercase", etc. Passes if paired
with an auto-lowercase correction.
README updated: 9 evals / 70 assertions, with per-eval summary table.
Co-authored-by: anwesham-lab <64298192+anwesham-lab@users.noreply.github.com>
* feat(databases-on-aws): grader enhancements + anti-hallucination framing on Expected Impact
Grader improvements for evals 6, 8, 9 — dedicated branches that were
previously hitting the 0.8-keyword fallback matcher:
- Before/after comparison table with numeric duration delta (eval 6)
- Comments explicitly on match vs Expected Impact (eval 6)
- Proposes next hypothesis on shortfall rather than declaring success (eval 6)
- Surfaces 'relation ... does not exist' verbatim (eval 8)
- Does NOT produce a fresh Diagnostic Report H1 for an un-EXPLAINable query (eval 8)
- Does NOT fabricate plan metrics / findings / row counts (eval 8)
- Asks user to confirm table / schema / cluster (eval 8)
- Names stale statistics as root cause (eval 9)
- Recommends ANALYZE or notes auto-analyze schedule (eval 9)
Grader (b) reframed from "must include numbers" to "must be evidence-grounded".
The old framing rewarded any number, which is directly hallucination-inducing
(same pathology as the case-sensitivity fabrication): forcing a concrete
prediction without evidence invites the agent to invent one. New framing
accepts either a numeric prediction OR an honest "cannot predict without X
evidence" admission. Plain hedging ("should improve performance") still fails.
Matching skill update in report-format.md: Expected impact is now instructed
to ground predictions in gathered evidence; when evidence is insufficient,
the agent MUST name the missing piece rather than fabricate a number.
Co-authored-by: anwesham-lab <64298192+anwesham-lab@users.noreply.github.com>1 parent bd83f9b commit d3a93d7
11 files changed
Lines changed: 2175 additions & 14 deletions
File tree
- plugins/databases-on-aws/skills/dsql
- references
- auth
- query-plan
- tools/evals/databases-on-aws
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
112 | 117 | | |
113 | 118 | | |
114 | 119 | | |
| |||
156 | 161 | | |
157 | 162 | | |
158 | 163 | | |
159 | | - | |
160 | | - | |
161 | 164 | | |
162 | 165 | | |
163 | 166 | | |
| |||
188 | 191 | | |
189 | 192 | | |
190 | 193 | | |
191 | | - | |
192 | | - | |
| 194 | + | |
193 | 195 | | |
194 | 196 | | |
195 | 197 | | |
| |||
250 | 252 | | |
251 | 253 | | |
252 | 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 | + | |
253 | 283 | | |
254 | 284 | | |
255 | 285 | | |
256 | 286 | | |
257 | | - | |
258 | 287 | | |
259 | 288 | | |
260 | 289 | | |
261 | | - | |
262 | | - | |
| 290 | + | |
263 | 291 | | |
264 | 292 | | |
265 | 293 | | |
| |||
268 | 296 | | |
269 | 297 | | |
270 | 298 | | |
271 | | - | |
272 | 299 | | |
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
Lines changed: 145 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 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 | + | |
| 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 | + | |
0 commit comments