Skip to content

Full strict Swift enforcement: Swift 6 mode, complete concurrency, SwiftLint safety rules, pinned toolchain — close the Swift enforcement gap #9843

Closed

Description

@Git-on-my-level

Problem

The Swift side of the desktop app — the platform with the repo's heaviest churn and its worst failure-class chains (FC-5) — has no general static enforcement, while its sibling stacks are locked down: Rust denies clippy::unwrap_used crate-wide, Python runs strict pyright. Verified current state (2026-07-15):

  • No SwiftLint, swift-format, or SwiftFormat config anywhere under desktop/macos/ (outside vendored checkouts).
  • Desktop/Package.swift (swift-tools-version: 5.9; three small Swift library targets totaling 12 files, one 444-file executable, one test target): no swiftSettings anywhere — no strict concurrency, no upcoming-feature flags, no warnings-as-errors.
  • desktop-swift-ci.yml: builds on a moving macos-15 image with no toolchain pin, .build cache keyed only by Package.swift (not Package.resolved or toolchain identity), no lint step.
  • The AGENTS.md Formatting table covers Dart, Python, ARB, C/C++, Rust, Web — Swift is absent from the formatting contract and pre-commit hook.
  • What exists: per-bug-class ratchet scripts (active in the manifest, local+CI — check_desktop_test_quality.py, check-async-after-ratchet.py, check-userdefaults-key-ratchet.py, etc.). Real guards, but each covers one instance of a class a compiler/linter setting would close wholesale.

Burn-down scale, measured: ~236 force-unwrap-family candidates (9 try!, 15 as!, ~212 ! unwraps), 584 @MainActor occurrences, 52 actor declarations. The concurrency surface is exactly FC-5's genus — split mutation authority across main-actor singletons, timers, and detached tasks — which is what complete concurrency checking exists to catch at compile time.

