Handle kFSEventStreamEventFlagMustScanSubDirs to prevent missed UI refreshes#2782
Handle kFSEventStreamEventFlagMustScanSubDirs to prevent missed UI refreshes#2782delacrixmorgan wants to merge 1 commit into
kFSEventStreamEventFlagMustScanSubDirs to prevent missed UI refreshes#2782Conversation
|
This is a change I've been thinking of making for a while, now, but I've always been bugged by the fact that I don't know why POL, the original author, wrote it this way to begin with; whether it's a mistake, or a deliberate choice. The only issue I can imagine this fix causing, would be GitUp adding oil to the fire, when the system is already swamped (which it would be, to reach the point of coalescing file system updates like this). Not sure if that's a reasonable concern, or if e.g. the debouncing ( Can you describe when you've hit issues, that you think this patch would resolve? Have you been able to confirm that this fix helps, or is it a best guess at a solution? Having a reliable repro would be a great first step to evaluate the change. |
|
I have to admit that I can't consistently recreate this issue, but it happened twice this week for me where I will need to close the application in order to see the latest code changes, else it'll just at an outdated state. When I added this fix, I didn't notice any breaking changes. |
|
Thanks @delacrixmorgan. I've experienced this myself in the Tahoe beta build. I have been meaning to debug why the UI doesn't appear to redraw in these cases and it's the main reason I haven't made the build the stable build yet. I'll review your changes tonight and see if I can track the refresh cycle with logs to see if I can better understand if this is resolving that issue or if there's something else going on. |
Summary
The UI occasionally fails to refresh when files change in the working directory or
.gitdirectory. This is caused by the FSEvents callback ignoringkFSEventStreamEventFlagMustScanSubDirsevents, which the kernel sends when its event buffer overflows during rapid filesystem activity.Problem
In
GCLiveRepository.m, the_stream:didReceiveEvents:withPaths:flags:method previously discarded events flagged withkFSEventStreamEventFlagMustScanSubDirs:Per Apple's FSEvents documentation, this flag means: "Your application must rescan not just the directory given in the event, but all its children, recursively." It fires when the kernel drops or coalesces events due to buffer overflow — typically during rapid multi-file changes (e.g.,
git checkout,git rebase, IDE refactoring, build tools).By ignoring this flag, the app missed those change notifications entirely, leaving the UI stale.
Fix
When
kFSEventStreamEventFlagMustScanSubDirsis received, we now mark the appropriate stream as changed and schedule the existing debounced update timer:This follows the exact same code path as regular file change events — no new logic introduced.
Why This Is Safe
kUpdateLatencytimer coalesces multiple triggers; no duplicate processing._updateStatus:compares the new diff against the current one (isEqualToDiff:) and only notifies the UI if something actually changed. No spurious redraws.Risk Assessment
_updateStatus:already diffs against current state and only notifies on actual changesMustScanSubDirs, we intentionally skip the ignore check — the kernel is telling us events were lost, so we must assume something changed. The downstream status computation will correctly reflect only non-ignored files.CFRunLoopGetMain()), same as beforeOverall risk: Very Low. The change is minimal, follows established patterns in the codebase, and Apple's documentation explicitly mandates this behavior.