Skip to content

feat(errors): structured error guidance for AI agents - #84

Merged
zx06 merged 6 commits into
mainfrom
cursor/error-guidance-for-agents-27de
Oct 10, 2026
Merged

zx06 merged 6 commits into
mainfrom
cursor/error-guidance-for-agents-27de

Conversation

@zx06

@zx06 zx06 commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds backward-compatible agent guidance to JSON/YAML error envelopes via error.details: hint, retryable, category, optional dialect, native_code, and native_code_kind. MySQL errno and PostgreSQL SQLSTATE map to stable categories (e.g. unknown_table, syntax_error, read_only_blocked, connection). Enrichment runs centrally in errors.New / errors.Wrap, so CLI, MCP, and Web share the same behavior without changing top-level code, exit codes, or schema_version (still 1).

Changes

  • RFC docs/rfcs/0016-error-guidance-for-agents.md and updates to docs/error-contract.md, docs/ai.md, and .agents/skills/xsql/SKILL.md
  • internal/errors: classification + enrichment (dbclassify.go, guidance.go)
  • internal/db/query.go: pass dialect on query failures; drivers tag connect errors with dialect
  • Unit tests for MySQL/PG mapping; integration tests (unknown table, syntax error, read-only block)

中文摘要

为 xsql 的错误 JSON 在 details 中自动补充 hint(下一步建议)、retryable(是否值得重试)、category(稳定语义分类)以及 MySQL/PostgreSQL 的 native_code,帮助 AI 在未知表、语法错误、连接失败、只读拦截等场景下少做无效重试。现有 error.code、退出码与 schema_version=1 不变,仅追加字段。

Testing

  • go build ./... / go vet ./...
  • go test ./...
  • go test -tags=e2e ./tests/e2e/...
  • go test -tags=integration ./tests/integration/... (MySQL 8.0 + PostgreSQL 16)
  • golangci-lint run ./...
Open in Web Open in Cursor 

cursoragent and others added 2 commits October 10, 2026 06:13
Enrich XError details with hint, retryable, category, and native DB
codes for MySQL/PostgreSQL. Document the contract, add RFC 0015, and
cover mapping with unit and integration tests.

Co-authored-by: x_zhuo <zx06@users.noreply.github.com>
Co-authored-by: x_zhuo <zx06@users.noreply.github.com>
@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.82474% with 55 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.43%. Comparing base (b9b8022) to head (b316d0e).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
internal/errors/dbclassify.go 85.58% 27 Missing and 5 partials ⚠️
internal/errors/guidance.go 85.51% 17 Missing and 4 partials ⚠️
internal/db/mysql/driver.go 50.00% 1 Missing ⚠️
internal/db/pg/driver.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #84      +/-   ##
==========================================
+ Coverage   84.32%   84.43%   +0.10%     
==========================================
  Files          67       69       +2     
  Lines        6367     6744     +377     
==========================================
+ Hits         5369     5694     +325     
- Misses        723      767      +44     
- Partials      275      283       +8     
Flag Coverage Δ
e2e 28.67% <39.94%> (+1.02%) ⬆️
integration 28.67% <39.94%> (+1.02%) ⬆️
unittests 78.02% <85.30%> (+0.42%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

cursoragent and others added 4 commits October 10, 2026 06:26
Co-authored-by: x_zhuo <zx06@users.noreply.github.com>
Co-authored-by: x_zhuo <zx06@users.noreply.github.com>
- Split MySQL 1045 and PG 28P01/28000 into auth_failed with keyring hint
- Map no_keyword and similar static RO reasons to unrecognized_statement
- Centralize hint strings; expand dbclassify unit tests and table-driven integration

Co-authored-by: x_zhuo <zx06@users.noreply.github.com>
Co-authored-by: x_zhuo <zx06@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

@zx06
zx06 marked this pull request as ready for review October 10, 2026 06:52
@zx06
zx06 merged commit a8ebb78 into main Oct 10, 2026
14 checks passed
cursor Bot pushed a commit that referenced this pull request Oct 10, 2026
Resolve merge conflicts (RFC 0015–0017, query executeQuery+dbType).
Reuse HintQueryResultTruncated from internal/errors after PR #84.

Co-authored-by: x_zhuo <zx06@users.noreply.github.com>
@zx06
zx06 deleted the cursor/error-guidance-for-agents-27de branch October 20, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants