Skip to content

macOS hot restart fails writing DevFS files into a sandboxed app container #193907

Description

@systematique

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 included app-sandbox, cs.allow-jit,
    get-task-allow, and network.server. The app was rebuilt/re-signed for the
    patched run, so its code-signature hash and signing timestamp changed.

Minimal reproduction

  1. Create a macOS Flutter app using the default counter-app source.
  2. 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.
  3. From the project root, run flutter run -d macos --verbose.
  4. 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.dart
  • packages/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, and devfs_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

  1. added
    in triage
    on Oct 7, 2026
  2. saurabh-mirajkar commented on Oct 7, 2026

    @saurabh-mirajkar
    Contributor

    @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.

  3. added
    tool
    platform-macos
    t: hot reload
    a: debugging
    a: desktop
    has reproducible steps
    team-macos
    and removed
    in triage
    on Oct 7, 2026
  4. LouiseHsu commented on Oct 8, 2026

    @LouiseHsu
    Contributor

    @saurabh-mirajkar Could you bisect this to pinpoint which commit introduced this?

  5. saurabh-mirajkar commented on Oct 9, 2026

    @saurabh-mirajkar
    Contributor

    @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.dill file creation errors at LocalDevFSWriter.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.

  6. vashworth commented on Oct 14, 2026

    @vashworth
    Contributor

    @saurabh-mirajkar Can you undo the workaround and then try to bisect the issue?

  7. saurabh-mirajkar commented on Oct 15, 2026

    @saurabh-mirajkar
    Contributor

    @vashworth Verified on macOS with Flutter 3.47.7:

    • Hot restart fails in the sandboxed reproduction app when Terminal Full Disk Access is disabled.
    • Hot restart succeeds in the same app when Terminal Full Disk Access is enabled.
    • Hot restart also succeeds in a separate non-sandboxed macOS app with Terminal Full Disk Access disabled.

    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.

  8. LongCatIsLooong commented on Oct 23, 2026

    @LongCatIsLooong
    Contributor

    /cc @bkonyi from macOS triage for thoughts

  9. LongCatIsLooong commented on Oct 23, 2026

    @LongCatIsLooong
    Contributor

    @saurabh-mirajkar could you provide the macOS version you tested this on?

  10. saurabh-mirajkar commented on Oct 26, 2026

    @saurabh-mirajkar
    Contributor

    @saurabh-mirajkar could you provide the macOS version you tested this on?

    macOS 27.0.1

  11. added
    P2
    fyi-tool
    found in release: 3.47
    on Nov 5, 2026
  12. cbracken commented on Nov 5, 2026

    @cbracken
    Member
  13. added
    triaged-macos
    on Nov 5, 2026
  14. self-assigned this
    on Nov 6, 2026
  15. bkonyi commented on Nov 6, 2026

    @bkonyi
    Contributor

    Proposed fix here: #195328

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2a: debugginga: desktopfound in release: 3.47fyi-toolhas reproducible stepsplatform-macost: hot reloadteam-macostooltriaged-macos

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions