Skip to content

Make local pre-push and GitHub CI deterministic and parity-driven #9440

Closed

Description

@Git-on-my-level

Problem

PR #9437 exposed a confidence gap between local verification and GitHub Actions. The immediate failure was not a Swift product regression: desktop/macos/tests/test-swift-test-suites.sh inferred parallel execution from the total wall-clock duration of the full suite runner.

The test gives two fake suites 3-second sleeps and fails when the whole runner takes 6 seconds or more. PR #9437 added the desktop-quality scan to the runner's setup path, adding about 1.9 seconds locally. The test passed once during pre-push, then failed unchanged locally at real 5.70s / integer elapsed=6s; GitHub's macOS runner reported 8 seconds. The actual Swift test step was skipped after this launcher-test failure, while the clean release compile passed.

This is primarily nondeterministic test design, but it also highlights real parity gaps:

  • local branch head vs GitHub's synthetic PR merge commit
  • mature/warm local checkout vs clean hosted checkout and restored caches
  • local macOS 26.5.1 / Xcode 26.6 / Swift 6.3.3 vs GitHub macOS 15.7.7 on a moving macos-15-arm64 image
  • CI behavior distributed across workflow YAML, component scripts, and scripts/pre-push
  • conditional checks derived independently from local and PR diff contexts
  • Swift cache keys that omit Package.resolved, architecture, Xcode/Swift version, and runner-image identity

Desired architecture

1. Deterministic concurrency and timeout tests

  • Replace absolute elapsed-time assertions with rendezvous/barrier or active-worker instrumentation.
  • For the immediate Swift scheduler test, make Alpha and Beta prove they were simultaneously active rather than comparing total runtime to 6 seconds.
  • Isolate scheduler tests from unrelated preflight/static scans through dependency injection or narrowly scoped runner modes.
  • Use wall-clock bounds only as outer deadlock guards, never as the behavioral oracle.
  • Do not use automatic reruns to turn first-attempt flakes green; reruns may classify infrastructure failures but should preserve the original failure.

2. Canonical CI entrypoints

Introduce one repository-owned entrypoint per required job, for example:

  • scripts/ci/desktop-swift
  • scripts/ci/backend-unit
  • scripts/ci/backend-static

GitHub workflows and local pre-push should invoke the same entrypoints. Workflow YAML should provision the environment and call the script, not duplicate selection or test logic.

3. Local GitHub-parity mode

Provide an explicit command that:

  • creates a temporary clean worktree
  • constructs/tests the same base + head merge that GitHub will test
  • scrubs inherited Git, Python, toolchain, and service environment state
  • uses clean or independently keyed build/cache directories
  • executes canonical jobs in GitHub order
  • prints a machine-readable manifest of selected, skipped, and completed checks

Fast pre-push may remain optimized, but “GitHub parity passed” should refer only to this clean mode.

4. Environment contract

Both local parity and CI should report:

  • OS and architecture
  • runner image identity where applicable
  • Xcode, Swift, Python, Rust, Node, and package-manager versions
  • selected DEVELOPER_DIR
  • material native dependencies

Pin/select Xcode explicitly where the hosted image supports it. Local parity should warn when it cannot match the required toolchain.

5. Cache correctness

At minimum, Swift cache identity should include:

  • Package.swift
  • Package.resolved
  • architecture
  • selected Xcode/Swift version
  • build configuration

Retain clean lanes for package, generated-code, build-script, and cache-contract changes.

6. Workflow parity contracts

Add static/behavioral checks proving:

  • required GitHub jobs call canonical entrypoints
  • pre-push calls those same entrypoints
  • both use the same changed-file primitive
  • base/head semantics are intentional and tested
  • workflow YAML has not accumulated unrepresented inline test commands
  • local and CI selection manifests match for fixture diffs, including adds, deletes, renames, type changes, and synthetic merges

Initial nondeterminism audit

A first-pass scan of macOS and backend unit tests found:

macOS

  • 1 shell timing oracle: desktop/macos/tests/test-swift-test-suites.sh uses date +%s, fixed sleeps, and a total-runtime threshold. This is the immediate P0 conversion to a rendezvous/barrier.
  • 10 Swift test files / 21 sleep sites using Task.sleep, Thread.sleep, or equivalent.
  • Initial candidates:
    • AwaitWithTimeoutTests.swift: observes real elapsed time; retain only a generous deadlock guard and make logical completion deterministic.
    • QueryTracerTests.swift: fixed sleeps and even random CPU work to manufacture durations; inject a monotonic clock.
    • MemoriesViewModelObserverTests.swift, TasksStoreObserverTests.swift, StartupWarmupPolicyTests.swift, and CrispManagerLifecycleTests.swift: fixed sleeps used for propagation; prefer expectations, async streams, callbacks, or explicit test hooks.
    • DashboardTaskRefreshPolicyTests.swift and RewindStorageVideoFrameExtractionTests.swift: inspect whether a yield/event can replace fixed delay.

