Skip to content

Strict Swift enforcement program (#9843) - #9855

Merged
Git-on-my-level merged 60 commits into
mainfrom
codex/strict-swift-9843
Jul 16, 2026
Merged

Git-on-my-level merged 60 commits into
mainfrom
codex/strict-swift-9843

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Strict Swift Enforcement Program (#9843)

20-ticket phased implementation: pinned/reproducible Swift tooling, safety-only SwiftLint, deterministic swift-format, strict concurrency, and Swift 6 language mode for the Omi desktop macOS app.

Status: Draft — Phase 1 complete (12/20 tickets), Ticket 13 complete.

Closes #9832.

Product invariants affected

  • INV-AUTH-1
  • INV-CHAT-1
  • INV-VOICE-1
  • INV-INT-1
  • INV-MEM-1

The formatter migration touched files under all five path globs. The new VoiceTurnDomain boundary changes the implementation of INV-VOICE-1 while preserving its behavior: voice lifecycle state has one owner, and drivers remain physical fact publishers rather than lifecycle owners. It does not change chat routing or backend semantics.

Phase 1 — Completed and Reviewed (Tickets 01-12, 19)

Rung 0: Deterministic Toolchain

  • Ticket 01: Pinned Xcode 16.4 (build 16F6), Package.resolved (23 pins), fail-closed selection, cache-key contract test (10 adversarial cases)
  • Ticket 02: swift-format 602.0.0 bootstrap wrapper, platform-aware manifest model (Check.platforms, macOS CI route, Ubuntu skip)
  • Ticket 03: Formatter config (2-space indent, 120-col), Generated/ exclusion, scope/config subcommands

Rung 1: Formatter + Linter Enforcement

  • Ticket 04: Mechanical formatter migration (560 files, idempotent, 54 source-inspection assertions updated, ratchet baselines adjusted)
  • Ticket 05: Pre-commit auto-format hook + macOS CI manifest enforcement (format idempotency check, 20 wrapper tests)
  • Ticket 06: SwiftLint 0.65.0 plugin on first-party targets (7 safety rules + 2 custom rules: asyncAfter + UserDefaults), baseline guard
  • Ticket 07: Down-only baseline guard (semantic-subset comparison), swiftlint:disable policy (named rule + reason required), 9 adversarial fixtures
  • Ticket 08: Replaced check-async-after-ratchet.py + check-userdefaults-key-ratchet.py with SwiftLint custom rules (equivalent fixture coverage)

Rung 2: Strict Leaf Targets

  • Ticket 10: OmiSupport strict (-strict-concurrency=complete + -warnings-as-errors, fixed 2 first! force unwraps)
  • Ticket 11: OmiWAL strict (zero diagnostics)
  • Ticket 12: OmiTheme strict (@MainActor on FontScaleSettings, Coordinator, resetWindowToDefaultSize)

Rung 3: Diagnostics + Tools

  • Ticket 09: Semantic feature sentinels (BareSlashRegexLiterals + strict-concurrency with negative control), advisory diagnostic ledger (fail-closed), index-store contract
  • Ticket 19: Periphery pilot — deferred verdict (binary incompatibility on pinned toolchain)

Phase 2 — In Progress (Tickets 14-18, 20)

  • Ticket 13 / FC-5: compiler-enforced voice-turn ownership — extract VoiceTurnDomain target, end the convergence churn #9832: Extracted the strict VoiceTurnDomain target. VoiceTurnEvent and VoiceTurnReducer are internal to the target; the app coordinator publishes typed VoiceTurnFact values and consumes read-only reductions. Reducer, PTT, transport, reconnect, and screen-evidence tests moved with the domain.
  • Ticket 14: Domain migration queue (migrate remaining domains to strict targets)
  • Ticket 15: Make executable target strict (-strict-concurrency=complete + -warnings-as-errors)
  • Ticket 16: Make test targets strict and blocking
  • Ticket 17: Enable Swift 5.10 language features
  • Ticket 18: Swift 6 language mode cutover
  • Ticket 20: Final audit — verify full contract closure

Root cause and durable guard

PTT, realtime, playback, and callback drivers could previously construct VoiceTurnEvent values and call the coordinator’s generic lifecycle entry point. That left lifecycle ownership dependent on convention, so future driver code could bypass the reducer boundary that recent chat and PTT fixes rely on.

The strict SwiftPM target makes the reducer and event type unrepresentable from the app target. VoiceTurnDomainBoundaryTests proves the fact façade works without @testable access and statically rejects app-source references to either internal type. Existing behavioral tests continue to exercise the allowed paths, including injected-clock deadlines, rapid PTT turns, reconnect, barge-in, output leases, screen escalation, and silent-mic recovery.

How it was verified

  • xcrun swift build -c debug --package-path Desktop --target 'Omi Computer' -Xlinker -L -Xlinker /opt/homebrew/opt/webp/lib
  • xcrun swift test -c debug --package-path Desktop --filter VoiceTurnDomainTests -Xlinker -L -Xlinker /opt/homebrew/opt/webp/lib — 109 tests passed
  • xcrun swift test -c debug --package-path Desktop --filter 'VoiceTurnCoordinatorTests|VoiceTurnOutputOwnershipTests|RealtimeHubBargeInContinuityTests|RealtimeHubSpawnAgentTests|PTTSilentTurnRecoveryWiringTests' -Xlinker -L -Xlinker /opt/homebrew/opt/webp/lib — 131 tests passed
  • python3 .github/scripts/test_run_checks.py, python3 .github/scripts/test_pr_preflight.py, python3 .github/scripts/test_swiftlint_config.py, and python3 desktop/macos/scripts/check-swiftlint-baseline.py --base origin/main passed
  • Built the named omi-voice-domain bundle through packaging. Launch was blocked because this machine has no development signing identity; ad-hoc signing was not used because it would reset Screen Recording permission for all Omi apps.

Tests

  • VoiceTurnDomainBoundaryTests covers the fact façade and compiler-enforced boundary.
  • Reducer/fuzz, PTT lifecycle, reconnect, and transport tests moved into VoiceTurnDomainTests so only domain tests can use internal event construction.
  • Coordinator/output/reconnect/agent-spawn/silent-mic suites cover the app-facing integration path.

Failure class (fixes)

Failure-Class: FC-split-mutation-authority

New guards

VoiceTurnDomainBoundaryTests is a narrow compiler-boundary guard for the lifecycle-owner failure in #9832. It is not a shared primitive because Swift target access control is the reusable enforcement mechanism; the test verifies this domain’s intentional exposure and the app-side source boundary.

@Git-on-my-level
Git-on-my-level force-pushed the codex/strict-swift-9843 branch 3 times, most recently from 0072c83 to dcb74ab Compare July 16, 2026 10:20
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Monitor summary — CI fix

Fixed two failing checks on this PR:

Desktop Swift Build & Tests — product-invariants failure

  • Desktop Swift CI ran run_checks.py without a PR body, causing the product-invariants check to fail on an empty body (the macOS runner has no GitHub API context to fetch the PR body).
  • Added --skip-pr-body-checks to the run_checks.py invocation in desktop-swift-ci.yml. Invariant citations are already validated by the Hygiene workflow via scripts/pr-preflight which fetches the actual PR body through the GitHub API.

Hygiene — desktop-manifest-routes failure

  • test_desktop_manifest_routes.py imported PyYAML at module level, but PyYAML is not available on CI runners (neither macOS nor Ubuntu).
  • Rewrote the test to parse the workflow file as raw text using the same regex patterns it already used for gate extraction and manifest-step detection, removing the PyYAML dependency entirely.

Verification

  • All 21 .github/scripts/test_*.py tests pass locally (including the rewritten test_desktop_manifest_routes.py).
  • run_checks.py --list --lane ci --platform macos --skip-pr-body-checks correctly excludes product-invariants while keeping desktop-manifest-routes.
  • CI: Desktop Swift Build & Tests ✅, Hygiene ✅ — all checks green.

@Git-on-my-level
Git-on-my-level force-pushed the codex/strict-swift-9843 branch from 3be117e to dc1f0c6 Compare July 16, 2026 15:12
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Monitor summary — CI fix (uv + format drift after rebase)

Fixed the Desktop Swift Build & Tests failure that appeared after rebasing onto current upstream main:

backend-route-policy-baseline — uv not installed on macOS runner

  • The Desktop Swift CI workflow runs the check manifest scoped to macOS. backend-route-policy-baseline triggers on backend/**/*.py (no platform restriction) and requires uv via openapi_runner.sh.
  • Without uv installed, the check failed immediately with "FAIL: uv is required for the OpenAPI runner."
  • Added astral-sh/setup-uv (same pinned commit as every other CI workflow that runs manifest checks) before the "Run macOS-scoped manifest checks" step.

swift-format drift in test files after rebase

  • PR fix(desktop): stabilize PTT agent routing #9859 landed new tests in RealtimeHubSpawnAgentTests.swift and PushToTalkStateMachineTests.swift with 4-space indentation; this PR's formatter uses 2-space. Re-applied the pinned formatter after resolving rebase conflicts.

Verification

  • All 37 manifest checks pass locally: run_checks.py --lane ci --platform macos --base origin/main --skip-pr-body-checks
  • actionlint clean on desktop-swift-ci.yml
  • Desktop Swift CI contract tests (10) and manifest-route tests (4) pass.

@Git-on-my-level
Git-on-my-level marked this pull request as ready for review July 16, 2026 15:38
@Git-on-my-level
Git-on-my-level force-pushed the codex/strict-swift-9843 branch from dc1f0c6 to 2eb5fdd Compare July 16, 2026 16:33
CI and others added 22 commits July 16, 2026 15:04
Ticket 01 of #9843 strict Swift enforcement program.

Pin Xcode 16.4 (build 16F6) in both desktop-swift-ci.yml jobs: select
/Applications/Xcode_16.4.app, fail closed if absent, assert version+build,
and print xcodebuild/xcrun versions before every Swift action.

Commit Desktop/Package.resolved (23 pins) — unignored via negation rule
in .gitignore. The lockfile makes dependency resolution deterministic;
both debug and release builds select the same toolchain.

Cache key now includes Package.swift + Package.resolved hashes and a
toolchain identity component (xcode164) so a dependency-graph or Xcode
change invalidates the cache.

Release-compile gating now triggers on Package.resolved changes (not
just Package.swift), since a dependency-graph change can break release
builds even when the manifest source is unchanged.

Contract test (.github/scripts/test_desktop_swift_ci_contract.py) fails
if either CI job loses Xcode selection/version assertion/logging or if
the cache key omits manifest, lockfile, or toolchain identity. Includes
adversarial tests that verify removal of each guard is detected.

Verification:
- test_desktop_swift_ci_contract.py: 9/9 pass
- test_run_checks.py (manifest validity): 9/9 pass
- actionlint: clean
- Package.resolved: 23 pins, all within declared ranges
Terra review fix for Ticket 01 (#9843): the release-compile
PACKAGE_RESOLVED gate test only checked for substring presence,
missing the main bypass — removing the SHOULD_RUN gate condition
while keeping other references kept all tests green.

Now asserts the gate condition ('$PACKAGE_RESOLVED' = "true") is
present in the SHOULD_RUN conditional, plus an adversarial test that
removes the gate and verifies detection.
Ticket 02 of #9843 strict Swift enforcement program.

Build a pinned swift-format bootstrap wrapper
(scripts/swift-format-wrapper.sh) that resolves exact source tag 602.0.0
at commit 62eaad2822b865407b8cde56c36386c00800f7ec, builds with the pinned
Xcode, caches by source+toolchain identity, verifies the emitted version,
and never invokes a moving runner binary. Provides lint (--strict),
format, version, digest, and binary-path subcommands.

Extend the deterministic check-manifest model with explicit platform
capability: Check.platforms field, detect_platform() auto-detection,
resolve_checks platform filtering, skipped_platform_checks reporting,
and validation of platform values. The Ubuntu hygiene lane reports
intentional platform skips; desktop-swift-ci.yml invokes the manifest
CI lane with --platform macos so macOS-only checks have an executable
CI route.

Contract tests:
- test_run_checks.py: 6 new PlatformTests (15 total)
- test_desktop_manifest_routes.py: cross-workflow route test (4 tests)
  verifies every macOS-scoped check has a trigger path reaching the macOS
  workflow's changed-file gate, including an adversarial stranded-check case
- test-swift-format-wrapper.sh: 10 wrapper unit tests (pinned constants,
  subcommand dispatch, fail-closed behavior)
- desktop-swift-ci.yml gate updated to include manifest/checker paths

Verification:
- test_run_checks.py: 15/15 pass
- test_desktop_swift_ci_contract.py: 10/10 pass
- test_desktop_manifest_routes.py: 4/4 pass
- test-swift-format-wrapper.sh: 10/10 pass
- actionlint: clean
- make preflight: 14/14 checks pass
Ticket 03 of #9843 strict Swift enforcement program.

Define Desktop/.swift-format configuration matching the repo's actual
2-space indentation style with 120-column line length (verified against
the codebase; defaults produce 111K diagnostics excluding Generated/).

Decide generated-source policy: Desktop/Sources/Generated/ (5 files) is
excluded from the formatter scope everywhere — wrapper, config, and
future pre-commit/CI wiring. The wrapper gains scope, config-path, and
config-aware lint/format subcommands.

Fixtures verify: config is valid JSON with correct settings (lineLength
120, indentation 2 spaces, tabWidth 2), scope excludes Generated/ while
including all hand-written first-party Swift + Tests/, and the wrapper
passes the pinned config to lint/format commands.

Update root AGENTS.md formatting table with the Swift row and generated-
source exclusion note. Add Swift Formatting section to desktop AGENTS.md
with bootstrap and lint instructions.

Generator freshness checks (test-tool-surfaces.sh,
generate_swift_openapi_types.py --check) agree with the exclusion policy.

Verification:
- test-swift-format-wrapper.sh: 16/16 pass
- generate_swift_openapi_types.py --check: pass
- make preflight: 15/15 checks pass
Terra review fix for Ticket 03 (#9843): the spec requires four fixture
categories including 'no writes in lint mode.' Added a static assertion
extracting the lint case body and verifying it contains no --in-place/-i
flag, guarding against a future change that adds file mutation to lint.
Ticket 05 of #9843 strict Swift enforcement program.

Enforce pinned swift-format in pre-commit and macOS CI:

Pre-commit hook: staged Desktop/**/*.swift files (excluding Generated/)
are auto-formatted and re-staged. Contributors get an actionable bootstrap
failure if xcrun is unavailable.

macOS CI manifest: desktop-swift-format-lint (platforms: [macos]) verifies
format idempotency on the full scope. Uses format-to-stdout + diff rather
than lint --strict because the lint command also reports advisory rules the
formatter cannot auto-fix (AlwaysUseLowerCamelCase, ReplaceForEachWithForLoop,
etc.) — true formatting drift is what enforcement must catch.

The lint command is identical locally and in macOS CI (same wrapper, same
config, same binary). The Ubuntu lane skips this check via the platform
filter from Ticket 02.

Fixtures: malformed Swift fails lint; format corrects it; lint passes after
format (3 new enforcement fixtures, 20 total).

Verification:
- test-swift-format-wrapper.sh: 20/20 pass
- lint-scope on clean tree: PASS (no formatting drift)
- make preflight: 16 checks pass (lint-scope is macOS-only, skipped locally)
Ticket 06 of #9843 strict Swift enforcement program.

Pin SimplyDanny/SwiftLintPlugins 0.65.0 (bundling SwiftLint 0.65.0) as
an exact SPM dependency. Attach the SwiftLintBuildToolPlugin to all 5
first-party Swift targets (OmiSupport, OmiTheme, OmiWAL, executable,
tests). ObjCExceptionCatcher and CWebP are excluded.

Create Desktop/.swiftlint.yml with only_rules for exactly the 7 safety
rules (force_unwrapping, force_try, force_cast,
implicitly_unwrapped_optional, fatal_error_message, legacy_random,
weak_delegate) plus custom_rules absorbing the two proven regex ratchets
(omi_floating_control_bar_async_after, omi_inline_userdefaults_key).
No strict: true.

Generate .swiftlint-baseline.json (843 violations) after Ticket 04
formatting. The baseline captures existing violations; the build-tool
plugin filters them, so only NEW violations are reported.

Config validation test (8 tests) verifies: only_rules exact set,
custom_rules regex patterns, baseline exists and is valid JSON array,
no strict mode, plugin attached to exactly 5 targets, ObjC/CWebP excluded.

Verification:
- test_swiftlint_config.py: 8/8 pass
- swift build --target OmiSupport: PASS (SwiftLint plugin executes,
  warnings shown and filtered by baseline)
- make preflight: all checks pass (e2e carry-over from Ticket 04)
Terra review fix for Ticket 06 (#9843):
1. Regex now uses negative lookbehind (?<!removeValue\() to filter
   Dictionary.removeValue(forKey:) false positives (18 removed from baseline)
2. Excluded path corrected from Sources/OmiSupport/DefaultsKey.swift
   (nonexistent) to Sources/DefaultsKey.swift (actual location)

Baseline regenerated: 825 violations (was 843).
Ticket 07 of #9843 strict Swift enforcement program.

Add a portable Python guard (check-swiftlint-baseline.py) that:

1. Compares baseline records semantically against the merge-base version.
   Candidate entries must be a subset of base entries — additions fail,
   removals pass. File paths are normalized from absolute file:// URLs to
   relative paths for cross-machine comparison. Bootstrap mode allows the
   initial baseline-introducing commit.

2. Enforces swiftlint:disable policy: every suppression must name a rule,
   have a local reason (-- ...), and not be a blanket disable. Net new
   suppressions are rejected by comparing against the base count.

Adversarial fixtures (9 tests) cover: addition (rejected), removal (allowed),
reorder (allowed), blanket disable (rejected), disable without reason
(rejected), multi-rule without reason (rejected), valid reasoned suppression
(accepted), absolute path normalization, same-file-different-line identity.

The guard is portable (pure Python). The macOS lint producer (SwiftLint
binary) remains platform-routed via the manifest.

Verification:
- test_swiftlint_baseline_guard.py: 9/9 pass
- check-swiftlint-baseline.py --base origin/main --bootstrap: OK
- make preflight: all checks pass (e2e carry-over from Ticket 04)
Ticket 08 of #9843 strict Swift enforcement program.

Delete check-async-after-ratchet.py and check-userdefaults-key-ratchet.py
plus their manifest entries and detect-changes references. The SwiftLint
custom_rules from Ticket 06 provide equivalent-or-stricter coverage:

- omi_floating_control_bar_async_after: 22 violations (matches ratchet
  baseline of 22). Scoped to FloatingControlBar via included paths.
- omi_inline_userdefaults_key: 284 violations (ratchet baseline was 173;
  SwiftLint is broader — catches every forKey: occurrence, not deduped
  by key). 0 setValue(forKey: false positives exist in the codebase.
  removeValue(forKey:) excluded via negative lookbehind.

Both rules are backed by the down-only baseline guard (Ticket 07) which
rejects new violations and enforces reasoned swiftlint:disable policy.

check_desktop_test_quality.py preserved — it does non-trivial lexical
work (string/comment masking, token spans) not replaceable by regex lint.

Cleaned up detect-changes/action.yml: removed has_desktop_defaults_ratchet
and has_desktop_async_after_ratchet outputs (no longer produced or consumed).

Verification:
- test_run_checks.py: 15/15 pass (manifest valid after deletion)
- check_desktop_test_quality.py: pass
- No remaining references to deleted scripts
- make preflight: all checks pass (e2e carry-over from Ticket 04)
Terra review fix for Ticket 08 (#9843): DefaultsKey.swift and
FloatingBarTimingSignalTests.swift referenced the deleted
check-userdefaults-key-ratchet.py and check-async-after-ratchet.py.

Updated to reference the SwiftLint custom rules and baseline instead.
Also corrected asyncAfterBaseline from 23 to 22.
Ticket 09 of #9843 strict Swift enforcement program.

Semantic feature sentinels: a dedicated SemanticFeatureSentinels test
target proves BareSlashRegexLiterals and -strict-concurrency=complete
are active on the pinned toolchain. A bare-slash regex literal compiles
only with the feature enabled; a non-Sendable capture test verifies the
strict concurrency target setting. The target is excluded from the parent
Omi ComputerTests to compile exactly once.

Negative control: test-feature-sentinel-negative-control.sh creates a
minimal SwiftPM package with a deliberately fake feature name
('ThisFeatureDoesNotExist12345') and proves SwiftPM silently accepts it
— the critical trap from #9843. Fake strictness is worse than none.

Advisory diagnostic ledger: swift-diagnostic-ledger.py builds the
executable with -Xswiftc -strict-concurrency=complete and publishes
normalized first-party diagnostics grouped by module/path. Report-only,
no fake baseline, no warnings-as-errors. The output becomes the
authoritative queue for domain migrations (Tickets 10-14).

Index-store contract: swift-index-store.sh builds tests once with an
explicit index-store path and emits a marker keyed by toolchain/lockfile.
Periphery (Ticket 19) consumes this path with --skip-build.

Verification:
- Sentinel target builds: PASS (6.42s)
- Negative control: 1/1 pass (proves silent acceptance)
- test_swiftlint_config.py: 8/8 pass (updated for 6 plugin attachments)
- test_run_checks.py: 15/15 pass (manifest valid)
- make preflight: all checks pass (e2e carry-over from Ticket 04)
Terra review fix for Ticket 09 (#9843):

1. StrictConcurrencySentinelTests: replaced @unchecked Sendable MutableBox
   (which compiled identically with/without the flag) with a real
   NonSendableBox captured in Task.detached. Under complete checking, this
   produces a non-Sendable/data-race warning. The companion shell test
   verifies the warning IS produced — if the flag is removed, the warning
   disappears and the test fails. This closes the 'fake strictness' trap.

2. Diagnostic ledger: added fail-closed check — if build output contains
   diagnostic-looking lines (:line:col: warning/error:) but the parser
   captured 0, the format may have changed and the script returns 1
   instead of silently reporting zero diagnostics.

3. Sentinel test now has both positive (warning produced) and negative
   (fake feature accepted) controls.
Ticket 10 of #9843 strict Swift enforcement program.

Apply -strict-concurrency=complete and -warnings-as-errors to the
OmiSupport library target. Zero diagnostics under the pinned toolchain.

Create OmiSupportTests target with the same strict settings. Move
DictionaryDeduplicationTests from the parent Omi ComputerTests target
to OmiSupportTests, excluding the directory from the parent to ensure
single compilation.

Fix two force-unwrap violations in DesktopLocalProfile.swift:
- applicationSupportURL(): .first! → guard let + fatalError
- cachesURL(): .first! → guard let + fatalError
These use descriptive fatalError messages (not behavior suppression)
because the directories are system invariants on macOS.

No @unchecked Sendable, nonisolated(unsafe), @preconcurrency, or
behavior suppression used.

Verification:
- OmiSupport build with strict+Werror: PASS (zero diagnostics)
- OmiSupportTests build with strict+Werror: PASS
- Full debug build: PASS (78.36s)
- test_swiftlint_config.py: 8/8 pass (updated for 7 plugin attachments)
Ticket 11 of #9843 strict Swift enforcement program.

Apply -strict-concurrency=complete and -warnings-as-errors to the OmiWAL
library target. Zero diagnostics under the pinned toolchain.

Create OmiWALTests target with the same strict settings. Move
WALModelTests from the parent Omi ComputerTests target to OmiWALTests,
excluding the directory from the parent to ensure single compilation.
App-dependent sync/upload/Wi-Fi tests (WALCloudSyncLogicTests,
WALServiceUploadTests, etc.) remain in the parent test target.

WALEntry Codable/defaulting and filename normalization preserved exactly.

Verification:
- OmiWAL build with strict+Werror: PASS (zero diagnostics)
- OmiWALTests build with strict+Werror: PASS
- Full debug build: PASS
- test_swiftlint_config.py: 8/8 pass (updated for 8 plugin attachments)
Ticket 12 of #9843 strict Swift enforcement program.

Apply -strict-concurrency=complete and -warnings-as-errors to the OmiTheme
library target. Zero diagnostics after fixing real concurrency issues:

1. FontScaleSettings (OmiFont.swift:7): marked @mainactor — it's an
   ObservableObject singleton with mutable state observed by SwiftUI views.
   Keeping it main-actor owned (per spec) makes the static 'shared' property
   concurrency-safe.

2. resetWindowToDefaultSize (OmiFont.swift:92): marked @mainactor — accesses
   NSApp.keyWindow and NSApp.windows, which are main-actor isolated.

3. Coordinator (OmiTextEditor.swift:227): marked @mainactor — NSObject/
   NSTextViewDelegate subclass that accesses layoutManager, textContainer,
   and textContainerInset (all main-actor isolated). The DispatchQueue.main.async
   capture of self is now safe because Coordinator is main-actor isolated.

No @preconcurrency, @unchecked Sendable, nonisolated(unsafe), broad actor
removal, or detached fire-and-forget used. All fixes keep UI state main-actor
owned and move only immutable value snapshots across boundaries.

No direct OmiTheme test target created — existing Theme-dependent tests
(AgentPillLifecycleTests, DashboardCaptureStateTests, DesktopChatDriftGuardTests)
require @testable import of the full app target and cannot be isolated.

Verification:
- OmiTheme build with strict+Werror: PASS (zero diagnostics)
- Full debug build: PASS (41.51s)
- All three strict leaf targets: PASS (OmiSupport, OmiWAL, OmiTheme)
…ator

Terra review fix for Ticket 12 (#9843): replaced DispatchQueue.main.async
with Task { @mainactor [weak self] in } in updateMarkedTextState to match
the codebase convention (zero DispatchQueue.main.async calls in strict
targets) and be explicit about main-actor isolation. Preserves the
deferred-to-main semantics.
Ticket 19 of #9843: Periphery 2.21.2 binary fails to initialize on this
environment. Verdict: deferred (non-promotion). Advisory operation
retained. Decision record: Desktop/.periphery-pilot-verdict.json
Move the voice lifecycle reducer, event model, and mutable state into a strict SwiftPM target. App drivers publish typed facts through the coordinator instead of constructing lifecycle events directly.

Root cause: mutation authority was convention-based across PTT, realtime, and playback drivers. Guard: target-internal reducer/event types plus a public fact facade and boundary regression test.

Verification: debug app build; 109 VoiceTurnDomain tests; 131 coordinator/PTT integration tests; selected preflight contracts.
Record exact line counts after the pinned swift-format migration and the strict VoiceTurnDomain move.
Keep PR preflight path gates aligned with scripts/changed-files so baseline removals are tied to renamed sources.
Preserve deferred-work enforcement for actual comments while ignoring ordinary todo values and formatter-only rewrites.
Git-on-my-level and others added 24 commits July 16, 2026 15:06
Desktop Swift CI runs run_checks.py without a PR body (macOS runners
have no GitHub API context), causing product-invariants to fail on an
empty body. Add --skip-pr-body-checks since the Hygiene workflow
already validates invariant citations via scripts/pr-preflight.

The desktop-manifest-routes test imported PyYAML, which is not
available on CI runners (neither macOS nor Ubuntu). Rewrite it to parse
the workflow file as text using regex, matching the same patterns the
test already used for gate extraction and manifest detection.

Failure-Class: new
Activate -strict-concurrency=complete and -warnings-as-errors on
the Omi Computer executable target. Fix all concurrency diagnostics
including Sendable conformances, @preconcurrency imports/protocols,
nonisolated(unsafe) for deinit access, @unchecked Sendable boxes for
non-Sendable values crossing actor boundaries, and KeyPath retroactive
Sendable conformance for AttributedString attribute scopes.

All 2628 tests pass.
…notations

Ticket 14 strict concurrency annotations (Sendable conformances, actor
isolation qualifiers) grew 19 product source files beyond the ratchet
baseline. Update each entry with a justification noting the growth is
from compile-time annotations, not runtime behavior changes.

Failure-Class: none
…concurrency

LocalAgentTool carries non-Sendable [String: Any] fields, so the static
`localAgentAPITools` manifest is non-Sendable shared state and fails strict
concurrency. Apply nonisolated(unsafe) (mirroring the existing pattern at
LocalAgentAPIServer.swift:562) in both the generator template and the generated
output. This latent violation was masked by incremental build cache; a clean
build of the (already-strict) executable surfaces it and blocks the test target.
Add -strict-concurrency=complete + -warnings-as-errors to the Omi ComputerTests
target in Package.swift, and resolve the resulting Swift 6 diagnostics across the
test suite (2628 tests, all passing). Recurring fixes:
- @mainactor on test classes touching MainActor-isolated production types, with
  setUp()/tearDown() promoted to the async throws variants (which inherit
  MainActor isolation, unlike the nonisolated sync overrides).
- nonisolated(unsafe) on lock-guarded mutable static stubs.
- @unchecked Sendable Box holders for locals captured/mutated in escaping closures.
- @mainactor / nonisolated(unsafe) on Sendable-conforming Fake mocks.
- Sendable boxing for UserDefaults and other non-Sendable values crossing actors,
  and region-safe handoffs for URLProtocol fixtures.
- Package.swift: swift-tools-version 6.0, swiftLanguageModes: [.v6];
  drop now-redundant BareSlashRegexLiterals upcoming-feature flag
- Fix Swift 6 deprecations: String(validatingUTF8:) -> validatingCString
  (7 sites) and String(cString: [CChar]) -> pointer-based init
- Remove unnecessary nonisolated(unsafe) on Sendable constant
  (OmiToolManifest) + keep the generator in sync
- Make DesktopCoordinatorRuntimeControlling / AgentArtifactProjectionLoading
  Sendable and drop @preconcurrency; thread [String:Any] payloads via the
  @unchecked Sendable RuntimeJSONPayloadBox so they can cross isolation
- Fix ChatDraftStore runtime isolation trap: a @mainactor dispatch block ran
  on the persistence queue; make persist/fileNameComponent nonisolated and
  the dispatch closures @sendable
- Marshal off-main test callbacks to MainActor (FakeSuggestedTasksClient)
  and box non-Sendable UserDefaults across the owner-transition boundary
  (PushToTalkStateMachineTests)
- Rewrite the strict-concurrency sentinel for Swift 6 (compile-only canary)
  and its companion shell test to assert the declared mode and that Swift 6
  rejects non-isolated global mutable state

All 2628 tests pass with zero diagnostics.
The Desktop Swift CI workflow runs the check manifest scoped to macOS.
backend-route-policy-baseline triggers on backend/**/*.py (no platform
restriction) and requires uv via openapi_runner.sh. Without uv installed,
the check fails immediately. Every other CI workflow that runs manifest
checks already installs uv via astral-sh/setup-uv.

Also corrects swift-format drift in PushToTalkStateMachineTests.swift
after rebase onto upstream main (PR #9859 added new tests with 4-space
indentation).
Resolve the post-ticket rebase defects and make the strict Swift CI checks executable: lint the handwritten desktop sources with a pinned SwiftLint wrapper, cache both formatter and linter bootstrap artifacts, use the final computed workflow diff base, and avoid SIGABRT from a closed version-command pipe. Preserve the accepted main-branch PTT behavior while eliminating unchecked AppKit image transfers across actors.\n\nVerification:\n- OMI_SWIFT_TEST_SUITE_WORKERS=4 ./scripts/swift-test-suites.sh (300 isolated Swift suites)\n- python3 .github/scripts/run_checks.py --lane ci --platform macos --base origin/main --skip-pr-body-checks (37 checks)\n- make preflight (39 checks)
Replace the cache-miss source build with SwiftLint's pinned universal macOS release artifact. Verify both the release ZIP and extracted executable SHA-256, reject symlinked or tampered cache entries before execution, and retain the exact version/config/baseline lint behavior.\n\nVerification:\n- Fresh-cache full 745-file lint: 1.75s (previous source bootstrap: 349.43s)\n- python3 .github/scripts/test_swiftlint_config.py (12 tests, including tampered-cache negative control)\n- make preflight (39 checks)
The semantic feature sentinel already touches its source to force recompilation. Removing the target build directory afterward deletes SwiftPM's output-file map while its build-plan metadata still references it, which made pre-push runs intermittently fail.\n\nVerification:\n- bash desktop/macos/tests/test-feature-sentinel-negative-control.sh (twice)\n- make preflight (39 checks)
SwiftLint baseline locations are absolute and previously stopped matching GitHub's checkout, exposing the 843 grandfathered violations. Rebase only verified Desktop-relative file URLs into a temporary baseline for the active checkout; malformed baseline records fail closed.

Tests: make preflight (39 checks, 132.60s); bash desktop/macos/scripts/swiftlint-wrapper.sh lint --no-cache; python3 .github/scripts/test_swiftlint_config.py
Remove only direct XCTestCase lifecycle calls that transfer @mainactor test instances across the Xcode 16.4 non-Sendable boundary, while retaining each suite's own setup and teardown.\n\nAdd a fixture-tested manifest guard before the full Swift build and save SwiftPM state after failed test attempts so retrying diagnostics can reuse validated incremental work.\n\nVerified: desktop/macos/scripts/swift-test-suites.sh (300 suites, 4 workers); actionlint .github/workflows/desktop-swift-ci.yml; targeted guard and workflow contract tests.
The Xcode 16.4 compiler rejects transferring NSImage from the RewindStorage actor to XCTest. Extract the frame's center pixel inside the actor and return a Sendable value to preserve the frame-selection and missing-frame behavior tests.\n\nVerified: xcrun swift test --package-path Desktop --skip-build --filter 'RewindStorageVideoFrameExtractionTests/' (7 passed); make preflight.
Apply the pinned swift-format output to files retained from main during conflict resolution and update the AppsPage line-count ratchet to the exact formatted size.\n\nVerified: desktop/macos/scripts/swift-format-wrapper.sh lint-scope.
@Git-on-my-level
Git-on-my-level force-pushed the codex/strict-swift-9843 branch from 7303c2c to 53982ce Compare July 16, 2026 19:20
AppDetailSheet is main-actor-isolated through SwiftUI, but its primary-action policy is a pure Bool-to-enum mapping used by synchronous XCTest. Mark the helper nonisolated so Xcode 16.4 can compile the regression test without weakening UI isolation.\n\nVerified: xcrun swift test --package-path Desktop --skip-build --filter 'AppsPagePrimaryActionTests/' (3 passed).
@Git-on-my-level
Git-on-my-level merged commit 79bdd79 into main Jul 16, 2026
31 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/strict-swift-9843 branch July 16, 2026 20:00
undivisible pushed a commit to undivisible/omi that referenced this pull request Sep 29, 2026
…9855)

## Strict Swift Enforcement Program (BasedHardware#9843)

20-ticket phased implementation: pinned/reproducible Swift tooling,
safety-only SwiftLint, deterministic swift-format, strict concurrency,
and Swift 6 language mode for the Omi desktop macOS app.

**Status: Draft — Phase 1 complete (12/20 tickets), Ticket 13
complete.**

Closes BasedHardware#9832.

## Product invariants affected

- INV-AUTH-1
- INV-CHAT-1
- INV-VOICE-1
- INV-INT-1
- INV-MEM-1

The formatter migration touched files under all five path globs. The new
VoiceTurnDomain boundary changes the implementation of `INV-VOICE-1`
while preserving its behavior: voice lifecycle state has one owner, and
drivers remain physical fact publishers rather than lifecycle owners. It
does not change chat routing or backend semantics.

## Phase 1 — Completed and Reviewed (Tickets 01-12, 19)

### Rung 0: Deterministic Toolchain

- **Ticket 01:** Pinned Xcode 16.4 (build 16F6), `Package.resolved` (23
pins), fail-closed selection, cache-key contract test (10 adversarial
cases)
- **Ticket 02:** swift-format 602.0.0 bootstrap wrapper, platform-aware
manifest model (`Check.platforms`, macOS CI route, Ubuntu skip)
- **Ticket 03:** Formatter config (2-space indent, 120-col),
`Generated/` exclusion, scope/config subcommands

### Rung 1: Formatter + Linter Enforcement

- **Ticket 04:** Mechanical formatter migration (560 files, idempotent,
54 source-inspection assertions updated, ratchet baselines adjusted)
- **Ticket 05:** Pre-commit auto-format hook + macOS CI manifest
enforcement (format idempotency check, 20 wrapper tests)
- **Ticket 06:** SwiftLint 0.65.0 plugin on first-party targets (7
safety rules + 2 custom rules: asyncAfter + UserDefaults), baseline
guard
- **Ticket 07:** Down-only baseline guard (semantic-subset comparison),
`swiftlint:disable` policy (named rule + reason required), 9 adversarial
fixtures
- **Ticket 08:** Replaced `check-async-after-ratchet.py` +
`check-userdefaults-key-ratchet.py` with SwiftLint custom rules
(equivalent fixture coverage)

### Rung 2: Strict Leaf Targets

- **Ticket 10:** OmiSupport strict (`-strict-concurrency=complete` +
`-warnings-as-errors`, fixed 2 `first!` force unwraps)
- **Ticket 11:** OmiWAL strict (zero diagnostics)
- **Ticket 12:** OmiTheme strict (`@MainActor` on `FontScaleSettings`,
`Coordinator`, `resetWindowToDefaultSize`)

### Rung 3: Diagnostics + Tools

- **Ticket 09:** Semantic feature sentinels (`BareSlashRegexLiterals` +
strict-concurrency with negative control), advisory diagnostic ledger
(fail-closed), index-store contract
- **Ticket 19:** Periphery pilot — deferred verdict (binary
incompatibility on pinned toolchain)

## Phase 2 — In Progress (Tickets 14-18, 20)

- **Ticket 13 / BasedHardware#9832:** Extracted the strict `VoiceTurnDomain` target.
`VoiceTurnEvent` and `VoiceTurnReducer` are internal to the target; the
app coordinator publishes typed `VoiceTurnFact` values and consumes
read-only reductions. Reducer, PTT, transport, reconnect, and
screen-evidence tests moved with the domain.
- **Ticket 14:** Domain migration queue (migrate remaining domains to
strict targets)
- **Ticket 15:** Make executable target strict
(`-strict-concurrency=complete` + `-warnings-as-errors`)
- **Ticket 16:** Make test targets strict and blocking
- **Ticket 17:** Enable Swift 5.10 language features
- **Ticket 18:** Swift 6 language mode cutover
- **Ticket 20:** Final audit — verify full contract closure

## Root cause and durable guard

PTT, realtime, playback, and callback drivers could previously construct
`VoiceTurnEvent` values and call the coordinator’s generic lifecycle
entry point. That left lifecycle ownership dependent on convention, so
future driver code could bypass the reducer boundary that recent chat
and PTT fixes rely on.

The strict SwiftPM target makes the reducer and event type
unrepresentable from the app target. `VoiceTurnDomainBoundaryTests`
proves the fact façade works without `@testable` access and statically
rejects app-source references to either internal type. Existing
behavioral tests continue to exercise the allowed paths, including
injected-clock deadlines, rapid PTT turns, reconnect, barge-in, output
leases, screen escalation, and silent-mic recovery.

## How it was verified

- `xcrun swift build -c debug --package-path Desktop --target 'Omi
Computer' -Xlinker -L -Xlinker /opt/homebrew/opt/webp/lib`
- `xcrun swift test -c debug --package-path Desktop --filter
VoiceTurnDomainTests -Xlinker -L -Xlinker /opt/homebrew/opt/webp/lib` —
109 tests passed
- `xcrun swift test -c debug --package-path Desktop --filter
'VoiceTurnCoordinatorTests|VoiceTurnOutputOwnershipTests|RealtimeHubBargeInContinuityTests|RealtimeHubSpawnAgentTests|PTTSilentTurnRecoveryWiringTests'
-Xlinker -L -Xlinker /opt/homebrew/opt/webp/lib` — 131 tests passed
- `python3 .github/scripts/test_run_checks.py`, `python3
.github/scripts/test_pr_preflight.py`, `python3
.github/scripts/test_swiftlint_config.py`, and `python3
desktop/macos/scripts/check-swiftlint-baseline.py --base origin/main`
passed
- Built the named `omi-voice-domain` bundle through packaging. Launch
was blocked because this machine has no development signing identity;
ad-hoc signing was not used because it would reset Screen Recording
permission for all Omi apps.

## Tests

- `VoiceTurnDomainBoundaryTests` covers the fact façade and
compiler-enforced boundary.
- Reducer/fuzz, PTT lifecycle, reconnect, and transport tests moved into
`VoiceTurnDomainTests` so only domain tests can use internal event
construction.
- Coordinator/output/reconnect/agent-spawn/silent-mic suites cover the
app-facing integration path.

## Failure class (fixes)

Failure-Class: FC-split-mutation-authority

## New guards

`VoiceTurnDomainBoundaryTests` is a narrow compiler-boundary guard for
the lifecycle-owner failure in BasedHardware#9832. It is not a shared primitive
because Swift target access control is the reusable enforcement
mechanism; the test verifies this domain’s intentional exposure and the
app-side source boundary.
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.

FC-5: compiler-enforced voice-turn ownership — extract VoiceTurnDomain target, end the convergence churn

1 participant