Repository navigation
Conversation
Sandboxed macOS apps place their DevFS directory inside ~/Library/Containers/<bundle-id>/Data/tmp/. Starting in macOS 14, macOS TCC associates sandbox containers with the app's code signature and blocks external processes like `flutter_tools` from writing directly into the container via `LocalDevFSWriter` unless the user approves the TCC prompt or the terminal/IDE has Full Disk Access, causing hot reload and hot restart to exit with a `ToolExit`. Override `MacOSDevice.createDevFSWriter` to return `null` (matching the transport already used by `flutter attach -d macos`) so `DevFS` syncs updated kernel and asset files over the VM service HTTP transport and the app process writes to its own container. Note that this reverts the local file copy from flutter#66678 for macOS targets, including non-sandboxed benchmarks like `hot_mode_dev_cycle_macos_target__benchmark`. Previous output: ``` Performing hot restart... Application finished. Flutter failed to create file at "/Users/user/Library/Containers/com.example.issue193907Repro/Data/tmp/appExfFRB/app/main.dart.dill". Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user. ``` Current output: ``` Performing hot reload... Reloaded 0 libraries in 114ms (compile: 16 ms, reload: 0 ms, reassemble: 35 ms). Performing hot restart... Restarted application in 623ms. ``` Fixes flutter#193907
…_darwin_temp_dir Sandboxed macOS apps place their DevFS directory inside `~/Library/Containers/<bundle-id>/Data/tmp/`. Starting in macOS 14, macOS TCC associates sandbox containers with the app's code signature (`kTCCServiceSystemPolicyAppData`) and blocks external processes like `flutter_tools` from writing directly into the container via `LocalDevFSWriter` unless the user approves the TCC prompt or the terminal/IDE has Full Disk Access. Falling back to `_DevFSHttpWriter` (`MacOSDevice.createDevFSWriter` returning `null`) avoids direct container writes, but regresses macOS hot restart times from ~200-400ms to ~660-880ms because `main.dart.dill` is ~70 MB and must be gzip-compressed and streamed over HTTP instead of cloned via APFS copy-on-write (`File.copySync`). Instead, revert the `MacOSDevice` / `DesktopDevice` writer change and redirect macOS sandbox container DevFS paths (`/Library/Containers/<bundle-id>/Data/tmp/<temp-dir>/<fs-name>/`) in `DevFS._prepareDeviceUri` to `application_darwin_temp_dir` (`<DARWIN_USER_TEMP_DIR>/<bundle-id>/<temp-dir>/<fs-name>/`, resolved via `getconf DARWIN_USER_TEMP_DIR`). The macOS App Sandbox profile (`/System/Library/Sandbox/Profiles/application.sb`) grants every sandboxed app full read/write access to `<DARWIN_USER_TEMP_DIR>/<bundle-id>`, which lies outside `~/Library/Containers/` and is not subject to TCC container protection. Reproduction was confirmed manually in `Terminal.app` on macOS with an `Apple Development`-signed sandboxed app (`kTCCServiceSystemPolicyAppData` denied for `com.apple.Terminal`). Current output: ``` OUT: [ +4 ms] DevFS: Creating new filesystem on the device (null) OUT: [ +17 ms] DevFS: Created new filesystem on the device (file:///var/folders/_y/rdj_3wtj5mbbtf6syy_2cw6800d8lv/T/com.example.sandboxRepro/sandbox_reproA1G4Iv/sandbox_repro/) OUT: [ ] DevFS: Sync finished OUT: [ ] Flutter run key commands. OUT: [ ] r Hot reload. 🔥🔥🔥 OUT: [ ] R Hot restart. OUT: [ +152 ms] flutter: ASSET_VERIFY_OK: FontManifest.json (208 bytes) OUT: [ ] Performing hot reload... OUT: [ +1 ms] DevFS: Sync finished OUT: [ +3 ms] flutter: ASSET_VERIFY_OK: FontManifest.json (208 bytes) OUT: [ +30 ms] Hot reload performed in 122ms. OUT: [ ] Performing hot reload... (completed in 126ms) OUT: [ ] Reloaded 1 of 1051 libraries in 132ms (compile: 25 ms, reload: 46 ms, reassemble: 34 ms). OUT: [ +1 ms] Performing hot restart... OUT: [ +38 ms] DevFS: Sync finished OUT: [ +243 ms] Hot restart performed in 343ms. OUT: [ ] Performing hot restart... (completed in 344ms) OUT: [ ] Restarted application in 354ms. OUT: [ +263 ms] flutter: ASSET_VERIFY_OK: FontManifest.json (208 bytes) OUT: [+1742 ms] DevFS: Deleting filesystem on the device (file:///var/folders/_y/rdj_3wtj5mbbtf6syy_2cw6800d8lv/T/com.example.sandboxRepro/sandbox_reproA1G4Iv/sandbox_repro/) OUT: [ +11 ms] DevFS: Deleted filesystem on the device (file:///var/folders/_y/rdj_3wtj5mbbtf6syy_2cw6800d8lv/T/com.example.sandboxRepro/sandbox_reproA1G4Iv/sandbox_repro/) OUT: [ +7 ms] Application finished. ``` Fixes flutter#193907
bkonyi
marked this pull request as ready for review
November 5, 2026 01:20
Contributor
There was a problem hiding this comment.
Code Review
This pull request redirects macOS sandbox container DevFS URIs to the DARWIN_USER_TEMP_DIR to prevent macOS TCC container protection issues, and ensures the redirected directories are cleaned up on destruction. It also adds corresponding unit tests. The review feedback suggests making the regular expression used to match the sandbox container path case-insensitive to robustly handle potential casing variations on macOS.
…tively Pass `caseSensitive: false` to `DevFS._macOSSandboxContainerTempRegExp` so macOS App Sandbox container DevFS paths with non-canonical directory casing (for example `/users/.../library/containers/<bundle-id>/data/tmp/...` on case-insensitive APFS) still redirect to `<DARWIN_USER_TEMP_DIR>/<bundle-id>/...` while preserving captured bundle identifier casing. Canonical macOS paths match identically to the previous `mac-runner` verification run (`mac-runner` is currently offline); case-insensitive path matching is covered in `devfs_test.dart`. Current output: ``` OUT: [ +4 ms] DevFS: Creating new filesystem on the device (null) OUT: [ +17 ms] DevFS: Created new filesystem on the device (file:///var/folders/_y/rdj_3wtj5mbbtf6syy_2cw6800d8lv/T/com.example.sandboxRepro/sandbox_reproA1G4Iv/sandbox_repro/) OUT: [ ] DevFS: Sync finished OUT: [ ] Flutter run key commands. OUT: [ ] r Hot reload. 🔥🔥🔥 OUT: [ ] R Hot restart. OUT: [ +152 ms] flutter: ASSET_VERIFY_OK: FontManifest.json (208 bytes) OUT: [ ] Performing hot reload... OUT: [ +1 ms] DevFS: Sync finished OUT: [ +3 ms] flutter: ASSET_VERIFY_OK: FontManifest.json (208 bytes) OUT: [ +30 ms] Hot reload performed in 122ms. OUT: [ ] Performing hot reload... (completed in 126ms) OUT: [ ] Reloaded 1 of 1051 libraries in 132ms (compile: 25 ms, reload: 46 ms, reassemble: 34 ms). OUT: [ +1 ms] Performing hot restart... OUT: [ +38 ms] DevFS: Sync finished OUT: [ +243 ms] Hot restart performed in 343ms. OUT: [ ] Performing hot restart... (completed in 344ms) OUT: [ ] Restarted application in 354ms. OUT: [ +263 ms] flutter: ASSET_VERIFY_OK: FontManifest.json (208 bytes) OUT: [+1742 ms] DevFS: Deleting filesystem on the device (file:///var/folders/_y/rdj_3wtj5mbbtf6syy_2cw6800d8lv/T/com.example.sandboxRepro/sandbox_reproA1G4Iv/sandbox_repro/) OUT: [ +11 ms] DevFS: Deleted filesystem on the device (file:///var/folders/_y/rdj_3wtj5mbbtf6syy_2cw6800d8lv/T/com.example.sandboxRepro/sandbox_reproA1G4Iv/sandbox_repro/) OUT: [ +7 ms] Application finished. ```
…irectory In production, `DevFS._toolContext.fs` is wrapped in `ErrorHandlingFileSystem`, which converts mapped `FileSystemException` errnos (such as `EACCES` and `EPERM`) on `existsSync` and `deleteSync` into `ToolExit` before `on FileSystemException` in `DevFS.destroy()` can catch them. Wrap the best-effort `_localSandboxTempDir` cleanup in `ErrorHandlingFileSystem.noExitOnFailure` (ahead of `_vmService.deleteDevFS(fsName)` so local cleanup still completes if the app window was closed and the VM service disconnected) so permission errors during temporary directory cleanup log a trace message instead of aborting shutdown with a `ToolExit`. Canonical macOS paths match the previous `mac-runner` verification run (`mac-runner` is currently offline); `ErrorHandlingFileSystem` cleanup error handling and local cleanup when the remote `_deleteDevFS` call fails are covered in `devfs_test.dart`. Current output: ``` OUT: [ +4 ms] DevFS: Creating new filesystem on the device (null) OUT: [ +17 ms] DevFS: Created new filesystem on the device (file:///var/folders/_y/rdj_3wtj5mbbtf6syy_2cw6800d8lv/T/com.example.sandboxRepro/sandbox_reproA1G4Iv/sandbox_repro/) OUT: [ ] DevFS: Sync finished OUT: [ ] Flutter run key commands. OUT: [ ] r Hot reload. 🔥🔥🔥 OUT: [ ] R Hot restart. OUT: [ +152 ms] flutter: ASSET_VERIFY_OK: FontManifest.json (208 bytes) OUT: [ ] Performing hot reload... OUT: [ +1 ms] DevFS: Sync finished OUT: [ +3 ms] flutter: ASSET_VERIFY_OK: FontManifest.json (208 bytes) OUT: [ +30 ms] Hot reload performed in 122ms. OUT: [ ] Performing hot reload... (completed in 126ms) OUT: [ ] Reloaded 1 of 1051 libraries in 132ms (compile: 25 ms, reload: 46 ms, reassemble: 34 ms). OUT: [ +1 ms] Performing hot restart... OUT: [ +38 ms] DevFS: Sync finished OUT: [ +243 ms] Hot restart performed in 343ms. OUT: [ ] Performing hot restart... (completed in 344ms) OUT: [ ] Restarted application in 354ms. OUT: [ +263 ms] flutter: ASSET_VERIFY_OK: FontManifest.json (208 bytes) OUT: [+1742 ms] DevFS: Deleting filesystem on the device (file:///var/folders/_y/rdj_3wtj5mbbtf6syy_2cw6800d8lv/T/com.example.sandboxRepro/sandbox_reproA1G4Iv/sandbox_repro/) OUT: [ +11 ms] DevFS: Deleted filesystem on the device (file:///var/folders/_y/rdj_3wtj5mbbtf6syy_2cw6800d8lv/T/com.example.sandboxRepro/sandbox_reproA1G4Iv/sandbox_repro/) OUT: [ +7 ms] Application finished. ```
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.
Sandboxed macOS apps place their DevFS directory inside
~/Library/Containers/<bundle-id>/Data/tmp/. Starting in macOS 14, macOS TCC associates sandbox containers with the app's code signature (kTCCServiceSystemPolicyAppData) and blocks external processes likeflutter_toolsfrom writing directly into the container viaLocalDevFSWriterunless the user approves the TCC prompt or the terminal/IDE has Full Disk Access, causing hot reload and hot restart to exit with aToolExit.Redirect macOS App Sandbox container DevFS paths (
/Library/Containers/<bundle-id>/Data/tmp/<temp-dir>/<fs-name>/) inDevFS._prepareDeviceUritoapplication_darwin_temp_dir(<DARWIN_USER_TEMP_DIR>/<bundle-id>/<temp-dir>/<fs-name>/, resolved viagetconf DARWIN_USER_TEMP_DIR). The macOS App Sandbox profile (/System/Library/Sandbox/Profiles/application.sb) grants every sandboxed app full read/write access to<DARWIN_USER_TEMP_DIR>/<bundle-id>, which lies outside~/Library/Containers/and is not subject to TCC container protection, preserving fast APFS copy-on-write file copies viaLocalDevFSWriter.Reproduction was confirmed manually in
Terminal.appon macOS with anApple Development-signed sandboxed app (kTCCServiceSystemPolicyAppDatadenied forcom.apple.Terminal).Current output:
Fixes #193907