Skip to content

fix(coordinator): resolve a table tab's schema from the active session when none is given#1808

Merged
datlechin merged 1 commit into
mainfrom
fix/mssql-tab-schema-identity
Jul 3, 2026
Merged

fix(coordinator): resolve a table tab's schema from the active session when none is given#1808
datlechin merged 1 commit into
mainfrom
fix/mssql-tab-schema-identity

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • Resolve a table tab's schema once, at tab creation, from the live session when the caller passes none. New shared resolver DatabaseManager.resolvedSchemaName(_:for:); explicit schemas always win, schema-less engines stay nil.
  • Covers every path that created tabs with no schema identity: Quick Switcher, the MCP open_table_tab tool, and tabs restored from either. FK navigation now uses the same resolver (no behavior change there).
  • Add a first-load backstop that stamps legacy nil-schema tabs after connect and schema switch, before their SQL runs.
  • Thread a schema parameter through FilterSQLGenerator.generatePreviewSQL.

Root cause

Quick Switcher items and MCP payloads carry no schema, so tableContext.schemaName stayed nil. Query builders correctly refuse to guess, so SQL Server received unqualified names: SELECT resolved through the login default schema and failed with "Invalid object name", and generated INSERT/UPDATE/DELETE could silently target a same-named table in another schema. No rebuild ever fixed the write path.

The sidebar path was already fixed by #1758. The re-report in #1774 came from the registry serving the pre-fix MSSQL plugin binary until v1.0.29 was published on June 30. This PR fixes the remaining nil-schema paths app-side; no plugin re-release is needed.

The fix deliberately does not add a _currentSchema fallback inside the driver (the approach in #1778): SQL Server has no session schema, and the app's cached query-building driver never connects, so its _currentSchema is permanently dbo and would mis-qualify names for logins with a different default schema.

Related: #1774. Supersedes #1778.

Validation

  • xcodebuild test on the six affected suites: 131 passed, 0 failed, including 13 new tests (Quick Switcher and MCP payload reproductions, resolver unit tests, first-load backstop, FK regression guard)
  • swiftlint lint --strict on changed files: no new violations
  • git diff --cached style gate: clean

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b81f9a6f9e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +93 to +95
let resolvedSchemaName = DatabaseManager.shared.resolvedSchemaName(
payload.schemaName, for: connectionId
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve schema after switching to the payload database

When a table payload such as MCP open_table_tab provides a databaseName different from the live session and omits schemaName, this resolves nil against the pre-switch session schema. initializeAndRestoreTabs later switches to selectedTab.tableContext.databaseName, but the tab has already been stamped and its query built with the old schema, so opening db_b.users while the session is on db_a.sales can query db_b.sales.users instead of the target database's default/current schema. Defer this fallback until after the database switch, or skip it when the payload database is not the active database.

Useful? React with 👍 / 👎.

Comment on lines 43 to 45
}

private func consumePendingLoad(trigger: TableLoadTrigger, session: ConnectionSession) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Stamp restored tab schemas after the database switch

When a pending load resumes for a restored nil-schema table whose saved database differs from the connected session, this call stamps the schema before the code below switches to the tab's database. After the switch, lazyLoadCurrentTabIfNeeded sees a non-nil schema and prepareTableTabFirstLoad will not re-resolve it, so the first query is qualified with the schema from the previous database. Move the schema resolution after the database switch so legacy restored tabs use the schema for their own database.

Useful? React with 👍 / 👎.

@datlechin datlechin merged commit bab5274 into main Jul 3, 2026
3 checks passed
@datlechin datlechin deleted the fix/mssql-tab-schema-identity branch July 3, 2026 17:57
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.

1 participant