End state (the contract; ambitious on purpose)

  1. Swift 6 language mode with complete strict concurrency on every first-party Swift target (including tests; Objective-C and system-library targets like ObjCExceptionCatcher/CWebP are excluded — they cannot take Swift settings). Data races become compile errors.
  2. Warnings-as-errors in CI on every strict target.
  3. SwiftLint via the pinned SimplyDanny/SwiftLintPlugins SPM build-tool plugin (version-pinned in Package.swift, attached per target, .swiftlint.yml inside Desktop/ — the plugin cannot take arbitrary config paths), configured with only_rules listing exactly the safety set: force_unwrapping, force_try, force_cast, implicitly_unwrapped_optional, fatal_error_message, legacy_random, weak_delegate, plus custom_rules absorbing the regex-expressible ratchets (asyncAfter ban, UserDefaults key sprawl; the Dictionary(uniqueKeysWithValues:) rule keeps the existing // omi-collection-safety: escape-hatch convention). only_rules is required — bare strict: true would drag in default style rules.
  4. Baseline discipline the tool doesn't provide, built explicitly: SwiftLint's baseline is a filter, not a ratchet — it neither shrinks itself nor stops someone enlarging it. A small CI guard rejects any PR that adds baseline entries and permits only removals. A narrow swiftlint:disable policy (named reason required, counted by the same guard) closes the one-line bypass.
  5. Apple swift-format, pinned release binary (bootstrapped, not the moving Xcode-provided one — the current main branch needs Swift 6 tools; use a pinned release compatible with the CI toolchain). Pre-commit: --in-place on staged Desktop/**/*.swift, re-stage; CI: lint --strict over the full tree. AGENTS.md Formatting table gains its Swift row.
  6. Dead-code detection via periphery, driven from the existing test-build index store (--skip-build --index-store-path Desktop/.build/.../index/store) so it doesn't duplicate the expensive build; advisory first (debug-only analysis and ObjC/dynamic references produce false positives), promoted to a no-new-findings snapshot guard only if the pilot's signal-to-noise justifies its maintenance cost.
  7. Upcoming-feature flags, only the ones that exist on the active toolchain. On 5.9: ConciseMagicFile, BareSlashRegexLiterals, and -strict-concurrency=complete via unsafeFlags/swiftSettings (the StrictConcurrency feature name arrived with Swift 6 tooling). IsolatedDefaultValues and GlobalConcurrency require 5.10+ — enabled at the tools-version bump, not before. ExistentialAny may be enabled but is not a Swift 6 default (currently scheduled for Swift 7) — listed separately. Critical trap this issue exists to avoid: SwiftPM silently ignores unknown feature names, so flags must be verified against the pinned compiler, not assumed — fake strictness is worse than none.
  8. Everything manifest-registered (local + ci lanes), reason fields citing real instances (fix(desktop): crash on duplicate ids in task/apps/chat data (#6506) #9288's trap siblings; an FC-5 race for concurrency).

Sequencing (each rung an independently landable PR; enforcement always precedes burn-down)

Rung 0 — deterministic toolchain. Pin the Xcode/Swift version in CI and print it in every job; fix the .build cache key to include Package.resolved + toolchain identity. Everything downstream depends on knowing which compiler the flags run against; today's moving image makes every subsequent claim unverifiable.

Rung 1 — formatter + linter. swift-format (pinned) in pre-commit + CI; SwiftLint plugin with only_rules, committed baseline, and the down-only baseline guard. New and changed code is fully strict from this day; existing violations (~236) can only shrink. Replaced regex ratchet scripts are deleted in the same PR, each only after the SwiftLint rule catches that script's own adversarial fixture. check_desktop_test_quality.py stays — it does non-trivial lexical work (string/comment masking, token spans, escape-annotation validation) and is not force-migrated until a fixture-equivalent SwiftSyntax rule exists.

Rung 2 — leaf targets go fully strict, zero baseline. OmiSupport, then OmiWAL, then OmiTheme (not free — it has DispatchQueue.main.async and singleton state to fix): -strict-concurrency=complete + existing upcoming-feature flags + warnings-as-errors. Proves the settings on the real toolchain before the monolith. Any new target created by other work (e.g. the domain target proposed in #9832) starts strict on day one — new code is only genuinely strict when it lives in a strict target.

Rung 3 — the executable under complete concurrency, advisory. A pinned-toolchain, report-only CI job builds Omi Computer with -strict-concurrency=complete and publishes the diagnostic count per module. No baseline pretense: compiler diagnostics cannot be baselined, and SwiftPM settings are target-scoped — the executable becomes blocking only by becoming clean. The burn-down mechanism is extraction: high-churn actor domains move into new strict library targets (the #9832 pattern, repeated), shrinking the non-strict monolith until the root target can flip. Diagnostics triaged like #9840's strictness migrations: real race → filed/fixed; false positive → narrow annotation with named reason.

Rung 4 — swift-tools-version bump (5.10+, then 6.x) and language-mode 6. Enables IsolatedDefaultValues/GlobalConcurrency, converts the accumulated flags into the default, deletes them from the manifest. By this rung it is a version bump, not a migration — that is the point of rungs 0–3.

Rung 5 — periphery pilot from the index store, advisory; promotion decision recorded either way.

Proof (per rung)

  • Rung 0: CI logs print the pinned toolchain; cache-hit behavior verified across a Package.resolved change.
  • Rung 1: each gate fails on an adversarial violation; each deleted script's fixture is caught by its replacement rule first; baseline guard rejects an adversarial baseline addition.
  • Rung 2: leaf targets compile warning-free under complete concurrency on the pinned toolchain in CI.
  • Rung 3: per-module diagnostic counts published every run; the trend is the deliverable. Each extraction PR moves its module's count to zero.
  • Feature-flag verification: a CI assertion that every enabled feature name is recognized by the active compiler (guards the silent-ignore trap).
  • Manifest reason fields cite real caught instances.

Cut list

  • No style/architecture lint rules (view-body length, naming aesthetics) — safety and correctness only; style belongs to swift-format.
  • No force-migration of non-regex ratchet scripts; no promise to delete the "fleet" — several enforce architecture/ownership contracts, not lint.
  • No iOS/Windows/other-target changes — desktop/macos/Desktop only.
  • No periphery blocking gate without a pilot verdict.
  • No burn-down deadlines in this issue — the gates stop growth immediately; cleanup pace is owned per-module by whoever touches it (the ratchet makes slow safe).

Sizing

A program, stated honestly: rungs 0–1 are ~a day each; rung 2 is small-but-real (OmiTheme needs actual fixes); rung 3 is the long arc whose cost is the latent races it surfaces (584 @MainActor sites, 52 actors) — paid incrementally per extraction, never as a big-bang flip. Registry: this is the enforcement half of FC-5's not-covered complement — the semantic-race class becomes compiler-visible as strict targets absorb the voice/agent domains.

Activity

  1. 56 remaining items

  2. Git-on-my-level commented on Jul 19, 2026

    @Git-on-my-level
    MemberAuthor

    Closing as completed: the enforcement outcome is in place — pinned Xcode/SwiftPM inputs, Swift 6 mode with complete concurrency checking, warnings-as-errors for the production and principal test targets, pinned swift-format, pinned safety-only SwiftLint with a down-only baseline, and the recorded Periphery pilot verdict.

    The remaining implementation deviations are intentional and non-blocking: SwiftLint runs through a SHA-verified CI wrapper rather than the SwiftPM plugin because the plugin cannot run cleanly in CI/release builds; two specialized test targets do not escalate warnings; and the diagnostic ledger remains available but is not published as a separate CI artifact.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions