fix(coordinator): reload table data on refresh while a query is in flight#1643
Conversation
There was a problem hiding this comment.
💡 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".
| cancelCurrentQuery() | ||
| rebuildTableQuery(at: tabIndex) | ||
| runQuery() |
There was a problem hiding this comment.
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 👍 / 👎.
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
handleRefreshcancelled the in-flight task withcurrentQueryTask?.cancel()and calledrunQuery()on the next line. Cancellation is cooperative: theisExecutingflag is only cleared inside the cancelled task, on a later run-loop turn. SorunQuery()hit its!isExecutingguard 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
handleRefreshnow callscancelCurrentQuery(), the existing synchronous primitive that cancels and nils the task, bumpsqueryGeneration, and clearsisExecutingbefore the new query starts. Both the direct branch and the pending-changes branch are covered.refreshTables()now fetches schema metadata throughwithMetadataDriver(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).dataGridRefresh()delegate path and itsonRefreshplumbing. It had no callers and skippedrebuildTableQuery, so it would have refreshed with a stale query if ever wired up.Tests
New
MainContentCoordinatorRefreshTests(5 tests, all passing):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 --strictclean on changed files.