The existing desktop quality ratchet also reports substantial source-inspection debt (62 files / 171 sites on current main). Audit source-reading tests separately: preserve true architecture guards, but move behavioral claims to compiled APIs/harnesses and keep static checks narrow and parser-backed.

Backend unit tests

  • 13 files / 59 time.sleep sites.
  • 11 files with elapsed/duration comparisons detected by the initial scan.
  • High-priority candidates:
    • test_vision_stream_async.py: requires a health task to finish in under 50ms; coordinate task progress with events instead.
    • test_pusher_ghost_connections.py: requires crash detection in under 500ms; assert supervisor ordering/completion with events.
    • test_vad_gate.py: compares elapsed runtime to a multiple of injected sleep despite already using a barrier; measure maximum concurrent entries or use a second rendezvous.
    • test_firestore_read_ops_cache.py: uses 1.1s/0.3s sleeps for expiry and pub/sub propagation; inject a clock and wait on callback events.
    • test_pusher_circuit_breaker.py: many small sleeps around state transitions; inject monotonic time and synchronize transitions.
    • test_streaming_deepgram_backoff.py: repeated sleeps to trigger keepalive/backoff behavior; use fake time and explicit thread/event control.
    • test_async_http_infrastructure.py, test_executors.py, test_mentor_notifications.py, and test_storage_fanout_limits.py: classify sleeps as simulated work vs synchronization, then replace synchronization sleeps with events/barriers.

Do not blindly ban sleeps. Long-running integration, load, media pacing, and chaos tests may legitimately model time. The audit should distinguish:

  1. Behavioral oracle: pass/fail depends on host speed — replace.
  2. Synchronization delay: hopes another task has progressed — replace with event/barrier/expectation.
  3. Fake workload: acceptable only when runtime itself is the subject; prefer injected worker hooks.
  4. Event-loop yield: await asyncio.sleep(0) may be legitimate and should not be ratcheted as ordinary sleeping.
  5. Integration pacing/deadlock timeout: retain with rationale and a generous outer timeout.

Proposed guardrail

Add a cross-platform test-quality scanner/ratchet for new or modified tests that flags:

  • absolute elapsed-time pass/fail thresholds
  • fixed sleeps used adjacent to assertions
  • polling loops without event-driven alternatives
  • source-reading behavioral assertions
  • retries that erase the first failure

Require either migration to deterministic control or a narrowly formatted, reasoned escape for true integration/performance tests.

Acceptance criteria

  • Immediate Swift scheduler test proves overlap deterministically and passes under artificial CPU contention.
  • GitHub and pre-push invoke canonical entrypoints for macOS Swift and backend required checks.
  • A clean synthetic-merge local parity command exists and emits a selection/execution manifest.
  • Contract tests compare local and GitHub check selection for representative diffs.
  • Toolchain/environment manifests are emitted locally and remotely.
  • Swift cache keys include dependency lockfile and material toolchain dimensions.
  • Initial macOS/backend candidates above are classified; P0 behavioral-oracle and synchronization-delay cases are migrated.
  • A no-increase guard prevents new unreasoned timing/source-inspection debt.
  • Contributor and agent guidance distinguishes fast pre-push from full GitHub-parity verification.

Evidence

Activity

  1. Git-on-my-level commented on Jul 16, 2026

    @Git-on-my-level
    MemberAuthor

    Additional evidence from #9855 (strict Swift enforcement): CI pins Xcode 16.4 / Swift 6 while the local development machine used Xcode 26.6. The PR surfaced three test-compilation failures that were specific to the older CI toolchain: @mainactor XCTest lifecycle hooks transferring XCTestCase, a non-Sendable NSImage escaping an actor test seam, and a pure SwiftUI policy helper inheriting main-actor isolation.

    The final CI run passed, but the desktop Swift test job took 13m48s and the clean release compile 17m36s: https://github.com/BasedHardware/omi/actions/runs/29528881464. A local, documented CI-toolchain mode that selects /Applications/Xcode_16.4.app when present—and otherwise fails with an actionable install/mismatch message—would have converted these into focused local failures before push. This is narrower than the full synthetic-merge parity mode but should be its first useful desktop-Swift milestone.

  2. undivisible commented on Jul 20, 2026

    @undivisible
    Collaborator

    Closed: fix committed to main. See commit reference in previous audit. Stale-open — resolution confirmed.

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