Skip to content

feat(local): default LOCAL_ENGINE=auto to turbo-fieldfare on macOS 26+ with macOS 15 diffgemma fallback - #110

Merged
ghchinoy merged 2 commits into
GoogleCloudPlatform:mainfrom
ghchinoy:feat/default-local-engine-macos26
Dec 3, 2026
Merged

ghchinoy merged 2 commits into
GoogleCloudPlatform:mainfrom
ghchinoy:feat/default-local-engine-macos26

Conversation

@ghchinoy

@ghchinoy ghchinoy commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Addresses #108:

  • Sets LOCAL_ENGINE ?= auto in Makefile, resolved via scripts/detect_local_engine.sh:
    • macOS 26+ Apple Silicon (Metal 4): auto-selects turbo-fieldfare (which auto-sizes --expert-cache-slots 16 on <= 16 GB Macs and 128 on >= 24 GB Macs).
    • macOS 15 (Metal 3) / non-Darwin: automatically falls back to diffgemma.
    • Explicit opt-in: LOCAL_ENGINE=diffgemma or LOCAL_ENGINE=turbo-fieldfare always overrides auto-detection.
  • Updates make stop under LOCAL_ENGINE=auto to cleanly stop whichever local engine PID file (turbo-fieldfare.pid / diffgemma.pid) is running so switching engines never leaves an orphaned listener on :8080.
  • Adds scripts/test_local_engine_detect.py covering macOS 26+, macOS 15, Intel, Linux, explicit overrides, and invalid-engine exit code 2.

