Skip to content

feat(editor): add "Fix with AI" button to query errors - #1327

Merged
debba merged 4 commits into
TabularisDB:mainfrom
Asymtode712:feat/fix-with-ai-button
Nov 13, 2026
Merged

debba merged 4 commits into
TabularisDB:mainfrom
Asymtode712:feat/fix-with-ai-button

Conversation

@Asymtode712

@Asymtode712 Asymtode712 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a "Fix with AI" button next to query errors in the editor results area. It opens the existing AI query dialog prefilled with a prompt containing the failed SQL and the error message. The user can review and edit the prompt, then generate a corrected query. The generated SQL is inserted into the editor and is never run automatically.

Closes #1305

Changes

  • utils/aiFixPrompt.ts: buildFixQueryPrompt(sql, error) builds Fix this query. It failed with: <error>\n\n<sql>. Only the brief error message is used; details after the first blank line (stack traces etc.) are dropped.
  • ErrorDisplay.tsx: new optional onFixWithAi prop that renders the button. Other callers are unchanged.
  • AiQueryModal.tsx: new optional initialPrompt prop. The prompt is applied each time the dialog opens and cleared after a successful fix, so a later "Generate" doesn't show stale text.
  • Editor.tsx: the button is shown only when settings.aiEnabled, there is an active connection and the query is non-empty (same availability rule as the AI generate action). In fix mode, onInsert only updates the editor and skips runQuery. The regular AI generate flow still runs the query as before.
  • Locales: editor.fixWithAi added to all locales.
  • No new backend command; existing generate_ai_query is reused.

Tests

  • tests/utils/aiFixPrompt.test.ts: prompt format, error details dropped, whitespace trimmed.
  • tests/components/ui/ErrorDisplay.test.tsx: button hidden without a handler; handler called on click.

Manual testing

  1. Enable AI in Settings and connect to a database.
  2. Run SELECT nme FROM users. The error shows a "Fix with AI" button next to Copy.
  3. Click it. The dialog opens with the prefilled prompt. Edit it, then generate.
  4. Confirm the corrected SQL replaces the editor text and is not executed.
  5. Open "Generate" from the AI dropdown. The prompt is empty, and the result still runs as before.
  6. Disable AI, or use a tab without a connection. The button does not appear.

Notes

The failed SQL is taken from the tab's editor text, so if only a selection was run, the prompt contains the whole editor text.

@kilo-code-bot

kilo-code-bot Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Incremental review of 61b9259..cfe8a81. The new commit ("clear cancelled Fix with AI prompt on Generate; add vi and zh-TW keys") is correct:

  • AiQueryModal.tsx: promptIsFixDraft clears a cancelled fix prompt when the modal is reopened through plain Generate. It leaves ordinary drafts alone, and it resets after a successful insert.
  • The new test covers both cases: the cancelled fix prompt is cleared, and an ordinary draft is kept.
  • vi.json and zh-TW.json now have the editor.fixWithAi key, so all locales are covered.

The earlier checks still hold: both Generate entry points reset aiFixPrompt, and the fix path only inserts the SQL without running it.

Files Reviewed (4 files)
  • packages/web-ui/src/components/modals/AiQueryModal.tsx
  • packages/web-ui/tests/components/modals/AiQueryModal.test.tsx
  • packages/web-ui/src/i18n/locales/vi.json
  • packages/web-ui/src/i18n/locales/zh-TW.json

Note: the raw git diff from the previous commit to HEAD is very large because the branch was rebased onto a newer base. I reviewed the PR's own diff from gh pr diff instead.

Previous Review Summaries (3 snapshots, latest commit 61b9259)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 61b9259)

Status: No Issues Found | Recommendation: Merge

No changes since the last review (HEAD 61b9259, empty incremental diff against e899df8). I re-verified the current code: the set_window_title reference in docs/web/web-ui-parity.json points to Editor.tsx:736, which is the invoke('set_window_title', ...) call. Both "AI generate" entry points reset aiFixPrompt, and the fix path only inserts the SQL without auto-running it. No issues were found.

Files Reviewed (18 files)
  • packages/web-ui/src/components/modals/AiQueryModal.tsx
  • packages/web-ui/src/components/ui/ErrorDisplay.tsx
  • packages/web-ui/src/pages/Editor.tsx
  • packages/web-ui/src/utils/aiFixPrompt.ts
  • packages/web-ui/tests/components/ui/ErrorDisplay.test.tsx
  • packages/web-ui/tests/utils/aiFixPrompt.test.ts
  • packages/web-ui/src/i18n/locales/{de,en,es,fr,it,ja,ko,pt-BR,ru,tl,zh}.json
  • docs/web/web-ui-parity.json

Previous review (commit e899df8)

Status: No Issues Found | Recommendation: Merge

