Repository navigation
fix(coordinator): present transfer results on the dialog's own window - #2319
Merged
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
Signed-off-by: Ngô Quốc Đạt <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2314.
The bug
A failed import shows its "Import failed" alert for about 9 milliseconds and then it is gone, so the reporter never learns why the import failed.
Root cause
A SwiftUI
.sheeton macOS is a real AppKit sheet (SheetPresentationWindow). The transfer dialogs pick their alert's parent window withNSApp.keyWindow, read from inside.onChangeat the moment the nested "Importing…" progress sheet is being dismissed. At that instantNSApp.keyWindowis the progress sheet. AppKit ends a sheet's children along with it, so the alert attaches, then its completion handler fires withNSApplication.ModalResponse.stop(-1000),isVisiblegoes false and it never renders. The completion still runs, so the app's own state resets and nothing is left on screen.I reproduced the exact window layering (window → dialog sheet → progress sheet → alert) in a standalone AppKit/SwiftUI harness and measured five candidate targets:
NSApp.keyWindow(what we ship today)-1000after ~9mswindow: nil→AlertHelper.resolveWindow.sheet(onDismiss:)+NSApp.keyWindowThree things that look like fixes and are not:
nildoes not help.AlertHelper.isContentWindowis!(window is NSPanel) && styleMask.contains(.titled), and aSheetPresentationWindowis neither a panel nor untitled (mask 65), so it clears the filter andresolveWindowre-picks the same dying sheet..sheet(onDismiss:)fires 2 to 13 ms after the binding flips, while the sheet window is still visible and still key.NSWindow.h: "If the window already has a presented sheet, it will queue up sheets presented after that… Critical sheets will skip this queuing process."presentImportFailureis.criticalso it would appear, but it visibly displaces the still-open import dialog; and the three non-critical success alerts would queue behind the open dialog sheet and never appear at all.Nothing at runtime can tell a dying sheet from a healthy one, so the rule has to hold at the call site: a dialog presents its alerts on the window it is hosted in.
The fix
Each transfer dialog captures its own
NSWindowwith the existingWindowAccessorand passes it to every alert and panel it raises. This is already the codebase's convention;MainContentCoordinator.swift:209spells it out:The three transfer dialogs were the ones not following it.
This is a targeted fix, not a restructure. I drafted a
pendingOutcome+.sheet(onDismiss:)rewrite of the result plumbing and dropped it: the measurement shows same-transaction presentation on the correct window already works, so the rewrite was risk with no correctness gain.Scope: 9 call sites, not 1
Both the success and the failure alerts in all three dialogs fail by this mechanism, so "Import completed with errors" (which carries the per-statement failure list) was flashing too, and so was every export result.
ImportDialog: success alert, failure alert, and the file open panelRowImportSheet: success alert, failure alertExportDialog: success alert,showExportError, theloadDatabaseItemserror, and the file save panelThe last three passed
window: nil, which the table above shows fails the same way.Also fixed: a failed import that would not say why
SQLImportPluginthrewrollbackFailedand discarded the original error. That error is the only carrier of the line number, the failing statement and the database's own message, so once a rollback also failed the user got "Transaction rollback failed" and nothing about what actually broke. Two more consequences of the same block: an import the user cancelled was reported as a rollback error, and an import that committed cleanly was reported as failed when only the foreign-key restore afterwards went wrong (the catch rolled back an already-committed transaction, which then failed).The cause is now preferred and the rollback failure appended to it, without touching
rollbackFailed's payload, which would break the PluginKit ABI. Two lifecycle fixes go with it: the.stopAndCommitpath now records that it committed, so the catch no longer rolls back a committed transaction, and restoring foreign-key checks after a successful commit can no longer turn a committed import into a reported failure (it logs, matching what.stopAndCommitalready did).Making the alert stay up while it says the wrong thing would only half-answer the report, which is why this rides along.
Also: the report is copyable again
docs/features/import-export.mdxpromised a "Copy Errors to Clipboard" button. Grep says it existed only in that sentence and as an orphaned string in the catalog; the button was lost when the bespoke result views becameNSAlert. Both result alerts now carry a Copy Details button inside the accessory view (anNSAlertbutton would dismiss the alert), routed throughClipboardService.sharedso it is testable. A single failure shows the statement, as before, but copies the line, the reason and the statement so the pasted text stands on its own. The docs line now matches.Tests
TransferAlertWindowOwnershipTestsscansViews/ImportandViews/Exportand fails if any alert presenter is handedNSApp.*ornil. This is the only thing that can catch a regression, since the defect is invisible to a unit test. I verified the guard actually fails: reintroducingwindow: NSApp.keyWindowinImportDialogturned it red, and reverting turned it green. Two more cases close the ways it could pass while broken: one asserts every dialog that presents onhostWindowalso captures it withWindowAccessor(spelling the argument proves nothing if the capture is gone andhostWindowis nil forever), and one asserts the scan really reaches all three dialogs, so it cannot pass by scanning nothing.SQLImportFailureTestscovers the error composition: the cause survives a failed rollback with its line and statement intact, a cancellation stays a cancellation, and an unstructured cause keeps both messages.SQLImportTransactionTestsdrives the realSQLImportPlugin.performImportagainst a recording sink and pins the transaction lifecycle: stop-and-commit never rolls back what it committed and still reports the failing statement rather than a rollback error, stop-and-rollback rolls back and never commits, and a committed import survives a failed foreign-key restore. Verified these bite too: reverting both plugin fixes turns exactly those three red and leaves the fourth green.TransferFailureReportTestsgains the failure-report composition and the clipboard write, asserted against an injectedClipboardProviderfake (NSPasteboard.generalreturns nil on CI).No UI test. Reaching the import dialog goes through an
NSOpenPanel, and there is no precedent for driving one anywhere inTableProUITestsand no seam that sets the import file directly. I would rather say so than land a flaky CI test.No screenshots. The "before" state is the absence of any alert, which is not a screenshot, and scripted capture of the "after" state hit a macOS UI-automation authorization prompt I could not satisfy in this environment. The measured evidence is in the table above.
Verified
Run through
.claude/skills/fix-issue/scripts/verify.shagainst this branch:generatePASSbuildPASStest SQLImportFailureTests SQLImportTransactionTests TransferFailureReportTests TransferAlertWindowOwnershipTests AlertWindowResolutionTestsPASS, 25 executed, 25 passedlinton all 8 changed paths PASS, 0 violationsSQLImportplugin scheme builds cleanplugins(theAllPluginsaggregate) fails locally on this machine, in the vendoredoracle-niopackage's@TaskLocalmacro expansion (unknown attribute 'usableFromInlinenonisolated'). That is a known local-only toolchain breakage unrelated to this change; no error in the log comes from TablePro source. CI's own plugin step is what covers it.