Skip to content

fix(sql): preserve execution context correctness - #1870

Merged
openai0229 merged 3 commits into
mainfrom
fix/sql-output-context-correctness
Jul 21, 2026
Merged

fix(sql): preserve execution context correctness#1870
openai0229 merged 3 commits into
mainfrom
fix/sql-output-context-correctness

Conversation

@openai0229

@openai0229 openai0229 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Related issue

Closes #1869

Enterprise equivalent: OtterMind/Chat2DB-Enterprise#97, tracked by Enterprise Issue #95.

Summary

  • Restore the database selected in the editor before each synchronous or streaming execution through the existing database-plugin abstraction and the same JDBC connection.
  • Make Output context capture observational only, preserving native catalog/schema semantics such as PostgreSQL SET LOCAL, DEFAULT, and multi-target search_path.
  • Preserve statement-start context on failure or cancellation, handle SQL Server GO batches correctly, bound Output record/message growth, and keep Community execution timing internally consistent.
  • Prevent duplicate Desktop log events and message ID collisions without changing the SQL execution API.
  • Route successful tabular Web executions to the newest result tab while keeping no-result, failed, and cancelled executions on Output. Mixed Web batches now fall back to the backend top-level statementSequence when structured stream metadata is absent.

Affected surfaces

  • Frontend / Web
  • Backend / API / Storage
  • Database plugin / Driver
  • JCEF / Desktop packaging
  • CI / Build / Release
  • Documentation only

Verification

  • Commands and results:
    • cd chat2db-community-server && rtk mvn -q clean test install -Dmaven.test.skip=false -DskipTests=false: passed all 48 modules; 866 tests, 0 failures, 0 errors, 1 skipped.
    • cd chat2db-community-client && rtk yarn test:search-result-tab-selection: passed.
    • cd chat2db-community-client && rtk yarn test:sql-execution-log: passed.
    • Targeted ESLint for the five changed frontend files: passed.
    • cd chat2db-community-client && rtk yarn run build:web:community --app_version=5.3.0: passed.
    • rtk git diff --check: passed.
  • Manual verification: Playwright CLI reproduced the old mixed-batch failure against local MySQL. After the correction, SELECT / SELECT / USE / SELECT activates the final result tab, a successful no-result USE activates Output, and a failed SELECT activates Output.
  • UI evidence: Browser-verified on Community Web at the current development build; this changes active-tab routing without changing visual layout.

Risk and compatibility

  • Public API or stored data: No public API, schema, or persisted-data migration.
  • Database or driver compatibility: Execution-start session alignment and SQL Server batch handling change intentionally; focused tests pass. Local MySQL Web smoke passed, while real PostgreSQL and SQL Server driver smoke remains the residual risk.
  • Network, privacy, or security: N/A; no network boundary or credential handling changes.
  • Community / Local / Pro boundary: This PR contains the Community implementation. Equivalent Enterprise behavior is under review in Enterprise PR 建议: ssh支持密钥登录 #97; enterprise-migration is intentionally unchanged.
  • Backward compatibility: Corrects session/context and result-tab behavior without a compatibility fallback or migration.

Reviewer map

  • Start here: DefaultSQLExecutor, JdbcExecutionContext, and SqlServerExecutor; then review sqlExecutionLog.ts for bounded frontend state and event deduplication. For result routing, review SQLExecute, SearchResult, tabSelection.ts, and sortExecutionResults.
  • Failure condition: A statement executes outside the editor-selected database, Output reports a context different from the JDBC session, GO reaches the driver, final status/timing is lost when records are bounded, or a successful batch ending in a tabular result leaves Output active.
  • Rollback or disable path: Revert this PR; there is no data migration or feature flag.

Contributor declaration

  • I linked the Issue that defines this change.
  • I tested the affected behavior and reported the actual results above.
  • I did not include credentials, private data, or generated build output.
  • I disclosed substantial AI assistance below, or this PR contains no substantial AI-generated code.

AI assistance: Substantial AI assistance was used for implementation, regression tests, browser verification, and cross-repository review.

@openai0229 openai0229 self-assigned this Jul 17, 2026
@openai0229 openai0229 added area/frontend Ownership: Community frontend components and UI code area/backend Community backend and domain services area/sql-editor SQL console, editor, completion, and execution db/mysql MySQL-specific behavior db/postgresql PostgreSQL-specific behavior db/sql-server SQL Server-specific behavior edition/community Chat2DB Community labels Jul 17, 2026
@openai0229

Copy link
Copy Markdown
Contributor Author

Cancellation follow-up

This PR now also fixes the persistent Unknown Error banner shown after an intentional Web query cancellation.

  • A confirmed transport cancellation still records cancelled, keeps Output active, and restores the previous result snapshot when needed.
  • The cancellation is no longer propagated to the SQL editor error banner.
  • Non-cancellation errors continue to propagate unchanged.
  • Classification is limited to structured AbortError, CanceledError, and ERR_CANCELED markers; PostgreSQL current transaction is aborted remains a real error.

Verification:

  • Playwright CLI: cancelling SELECT SLEEP(10) AS slept; produces Execution cancelled with zero Unknown Error banners.
  • test:sql-execution-log: passed in Community and Enterprise.
  • Targeted ESLint: passed in Community and Enterprise.
  • Web production build: passed in Community and Enterprise.
  • git diff --check: passed in Community and Enterprise.

@openai0229
openai0229 merged commit b22e4e9 into main Jul 21, 2026
9 checks passed
@openai0229
openai0229 deleted the fix/sql-output-context-correctness branch August 5, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/backend Community backend and domain services area/frontend Ownership: Community frontend components and UI code area/sql-editor SQL console, editor, completion, and execution db/mysql MySQL-specific behavior db/postgresql PostgreSQL-specific behavior db/sql-server SQL Server-specific behavior edition/community Chat2DB Community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQL Output context, timing, and log lifecycle have correctness gaps

1 participant