Skip to content

[codex] fix CI tests and encoding scheduling - #1

Merged
rawphp merged 1 commit into
mainfrom
codex/ci-performance-fixes
May 12, 2026
Merged

rawphp merged 1 commit into
mainfrom
codex/ci-performance-fixes

Conversation

@rawphp

@rawphp rawphp commented May 11, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Run the macOS XCTest suite in CI instead of build-only validation.
  • Enforce the documented two-job EncodingQueue concurrency cap with a scheduler and regression test.
  • Make silence auto-stop count grace and threshold from audio buffer duration rather than wall-clock time.
  • Keep the auto-stop duration and silence integration tests deterministic on slow CI runners by driving large synthetic buffers and avoiding tight wall-clock assertions in the integration layer.
  • Keep Core Audio tap unit tests headless by avoiding real tap construction in XCTest.

Validation

  • xcodebuild -project SystemAudioRecorder.xcodeproj -scheme SystemAudioRecorder -destination 'platform=macOS' -only-testing:AudioEngineTests/RecordingSessionIntegrationTests/testAutoStopDurationProducesMP3 test
  • xcodebuild -project SystemAudioRecorder.xcodeproj -scheme SystemAudioRecorder -destination 'platform=macOS' -only-testing:AudioEngineTests/RecordingSessionIntegrationTests/testAutoStopSilenceProducesMP3 -only-testing:AudioEngineTests/RecordingSessionTests/testSilenceDetectorGraceUsesAudioDurationNotWallClock test
  • make test — 409 tests, 1 skipped, 0 failures

@rawphp
rawphp force-pushed the codex/ci-performance-fixes branch 2 times, most recently from ba1b1f8 to 21f4dca Compare May 12, 2026 06:16
@rawphp
rawphp marked this pull request as ready for review May 12, 2026 06:19
@rawphp
rawphp requested a review from Copilot May 12, 2026 06:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates CI to run the macOS XCTest suite and hardens a couple of timing/concurrency-sensitive behaviors in the audio pipeline (silence auto-stop and encoding job scheduling) by shifting tests toward deterministic, buffer-driven inputs.

Changes:

  • Switch GitHub Actions from xcodebuild build to xcodebuild test for macOS.
  • Rework RecordingSession silence detection to measure grace/threshold using audio-buffer duration (not wall clock), and adjust/add tests accordingly.
  • Replace EncodingQueue’s implicit concurrency behavior with an explicit scheduler/drain mechanism and add a regression test for the 2-job cap.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Tests/AudioEngineTests/RecordingSessionTests.swift Adds a regression test asserting grace/threshold are based on audio duration.
Tests/AudioEngineTests/ProcessTapCaptureTests.swift Makes the “real emitter factory” test headless to avoid macOS permission prompts in CI.
Tests/AudioEngineTests/IntegrationTests/RecordingSessionIntegrationTests.swift Makes integration tests less wall-clock-sensitive by emitting larger synthetic buffers and loosening timing assertions.
Tests/AudioEngineTests/EncodingQueueTests.swift Adds a test asserting the queue never runs more than two jobs concurrently.
AudioEngine/Recording/RecordingSession.swift Changes silence detector accounting from wall-clock to audio-duration-based counters.
AudioEngine/Encoding/LameEncoder.swift Marks BitrateMode as Sendable.
AudioEngine/Encoding/EncodingQueue.swift Replaces the previous concurrency mechanism with a manual drain/scheduling model and cancellation bookkeeping.
App/AppStore.swift Explicitly ignores the return value of requestAudioTap().
.github/workflows/ci.yml Runs xcodebuild test in CI and uploads .xcresult on failure.
Comments suppressed due to low confidence (1)

AudioEngine/Encoding/EncodingQueue.swift:146

  • EncodingQueue is @MainActor, but startJob launches encoding work with Task { ... }, which inherits the MainActor context. Since LameEncoder.encode is effectively synchronous CPU/I/O (no suspension points), this will block the main thread/UI and also prevents true concurrency. Run the encode task off the MainActor (e.g., Task.detached / a dedicated background executor) and only hop to MainActor for state updates.
    private func startJob(_ job: EncodingJob, keepWAV: Bool) {
        var runningJob = job
        running.append(runningJob)

        let task = Task {
            let encoder = LameEncoder()
            do {
                try await encoder.encode(
                    wavURL: job.wavURL,
                    mp3URL: job.mp3URL,
                    bitrate: job.bitrate,
                    mode: job.mode,
                    progress: { [weak self] p in
                        guard let self else { return }
                        Task { @MainActor [weak self] in
                            guard let self else { return }
                            if let idx = self.running.firstIndex(where: { $0.id == job.id }) {
                                self.running[idx].progress = p
                            }
                        }
                    }
                )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 91 to 101
/// Cancels all pending and running jobs; removes any partial MP3 files.
public func cancelAll() async {
// Cancel all running tasks
cancelledJobIDs.formUnion(pending.map(\.id))
cancelledJobIDs.formUnion(running.map(\.id))
for task in runningTasks.values {
task.cancel()
}
runningTasks.removeAll()
pendingKeepWAV.removeAll()

Comment on lines +793 to 809
let frames = Double(buf.frameLength)
let sampleRate = buf.format.sampleRate
let bufferDuration = sampleRate > 0 ? frames / sampleRate : 0
activeAudioSeconds += bufferDuration

// Skip grace period.
guard state.activeSeconds() >= gracePeriod else {
silenceRunStart = nil
guard activeAudioSeconds >= gracePeriod else {
silentAudioSeconds = 0
continue
}

let rms = MeterTap.computeRMS(buf)

if rms < silenceDBFS {
// Silent buffer — start or continue the silence run.
if silenceRunStart == nil {
silenceRunStart = Date()
}
// Check if we've been silent long enough.
let silentSecs = Date().timeIntervalSince(silenceRunStart!)
if silentSecs >= threshold {
silentAudioSeconds += bufferDuration
if silentAudioSeconds >= threshold {
_ = await self.stop()
Comment on lines +607 to +638
func testSilenceDetectorGraceUsesAudioDurationNotWallClock() async throws {
let session = RecordingSession()
let e = FakeEmitter(id: "app1")

let cfg = SessionConfig(
sources: [SessionConfig.Source(id: "app1", emitter: e)],
outputMode: .mixed,
outputFolder: tmpDir,
timestamp: "2026-05-09T10-00-00",
autoStopSilenceSeconds: 1.0
)

try await session.start(config: cfg)

e.pushSilent(frameCount: 48_000)
e.pushSilent(frameCount: 48_000)
try await Task.sleep(nanoseconds: 50_000_000)
let afterGraceState = await session.state
XCTAssertEqual(afterGraceState, .recording, "2 s grace alone must not stop the session")

e.pushSilent(frameCount: 48_000)

let deadline = Date().addingTimeInterval(1.0)
while Date() < deadline {
if await session.state == .stopped { break }
try await Task.sleep(nanoseconds: 10_000_000)
}

let finalState = await session.state
XCTAssertEqual(finalState, .stopped,
"grace and silence threshold should be measured from audio duration, not CI wall-clock speed")
}
@rawphp
rawphp force-pushed the codex/ci-performance-fixes branch from 21f4dca to 372a638 Compare May 12, 2026 06:35
@rawphp
rawphp merged commit bccba7f into main May 12, 2026
2 checks passed
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