Skip to content

Feature flags change on the same commit depending on local git branch name / detached HEAD #196916

Open

Description

@gmackall

Currently Flutter determines the channel from the local git branch name (git symbolic-ref --short HEAD), and any branch other than stable or beta (including detached HEAD, e.g. git checkout 3.50.0, or a custom local branch) becomes [user-branch] and falls back to master feature flag defaults:

String getBranchName({bool redactUnknownBranches = false}) {
_branch ??= () {
final String branch = _git
.runSync(['symbolic-ref', '--short', 'HEAD'], workingDirectory: flutterRoot)
.stdout
.trim();
return branch == 'HEAD' ? '' : branch;
}();
if (redactUnknownBranches || _branch!.isEmpty) {
// Only return the branch names we know about; arbitrary branch names might contain PII.
if (!kOfficialChannels.contains(_branch) && !kObsoleteBranches.containsKey(_branch)) {
return kUserBranch;
}
}
return _branch!;
}

FeatureChannelSetting getSettingForChannel(String channel) {
return switch (channel) {
'stable' => stable,
'beta' => beta,
'master' || _ => master,
};
}

This means the exact same commit can behave differently depending on how you checked it out, which is pretty confusing. Two places where this comes up:

  1. Pinned tag checkouts / reproducible builds (see Turn Hybrid Composition++ (HCPP) on by default #189939): checking out 3.50.0 directly puts you in detached HEAD ([user-branch]), which turns enable-hcpp on by default and injects <meta-data android:name="io.flutter.embedding.android.EnableHcpp" android:value="true"/> into AndroidManifest.xml, whereas building from the stable branch on the exact same commit omits it.
  2. Investigating a bug or bisecting on stable: branching off stable to investigate an issue (or running git bisect) can silently run with master feature flags (enable-hcpp, enable-riscv64, etc.) instead of stable's.

There is also what seems like a separate caching bug that makes this worse: bin/cache/flutter.version.json caches channel, and shared.sh/shared.bat only deletes it when the commit SHA changes and the tool rebuilds (

rm -f "$FLUTTER_ROOT/bin/cache/flutter.version.json"
). So if you branch off stable, you initially keep stable flags, and then making even an empty commit (or checking out another commit to rebuild the tool and coming back to your untouched branch) invalidates the cache and flips the flags underneath you.

Repro (on 3.50.0 / ab2912035e)
# Case 1: Branch off `stable`, then make a commit on the investigation branch.
# Initially `bin/cache/flutter.version.json` still caches `channel: stable`
# (same commit SHA), so the new branch keeps `stable` feature flags. Once any
# commit changes the SHA, the flutter tool rebuilds, invalidates
# `flutter.version.json`, detects channel `[user-branch]`, and silently flips
# to `master` defaults (`enable-riscv64` and `enable-hcpp` turn on underneath you).

mackall-mac2:flutter mackall$ git checkout stable
Switched to branch 'stable'
Your branch is up to date with 'upstream/stable'.
post-checkout: The engine source tree has been updated.

You may need to run "gclient sync -D"

mackall-mac2:flutter mackall$ flutter doctor -v | grep "Feature flags:"
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

mackall-mac2:flutter mackall$ git checkout -b hypothetically_investigate_stable_bug
Switched to a new branch 'hypothetically_investigate_stable_bug'
post-checkout: The engine source tree has been updated.

You may need to run "gclient sync -D"

mackall-mac2:flutter mackall$ flutter doctor -v | grep "Feature flags:"
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

mackall-mac2:flutter mackall$ git commit --allow-empty -m "nothing"
[hypothetically_investigate_stable_bug 7e11ab92d11] nothing

mackall-mac2:flutter mackall$ flutter doctor -v | grep "Feature flags:"
Building flutter tool...
Got dependencies.
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration, enable-riscv64, enable-hcpp



# Case 2: Comparing `stable` directly against checking out a custom branch or
# detached tag (e.g. `git checkout 3.50.0`) on the exact same commit without a
# pre-cached `stable` `flutter.version.json`.
#
# Removing `bin/cache/flutter.version.json` simulates either:
#   (a) a fresh checkout (e.g. CI / F-Droid builder checking out a tag directly), or
#   (b) checking out `stable` -> creating an investigation branch -> checking out
#       any other commit (rebuilding the tool and clearing `flutter.version.json`) ->
#       checking back out to your untouched investigation branch, which now behaves
#       differently (`enable-riscv64` and `enable-hcpp` enabled) with zero changes.

mackall-mac2:flutter mackall$ git checkout stable
Switched to branch 'stable'
Your branch is up to date with 'upstream/stable'.
post-checkout: The engine source tree has been updated.

You may need to run "gclient sync -D"

mackall-mac2:flutter mackall$ flutter doctor -v | grep "Feature flags:"
Building flutter tool...
Got dependencies.
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

mackall-mac2:flutter mackall$ git checkout -b again_hypothetically_do_work
Switched to a new branch 'again_hypothetically_do_work'
post-checkout: The engine source tree has been updated.

You may need to run "gclient sync -D"

mackall-mac2:flutter mackall$ rm -f bin/cache/flutter.version.json

mackall-mac2:flutter mackall$ flutter doctor -v | grep "Feature flags:"
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration, enable-riscv64, enable-hcpp

Activity

  1. added
    team-tool
    on Nov 18, 2026
  2. added
    P2
    triaged-tool
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2team-tooltriaged-tool

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions