# #42 M0: Implement Engine gate (S2.1) > **Date:** 2026-09-03 > **Type:** issue > **Reference:** https://git.babylondreams.de/AlexKucera/museion/issues/42 ## Goal Build the launch Engine gate exactly as specified by wayfinder map #12 (closed) and its seven child tickets #35–#41: discover the user-installed `hermes` binary via the six-path probe, health-check it with `acp --check`, version it with `acp --version`, record every completed check in `state.json`, and gate the app behind a blocking sheet on every launch — no decisions left to make. ## What Was Done - `Museion/EngineGate.swift` — `EngineProbe` (nonisolated): six-path absolute probe order, one iterate-until-pass loop over `acp --check` (stdin closed, 5 s per-candidate timeout, exit-status branching, first-candidate stderr on all-fail), SIGTERM→SIGKILL escalation + reap on timeout, `acp --version` with `unknown` fallback on failure, one `zsh -l -c 'command -v hermes'` last-resort fallback, schemaVersion-1 `state.json` written/wholesale-replaced after every completed check. `EngineGateModel` (@MainActor @Observable): phases, `onPass` seam for #13 provisioning, `beginAutomaticCheck()` once-per-app-launch guard. - `Museion/EngineGateView.swift` — the blocking sheet card: checking (spinner, no buttons) / pass (version + binary path + Start Writing) / fail (#40 copy verbatim: two install steps with copyable curl line, Re-check, collapsed Technical-details disclosure). - `Museion/MuseionApp.swift` — `AppGateState` (app-scoped; shared `gateModel` so ⌘N can't start a second concurrent check), About window via `CommandGroup(replacing: .appInfo)` + `openWindow` reading `state.json` read-only. - `Museion/ContentView.swift` — sheet wiring over the workspace. - `MuseionTests/EngineGateTests.swift` — 12 Swift Testing tests exercising the real `Process` path with runtime-built fake zsh `hermes` binaries. - DOX: engine-gate section in `Museion/AGENTS.md`, fake-binary test pattern in `MuseionTests/AGENTS.md`. ## Decisions & Rationale | Decision | Rationale | |----------|-----------| | About = `Window` + `CommandGroup(replacing: .appInfo)` | Verified against the macOS 26.5 swiftinterface: SwiftUI has no About scene on macOS. Two hallucinated modifiers (`.about`, `.aboutWindow`) failed to compile before the SDK check. | | Shared `AppGateState.gateModel` + `beginAutomaticCheck()` | Finish-audit found ⌘N during the gate bound two sheets to one flag → two models, two checks, two state.json writes, violating #41/#39. One shared model with a hasStarted guard fixes the class. | | SIGTERM + 0.5 s grace + SIGKILL + `waitUntilExit` | Audit MED: bare `terminate()` never reaped; a SIGTERM-ignoring child would live forever and the Process never waited. | | `version == "unknown"` on `acp --version` failure | Audit LOW: empty version rendered "Hermes answered" (double space). A failing version probe must not fail the gate (#35: health is --check's job). | | Sequential post-exit pipe reads (ponytail comment) | Swift 6 rejects capturing mutable vars in @Sendable reader closures; child output is one line or a bounded traceback, so post-exit reads are correct here with a named ceiling. | | Model in `AppGateState`, not `@State` in the view | Gate is app-scoped per #41; view-local state would re-create per window. | ## Gotchas & Fixes | Problem | Root Cause | Fix | |---------|------------|-----| | First subagent produced a syntactically corrupted test file (`# "expect"(…)`, duplicate args, invented identifiers) and never ran the build | Child hit its iteration cap; provider's 90 s non-streaming timeout killed its final generations (4 child deaths this session) | Rewrote tests in-parent; verified everything with real xcodebuild runs | | 3-reviewer finish-audit fanout died twice at caps, zero findings delivered | Same child timeout, triggered by long final reports | Retried with hard brevity caps (≤15/20/25 lines) — all three reports then landed | | `EngineProbe` implicitly MainActor-isolated; `Task.detached` couldn't call it | Project uses `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor` | `nonisolated enum` (SE-0449) on both probe enums | | Patches collided on overlapping matches, mangling braces twice | Rapid-fire fuzzy patches against adjacent regions | Full-file `write_file` rewrites, verified by the next build | | SwiftLint `nesting` on `CodingKeys` | Only violation; suppression comment | Deleted entirely in audit — synthesized CodingKeys are identical (optionals omit via encodeIfPresent) | ## Files Changed | File | Change Summary | |------|---------------| | `Museion/EngineGate.swift` | new — probe/check/version/state machinery + observable model | | `Museion/EngineGateView.swift` | new — blocking gate sheet, three cards | | `MuseionTests/EngineGateTests.swift` | new — 12 tests, fake-binary Process harness | | `Museion/MuseionApp.swift` | AppGateState, About window, appInfo replacement | | `Museion/ContentView.swift` | gate sheet wiring | | `Museion/AGENTS.md`, `MuseionTests/AGENTS.md` | DOX for the gate + test pattern | | `CHANGELOG.md` | Unreleased/Added entry | ## Open Items & Next Steps - [ ] #13 provisioning — wire into the `onEnginePass` seam (stub comment marks the spot) - [ ] #42 close + comment on the forge (verification data above) - [ ] CI note: XCUITest automation-mode timeout flake observed once locally; retry passed — watch for it when the macOS runner registers - [ ] #14 ACP bridge reads `state.json` (never checks) per #39 **Verification:** `xcodebuild build` + `test` green (12 unit + 1 UI, zero warnings), swiftformat + swiftlint clean, real app launch wrote `{"status":"pass","engineVersion":"0.20.6","binaryPath":"/Users/alex/.local/bin/hermes"}`, gitnexus detect-changes low-risk/expected symbols only, index 411→621 nodes. --- *Log written by write-log skill*