5e72a803761f3d9c09f9da677d2b3c875c92c297
The previous loop burned all 8 hops re-running the same broken query
("operator does not exist: character varying = uuid") because (a) the
agent never saw PostgreSQL's HINT — only the bare error message — and
(b) the prompt's "retry once" rule was advisory, not enforced.
Backend (commands/chat.rs)
- New format_db_error helper. When the error is sqlx::Error::Database
with a PostgreSQL backend, downcast to PgDatabaseError and append
DETAIL and HINT lines. Common PG hints are exactly the spelled-out
fix the agent needs ("You might need to add explicit type casts").
- New last_run_query_error helper to fish the most recent failing SQL
text out of working history for the give-up message.
- Hard server-side guard: track consecutive_query_errors. On
consecutive run_query failures >= 2, force-emit a `final` message
that quotes the last error and suggests next steps (cast hints,
open the table in sidebar, switch to Advanced mode). The model
cannot loop past this regardless of how many hops remain.
- Counter resets to 0 when the model takes any non-RunQuery action
(get_columns, list_tables, etc.) — investigation buys a fresh
error budget.
- Stronger prompt RULES section: explicitly walks through three of
the most common PG error classes ("operator does not exist",
"column does not exist", "relation does not exist") and the
matching fixes. Tells the model the harness force-stops after 2
consecutive failures.
Tests (4 new): format_db_error fallback, last_run_query_error finds
most recent / handles empty / handles no-errors thread.
Verification: cargo test --lib 70 pass (+4), tsc clean, vitest 20
pass.
Description
No description provided
Languages
TypeScript
63.1%
Rust
33.5%
CSS
2.4%
Makefile
0.8%
JavaScript
0.1%