Repository navigation
Description
macOS hot restart cannot write DevFS files into a sandboxed app container
Summary
A Flutter macOS debug app can launch and connect to the VM service, but hot
restart fails while the tool writes the compiled kernel file (main.dart.dill)
under the app's sandbox container. The failure was reproduced in a minimal
Flutter counter app signed for macOS with App Sandbox enabled.
Environment
- Flutter 3.47.6, framework revision
5fc346839b5d0eef006ed8404392afb4dfae428d - macOS 27.0.1 and Xcode 27.0 (27A266a). These versions were measured on the
same host after the original failure; they were not printed in that failure
log. - Apple Development-signed arm64 macOS app. For both runs the bundle identifier,
signing authority/team, and effective entitlements were the same. The
effective entitlements includedapp-sandbox,cs.allow-jit,
get-task-allow, andnetwork.server. The app was rebuilt/re-signed for the
patched run, so its code-signature hash and signing timestamp changed.
Minimal reproduction
- Create a macOS Flutter app using the default counter-app source.
- Enable the App Sandbox for the Debug configuration and retain the JIT,
debugger, and VM-service network entitlements needed for a debug run. Sign
with an Apple Development identity. - From the project root, run
flutter run -d macos --verbose. - After the app launches and the VM service connects, press uppercase
R
once to request a hot restart.
Expected
The tool writes the updated kernel and other DevFS entries and restarts the app.
Observed before the change
The app launches and connects to the VM service, then hot restart exits while
creating main.dart.dill beneath a path of the form
<sandbox-container>/Data/tmp/<run>/<app>/main.dart.dill, followed by Flutter's
generic read/write-permissions guidance. A complete raw stack trace and errno
were not retained. Inspection of the Flutter 3.47.6 code shows macOS selecting
LocalDevFSWriter; its direct filesystem write path reaches
File.copySync/createSync for that container URL.
Candidate change
In the isolated checkout based on the revision above, MacOSDevice overrides
createDevFSWriter and returns a small adapter that delegates to the existing
VM-service HTTP writer passed by DevFS.update. Other desktop platforms retain
DesktopDevice's local writer. The adapter does not catch or mask transfer
errors.
@override
DevFSWriter createDevFSWriter(ApplicationPackage? app, String? userIdentifier) {
return MacOSHttpDevFSWriter();
}
class MacOSHttpDevFSWriter implements DevFSWriter {
@override
Future<void> write(Map<Uri, DevFSContent> entries, Uri baseUri, DevFSWriter parent) {
return parent.write(entries, baseUri, parent);
}
}Changed files:
packages/flutter_tools/lib/src/macos/macos_device.dartpackages/flutter_tools/test/general.shard/macos/macos_device_test.dart
The focused tests cover macOS writer selection, delegation, and propagation of
transfer failures. Existing desktop coverage continues to assert that other
desktop devices use LocalDevFSWriter.
Evidence after the change
The same minimal app source and signing/sandbox configuration was rebuilt and
run with the isolated patched Flutter checkout (same framework revision, with
only the change above). Exactly one hot restart was requested. The verbose log
showed DevFS syncing 43.5 MB through the VM service, followed by:
Hot restart performed in 361ms.
Restarted application in 368ms.
The app was quit after this run. This is one controlled positive run, not a
claim of broad reliability.
Hermetic validation on the isolated checkout:
macos_device_test.dart,desktop_device_test.dart, anddevfs_test.dart:
55 tests passed.- Targeted Dart analysis of the changed implementation and test: no issues.
git diff --check: clean.
Interpretation and limits
The before/after evidence supports the hypothesis that using the VM-service
transport avoids the failing direct host write into the sandbox container. It
does not prove code signing itself is causal, nor does it establish that every
sandboxed configuration is affected. Only one patched runtime restart was
performed. Lexi's runtime compatibility has not been tested, and the shared
Flutter SDK has not been modified or adopted.
Please review the transport-selection scope and expected transfer/performance
tradeoffs before deciding whether this should become an upstream change. This report describes a reproducible failure and a candidate workaround for maintainer review; it does not claim a general fix.
Activity
saurabh-mirajkar commentedon Oct 7, 2026
@systematique Thanks for the detailed report. I was able to reproduce this on Flutter 3.47.6 with an Apple Development-signed, sandboxed macOS app. Routing this to the macOS team for further investigation.
LouiseHsu commentedon Oct 8, 2026
@saurabh-mirajkar Could you bisect this to pinpoint which commit introduced this?
saurabh-mirajkar commentedon Oct 9, 2026
@LouiseHsu Hot reload works on Flutter stable 3.47.7 (
abaf9c5237), macOS 27.0.1, and Xcode 27.0 when Full Disk Access is enabled for Terminal.Before enabling it, hot restart failed with
main.dart.dillfile creation errors atLocalDevFSWriter.write()across several Flutter versions. This matches the workaround described in #148648 (comment).With this workaround, I couldn't establish a Flutter regression or identify a good/bad revision range.
vashworth commentedon Oct 14, 2026
@saurabh-mirajkar Can you undo the workaround and then try to bisect the issue?
saurabh-mirajkar commentedon Oct 15, 2026
@vashworth Verified on macOS with Flutter 3.47.7:
The issue was also tested with earlier Flutter versions (3.47.6, 3.47.2, 3.44.9, 3.41.9, 3.38.10, 3.35.5, 3.32.x, 3.29.3, and 3.27.4), with the failure reported across those versions.
The issue is reproducible in the sandboxed configuration. The underlying root cause and regression range remain undetermined.
LongCatIsLooong commentedon Oct 23, 2026
/cc @bkonyi from macOS triage for thoughts
LongCatIsLooong commentedon Oct 23, 2026
@saurabh-mirajkar could you provide the macOS version you tested this on?
saurabh-mirajkar commentedon Oct 26, 2026
macOS 27.0.1
[flutter_tools] Redirect macOS sandbox container DevFS to application…
cbracken commentedon Nov 5, 2026
/cc @vashworth @bkonyi
bkonyi commentedon Nov 6, 2026
Proposed fix here: #195328