Skip to content

fix(coordinator): reload table data on refresh while a query is in flight#1643

Merged
datlechin merged 1 commit into
mainfrom
fix/1637-refresh-stale-data
Jun 11, 2026
Merged

fix(coordinator): reload table data on refresh while a query is in flight#1643
datlechin merged 1 commit into
mainfrom
fix/1637-refresh-stale-data

Conversation

@datlechin

Copy link
Copy Markdown
Member

Fixes #1637.

Problem

Clicking Refresh (toolbar or Cmd+R) on an open table tab did nothing when a query was still running. Rows inserted from another client never showed up; the only workaround was closing and reopening the tab.

Root cause

handleRefresh cancelled the in-flight task with currentQueryTask?.cancel() and called runQuery() on the next line. Cancellation is cooperative: the isExecuting flag is only cleared inside the cancelled task, on a later run-loop turn. So runQuery() hit its !isExecuting guard and returned early. The refresh SELECT never ran, with no log and no user feedback. This fired whenever a query was in flight at refresh time: slow queries, the initial load still running, or rapid repeated refreshes.

Fix

  • handleRefresh now calls cancelCurrentQuery(), the existing synchronous primitive that cancels and nils the task, bumps queryGeneration, and clears isExecuting before the new query starts. Both the direct branch and the pending-changes branch are covered.
  • refreshTables() now fetches schema metadata through withMetadataDriver(workload: .bulk) instead of the main connection driver, so the schema reload no longer contends with the data SELECT on the same socket (same isolation rule as the rest of background introspection since fix(perf): open tables without waiting behind background schema introspection #1483).
  • Removed the dead dataGridRefresh() delegate path and its onRefresh plumbing. It had no callers and skipped rebuildTableQuery, so it would have refreshed with a stale query if ever wired up.

Tests

New MainContentCoordinatorRefreshTests (5 tests, all passing):

  • regression: refresh during an in-flight query cancels it and starts a new execution
  • refresh on an idle table tab starts an execution
  • refresh rebuilds the table query from current filter/sort/pagination state
  • refresh on a query tab is a no-op
  • refresh in structure view leaves execution state untouched

The pending-changes confirmation branch shares the same three-line sequence but goes through an NSAlert, so it is not covered by a deterministic unit test.

swiftlint lint --strict clean on changed files.

@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: d948e4b38c

ℹ️ 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 +45 to 47
cancelCurrentQuery()
rebuildTableQuery(at: tabIndex)
runQuery()

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 Guard stale cancellation cleanup before restarting

When Refresh is pressed while a table query is in flight, this starts the replacement query immediately after cancelling the old task. The old task’s cleanup in executeQueryInternal still runs later and unconditionally clears currentQueryTask / isExecuting before checking queryGeneration, so the cancelled task can mark the newly-started refresh query as idle and drop its task reference while its SELECT is still running. In that state the toolbar shows idle and later Cancel/Refresh actions can no longer target the real query; guard the old task cleanup by generation or wait for cancellation before calling runQuery().

Useful? React with 👍 / 👎.

@datlechin datlechin merged commit 0d7548c into main Jun 11, 2026
4 checks passed
@datlechin datlechin deleted the fix/1637-refresh-stale-data branch June 11, 2026 06:54
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