The only change since the last review is docs/web/web-ui-parity.json, where the set_window_title call-site line in Editor.tsx moves from 734 to 736. I confirmed line 736 is the invoke('set_window_title', ...) call, so the reference is correct. No new issues were found, and the earlier review found none.

Files Reviewed (18 files)
  • packages/web-ui/src/components/modals/AiQueryModal.tsx
  • packages/web-ui/src/components/ui/ErrorDisplay.tsx
  • packages/web-ui/src/pages/Editor.tsx
  • packages/web-ui/src/utils/aiFixPrompt.ts
  • packages/web-ui/tests/components/ui/ErrorDisplay.test.tsx
  • packages/web-ui/tests/utils/aiFixPrompt.test.ts
  • packages/web-ui/src/i18n/locales/{de,en,es,fr,it,ja,ko,pt-BR,ru,tl,zh}.json
  • docs/web/web-ui-parity.json

Previous review (commit cf778ad)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (17 files)
  • packages/web-ui/src/components/modals/AiQueryModal.tsx
  • packages/web-ui/src/components/ui/ErrorDisplay.tsx
  • packages/web-ui/src/pages/Editor.tsx
  • packages/web-ui/src/utils/aiFixPrompt.ts
  • packages/web-ui/tests/components/ui/ErrorDisplay.test.tsx
  • packages/web-ui/tests/utils/aiFixPrompt.test.ts
  • packages/web-ui/src/i18n/locales/{de,en,es,fr,it,ja,ko,pt-BR,ru,tl,zh}.json

Reviewed by claude-sonnet-5.5 · Input: 256 · Output: 1.7K · Cached: 312.5K

Review guidance: REVIEW.md from base branch main

@Asymtode712
Asymtode712 force-pushed the feat/fix-with-ai-button branch from e899df8 to 61b9259 Compare October 28, 2026 11:54

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work on connecting query errors to a Fix with AI action. We are evaluating moving AI assistant integrations into plugins, so I am holding off on reviewing and merging AI assistant changes for now. The draft with that work is #1337.

1-DARK
1-DARK previously requested changes Nov 11, 2026

@1-DARK 1-DARK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clean implementation! This follows the issue's pointers closely - the helper lives in utils/ with mirrored tests, the prefill uses the adjust-state-during-render pattern rather than an effect, and I verified all acceptance criteria of #1305 on your branch: new tests pass (8/8),the full web-ui suite passes (7669 tests), and pnpm lint / pnpm typecheck are clean.

Two things are needed before merge:

  1. Rebase / merge conflict: main removed the web UI API inventory in #1342, deleting docs/web/web-ui-parity.json. Since this PR modifies that file,GitHub reports it as conflicting. Please rebase onto current main and drop the web-ui-parity.json hunk entirely.
  2. Missing locale key: vi.json is missing editor.fixWithAi (the other 11 locales have it), so Vietnamese would fall back to English. Please add it next to showErrorDetails (~line 1677).

One optional suggestion (not blocking, and not a reachable bug today): aiFixPrompt in Editor.tsx is only reset by the two "Generate" entry points, never on close. Resetting it in onClose would make fix mode less fragile if a new open path is added later, and would also avoid a cancelled fix leaving its prompt as the modal's draft the next time "Generate" is opened.

@NewtTheWolf

Copy link
Copy Markdown
Collaborator

The architecture hold now has a concrete interface: #1337 is merged, with built-in providers and installable declarative AI assistants. The existing typed generate_ai_query request remains the entry point; provider selection, credentials and HTTP dispatch stay in the host.

Please update this branch against current main and keep Fix with AI on that shared client path, using the selected provider/model and the relevant schema context rather than adding provider-specific dispatch. The new package guide is https://github.com/TabularisDB/tabularis/blob/main/plugins/ai-assistants/README.md . I have not revalidated this older UI revision against the merged runtime, so this status update is not a merge approval. The previous wait for the AI interface itself is over.

@NewtTheWolf

Copy link
Copy Markdown
Collaborator

A follow-up on the AI runtime/registry prerequisites: Tabularium #35 is now merged and the ai-assistant kind is live. The published Gemini 1.0.2 example declares min_runtime_version: "0.32.1-4" and is approved in the registry. It provides a concrete packaging and compatibility example for the interface from #1337. That floor still requires a compatible runtime build; it does not make older published nightlies compatible.

The eight existing providers remain embedded in the app, so the earlier replacement-package rollout is unnecessary. The remaining code work can use the current provider/context interfaces on main and the independent external-package flow where applicable.

…tton

# Conflicts:
#	docs/web/web-ui-parity.json
@Asymtode712

Copy link
Copy Markdown
Contributor Author

@NewtTheWolf @debba Can you please review this PR now