(Docs updates reflecting LOCAL_ENGINE=auto default are intentionally left for a clean follow-up after #109 merges to avoid conflicts on docs/deploy/laptop.md and docs/reference/metal-engine.md.)

Verification

  • bash -n scripts/detect_local_engine.sh
  • python3 -m unittest -v scripts/test_local_engine_detect.py (4/4 OK)
  • make local-status on macOS 26.7.3 Apple Silicon resolves LOCAL_ENGINE=auto -> turbo-fieldfare

@jigyasujuneja jigyasujuneja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two blockers should be resolved before switching LOCAL_ENGINE to auto by default:

  • The Makefile swallows exit code 2 on invalid LOCAL_ENGINE values and silently runs diffgemma (Makefile:60-66, 69-75, 78-84, 87-99, 114-115). GNU Make runs recipes with /bin/sh -c without set -e, so a failed ENGINE="$$(... detect_local_engine.sh)"; leaves ENGINE="", prints the error to stderr, falls into the else branch, and executes the diffgemma script with exit code 0. Reproduced locally with make LOCAL_ENGINE=bogus local-status (exited 0, printed LOCAL_ENGINE=bogus -> ). On main, invalid values exit 2. A typo like turbo_fieldfare on a 16 GB Mac would kick off an 18.8 GiB diffgemma download. Fix every recipe with || exit $$? and an explicit case:
    @ENGINE="$$(LOCAL_ENGINE="$(LOCAL_ENGINE)" ./scripts/detect_local_engine.sh)" || exit $$?; \
    echo "==> Resolved LOCAL_ENGINE=$$ENGINE (requested: $(LOCAL_ENGINE))"; \
    case "$$ENGINE" in \
      turbo-fieldfare) ./scripts/setup_turbo_fieldfare.sh ;; \
      diffgemma) ./scripts/setup_diffgemma.sh ;; \
      *) echo "Error: unexpected engine '$$ENGINE'" >&2; exit 2 ;; \
    esac
  • Unconditionally defaulting macOS 26+ Apple Silicon to turbo-fieldfare breaks fresh quickstarts and existing diffgemma installs (Makefile:57, scripts/detect_local_engine.sh:33-39). auto checks only OS, arch, and major version >= 26, with no check for installed binaries, .gturbo weights, or RAM. Upstream drumih/turbo-fieldfare does not contain TurboFieldfareDiffusionProbe, setup_turbo_fieldfare.sh:47-59 exits 1 without a local ../turbo-fieldfare-dgem checkout, and download_turbo_fieldfare.sh:43-51 has no downloader. Existing 32 GB+ diffgemma users on macOS 26+ also lose dgem ask plain chat, :think mode, and the 32,768 default context window (and hit the unaddressed #106 hardening gaps tracked in #112). Keep LOCAL_ENGINE ?= diffgemma until the fork and .gturbo pack have a public automated install, or restrict auto to choose turbo-fieldfare only when the probe binary and .gturbo pack already exist.

Additional items:

  • Wire scripts/test_local_engine_detect.py into .github/workflows/build.yml:84-105 (CI never runs it today), and add a Makefile-level test asserting make LOCAL_ENGINE=unknown-engine local-status exits 2.
  • Coordinate the default change with #109 (NOTICE and three docs pages in #109 still state diffgemma is the default and turbo-fieldfare is opt-in) and add an Unreleased changelog entry in the same PR that changes the default.
  • make stop (Makefile:88-95): detect_local_engine.sh:30 treats empty LOCAL_ENGINE="" as auto, but line 88 only checks [ "$(LOCAL_ENGINE)" = "auto" ], skipping dual-PID cleanup on LOCAL_ENGINE="". Also when STOPPED=0 (for example after make clean), running both idempotent stop scripts avoids leaving an unmanaged diffgemma serve running on macOS 26+.
  • scripts/detect_local_engine.sh:36: (( MAJOR >= 26 )) parses leading zeros as octal. Reproduced: DGEM_MACOS_VERSION_OVERRIDE=08.0 throws ((: 08: value too great for base, and 026.0 evaluates as decimal 22 (diffgemma). Switch to (( 10#$MAJOR >= 26 )).
  • Minor portability and quoting: use SYSTEM_VERSION_COMPAT=0 sw_vers -productVersion and sysctl -n hw.optional.arm64 so compatibility mode or Rosetta shells do not silently fall back to diffgemma. In Makefile, export LOCAL_ENGINE once and reference "$$LOCAL_ENGINE" instead of interpolating $(LOCAL_ENGINE) inside double quotes.

…+ with macOS 15 diffgemma fallback

Addresses GoogleCloudPlatform#108:
- Add scripts/detect_local_engine.sh resolving LOCAL_ENGINE=auto to
  turbo-fieldfare on macOS 26+ Apple Silicon (Metal 4, bimodal slots=16/128)
  and falling back to diffgemma on macOS 15 or non-Darwin hosts.
- Update Makefile so LOCAL_ENGINE defaults to auto while honoring explicit
  LOCAL_ENGINE=diffgemma or LOCAL_ENGINE=turbo-fieldfare overrides, and make
  stop cleanly shut down whichever engine PID file is active.
- Add scripts/test_local_engine_detect.py covering macOS 26+, macOS 15,
  x86_64, Linux, explicit overrides, and invalid engine rejection.
… turbo-fieldfare, and wire CI tests

Addresses all PR GoogleCloudPlatform#110 review items:
- Makefile: export LOCAL_ENGINE once, propagate detect_local_engine.sh exit
  status (|| exit $$?) with explicit case dispatch across every recipe,
  and handle empty LOCAL_ENGINE + STOPPED=0 in make stop.
- scripts/detect_local_engine.sh: gate LOCAL_ENGINE=auto selecting
  turbo-fieldfare on macOS 26+ Apple Silicon only when both
  TurboFieldfareDiffusionProbe and a .gturbo manifest.json are already
  installed (preserving fresh quickstarts and existing diffgemma setups);
  fix octal parsing with 10#$MAJOR; use SYSTEM_VERSION_COMPAT=0 sw_vers
  and sysctl hw.optional.arm64 Rosetta fallback.
- scripts/test_local_engine_detect.py + .github/workflows/build.yml: wire
  into CI, test octal versions (08.0, 026.0), installed vs uninstalled
  auto fallback, and Makefile invalid-engine non-zero exit.
- CHANGELOG.md: add Unreleased entry.
@ghchinoy

ghchinoy commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @jigyasujuneja — rebased onto main (post-#113) and addressed both blockers plus all 5 follow-ups:

  • Fail-fast Makefile recipes: Exported LOCAL_ENGINE once, added || exit $$? plus explicit case "9926ENGINE" dispatch on every recipe (setup, download, serve, stop, local-status), and added a Makefile-level unit test asserting make LOCAL_ENGINE=unknown-engine local-status exits non-zero with the error message.
  • Safe auto detection (no broken quickstarts or existing diffgemma installs): Restricted LOCAL_ENGINE=auto to select turbo-fieldfare on macOS 26+ Apple Silicon only when TurboFieldfareDiffusionProbe and a .gturbo pack (manifest.json) are already installed locally; otherwise auto falls back cleanly to diffgemma (explicit LOCAL_ENGINE=turbo-fieldfare or LOCAL_ENGINE=diffgemma still always overrides).
  • Octal & Rosetta/compat-mode fixes: Switched to (( 10#$MAJOR >= 26 )) (tested 08.0 and 026.0), SYSTEM_VERSION_COMPAT=0 sw_vers -productVersion, and sysctl -n hw.optional.arm64 fallback for Rosetta shells.
  • make stop edge cases: Handled empty LOCAL_ENGINE="" identically to auto and ran both idempotent stop scripts when STOPPED=0.
  • CI & Changelog: Wired scripts/test_local_engine_detect.py and bash -n scripts/detect_local_engine.sh into .github/workflows/build.yml and added an Unreleased entry to CHANGELOG.md.

Verified: bash -n scripts/detect_local_engine.sh and python3 -m unittest -v scripts/test_local_engine_detect.py (6/6 OK, including Makefile error-propagation test).

@ghchinoy
ghchinoy force-pushed the feat/default-local-engine-macos26 branch from d71904d to baec86b Compare December 2, 2026 16:02

@jigyasujuneja jigyasujuneja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both blockers and all five follow-ups are addressed cleanly: LOCAL_ENGINE is exported once, every Makefile target fails fast with || exit $$? and explicit case dispatch, auto selects turbo-fieldfare only when both TurboFieldfareDiffusionProbe and .gturbo manifest.json exist (matching scripts/serve_turbo_fieldfare.sh), octal parsing is fixed via 10#$MAJOR, SYSTEM_VERSION_COMPAT=0 and hw.optional.arm64 handle compatibility mode and Rosetta 2, make stop handles empty LOCAL_ENGINE and STOPPED=0, CI runs test_local_engine_detect.py and bash -n, and CHANGELOG.md has the Unreleased entry.

Nit (non-blocking, fine for a follow-up): all cases in scripts/test_local_engine_detect.py set DGEM_TURBO_READY_OVERRIDE. Adding one tempfile.TemporaryDirectory test with a stub executable TurboFieldfareDiffusionProbe and manifest.json (present vs. missing) would also exercise the real _turbo_fieldfare_installed path check.

CI checks are green (11 passed, 1 skipped). Approved.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants