Fix hang-on-launch issue on macOS Sequoia (#169)#170
Merged
Conversation
This commit addresses a critical bug where MacDown 3000 hangs immediately on launch on macOS Sequoia 15.7.2. The root cause was the preferences migration code performing synchronous operations on the main thread during app initialization, which times out on Sequoia due to stricter sandbox restrictions. Changes made: 1. Preferences Migration (MPPreferences.m): - Add 2-second timeout protection around migration using dispatch_semaphore - Run migration on background queue to prevent blocking main thread - Add comprehensive logging for diagnostics - Add error handling with @try/@catch blocks - Mark migration as complete on timeout/failure to prevent retry loops - Replace custom initWithSuiteNamed: with Apple's built-in initWithSuiteName: - Gracefully fall back to default preferences if migration fails 2. CI Enhancements (test.yml): - Add macOS 15 (Sequoia) to test matrix alongside macOS 14 - Add fail-fast: false to test both OS versions - Add comprehensive runtime launch test (smoke test) - Test both fresh install and migration scenarios - Verify app launches within timeout (detects hangs) - Validate migration completion flag is set correctly Testing approach: - Fresh install scenario: No legacy preferences - Migration scenario: Legacy preferences present - Both scenarios verified on macOS 14 and 15 - Timeout protection ensures app never hangs Related to #169
Each OS matrix job was trying to upload artifacts with the same name, causing conflicts. Now artifacts are named uniquely per OS version.
Following Chico's code review, this commit fixes two critical issues: 1. Added timeout protection to Phase 2 (preference copying) - Wrapped preference copying in background queue with semaphore - Added 2-second timeout for the copy operation - Prevents hang if writing preferences blocks on disk I/O 2. Removed all deprecated synchronize calls - Removed 5 synchronize() calls (deprecated since macOS 10.13) - NSUserDefaults auto-syncs periodically - Eliminates potential lag from synchronous disk writes on main thread Both phases of migration now have timeout protection and run on background queues, ensuring the app never hangs during startup. Related to #169
Contributor
Code Coverage ReportCurrent Coverage: 41.18% Coverage Details (Summary) |
Closed
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.
Summary
Fixes a critical bug where MacDown 3000 hangs immediately on launch on macOS Sequoia 15.7.2. The root cause was the preferences migration code performing synchronous operations on the main thread during app initialization, which times out on Sequoia due to stricter sandbox restrictions.
Changes Made
1. Preferences Migration (MPPreferences.m)
[MPPreferences]prefix for diagnosticssynchronizecalls (deprecated since macOS 10.13)initWithSuiteNamed:with Apple's built-ininitWithSuiteName:2. CI/CD Enhancements (.github/workflows/test.yml)
3. Documentation Updates
Testing Approach
Automated Testing
✅ Unit tests pass on macOS 14 and 15
✅ Fresh install test - App launches without hanging
✅ Migration test - App launches with legacy preferences without hanging
✅ Timeout detection - Would fail if app hangs
✅ Both OS versions tested (Sonoma and Sequoia)
Manual Testing Plan
Zeppo assessed that manual testing has limited value given the comprehensive automated coverage, but provided a minimal testing plan for real-world validation on macOS Sequoia hardware:
See Zeppo's analysis for detailed steps.
Code Review
Chico reviewed the implementation and identified two critical issues, which have been addressed:
Technical Details
Migration Flow:
com.uranusjr.macdown(background queue, 2s timeout)app.macdown.macdown3000(background queue, 2s timeout)Timeout Protection:
Error Handling:
Related Issue
Related to #169
Review Notes
Architectural Guidance: Groucho validated the approach and confirmed proper Objective-C patterns
Code Review: Chico identified and all critical issues were addressed
Documentation: Harpo updated relevant documentation
Testing: Zeppo provided manual testing assessment
CI Status: ✅ All tests passing on macOS 14 and 15