@Asymtode712
Asymtode712 requested a review from debba November 13, 2026 06:58

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 929ea7ed50fce87f820e9f8505c2c275d6908015. The architecture hold is resolved: Fix with AI uses the existing typed generate_ai_query client call, selected provider/model and schema context. The removed web API inventory is no longer in the diff. Two issues still need correction before merge:

  1. P2 — A cancelled fix leaks into ordinary Generate. In AiQueryModal.tsx:49-53, reopening only resets prompt when initialPrompt is defined. Reproduce: open Fix with AI, cancel/close it, then open ordinary Generate from the dropdown or command. Editor clears aiFixPrompt to null, but the persistent modal still shows the previous fix prompt because its new initialPrompt is undefined. Submitting this stale prompt now also takes the ordinary Generate path (Editor.tsx:6950-6955), which calls runQuery, rather than the insert-only fix path. Please clear/separate the fix draft on the transition back to ordinary Generate while preserving the intended ordinary draft behavior, and add a cancel/reopen regression. I reproduced this with a temporary component regression test using the same close/reopen props as Editor: expected an empty ordinary prompt, received the cancelled fix prompt. This is reachable with the current UI, not only a possible future entry point.

  2. P2 — Missing locale keys. editor.fixWithAi is absent in both packages/web-ui/src/i18n/locales/vi.json and zh-TW.json. The earlier Vietnamese locale finding is still outstanding, and Traditional Chinese is missing too. Please add the key to both, as required by the issue/repository rules.

The existing focused tests pass: 13 tests across aiFixPrompt, ErrorDisplay and AiQueryModal. The added temporary reproduction fails as described and was removed after verification. Typecheck/lint results are recorded below. GitNexus impact analysis remains unavailable because this checkout's copied index points to another directory; I traced the affected paths directly (the shared AI modal, Editor Generate/Fix actions and ErrorDisplay callers). No production source edits were made.

Manual fixture: SQLite users(id INTEGER PRIMARY KEY, name TEXT, active INTEGER) with (1, 'Alice', 1) and (2, 'Bob', 0). Running SELECT nme FROM users gives the real error no such column: nme; SELECT name FROM users ORDER BY id returns Alice/Bob. Test Fix -> generate inserts only; Fix -> cancel -> Generate must not retain the cancelled fix; with AI disabled the button is hidden. Test the same client path with an installed AI assistant when configured. No paid/live AI request was made in this review.

Frontend typecheck and full lint (ESLint, Prettier and theme tokens) passed on this head.

@Asymtode712

Asymtode712 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

@debba Thanks for the review. Both P2s are fixed.

Stale fix prompt: AiQueryModal now remembers when its current prompt came from Fix with AI. If the modal reopens for ordinary Generate (no initialPrompt), it clears that prompt. A cancelled fix therefore no longer leaks into Generate, and Generate no longer goes through the runQuery path with a stale fix prompt. Ordinary drafts are still kept across close and reopen. A successful fix still clears the prompt, as before. I added a regression test with the same close and reopen props as the Editor. It checks that a cancelled fix reopens as an empty Generate prompt, and that an ordinary draft is kept.

Locales: I added editor.fixWithAi to vi.json and zh-TW.json.

The typecheck, the modal and i18n tests, and Prettier on the touched files pass. I'll wait for your next review.

@Asymtode712
Asymtode712 requested review from 1-DARK and debba November 13, 2026 07:09

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed cfe8a81b4f484a78fda25906a731edac24138648. Both blockers from my previous review are resolved. promptIsFixDraft clears a cancelled Fix prompt when ordinary Generate reopens, while keeping ordinary Generate drafts; successful fixes also clear the marker. The new regression covers the cancel/reopen and ordinary-draft cases. editor.fixWithAi is now present in all 13 locales, including vi and zh-TW. The shared AI client/provider/model/schema path and insert-only Fix behavior remain unchanged.

Local validation on this exact head: 277 tests across 19 files passed (modal, error display, prompt helper and i18n), frontend typecheck passed. Lint results recorded below. No source edits made. GitNexus remains unavailable for this checkout as documented in the preceding review; the incremental change is limited to the modal, its test and the two missing locale keys. No remaining code blocker found.

Full lint passed: ESLint, Prettier and theme-token checks.

@debba
debba dismissed 1-DARK’s stale review November 13, 2026 07:12

Superseded after maintainer re-review of cfe8a81: the removed web API inventory is absent from the PR diff, the branch is mergeable, the Vietnamese locale key is present (as is zh-TW), and the cancelled-fix lifecycle has a passing regression. All requested corrections verified.

@debba
debba merged commit 8c50f91 into TabularisDB:main Nov 13, 2026
11 checks passed
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.

[Feat]: Editor: "Fix with AI" on a failed query

4 participants