Repository navigation
[codex] fix CI tests and encoding scheduling - #1
Merged
Merged
Conversation
rawphp
force-pushed
the
codex/ci-performance-fixes
branch
2 times, most recently
from
May 12, 2026 06:16
ba1b1f8 to
21f4dca
Compare
rawphp
marked this pull request as ready for review
May 12, 2026 06:19
There was a problem hiding this comment.
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 buildtoxcodebuild testfor macOS. - Rework
RecordingSessionsilence 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
EncodingQueueis@MainActor, butstartJoblaunches encoding work withTask { ... }, which inherits the MainActor context. SinceLameEncoder.encodeis 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 toMainActorfor 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
force-pushed
the
codex/ci-performance-fixes
branch
from
May 12, 2026 06:35
21f4dca to
372a638
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validation
xcodebuild -project SystemAudioRecorder.xcodeproj -scheme SystemAudioRecorder -destination 'platform=macOS' -only-testing:AudioEngineTests/RecordingSessionIntegrationTests/testAutoStopDurationProducesMP3 testxcodebuild -project SystemAudioRecorder.xcodeproj -scheme SystemAudioRecorder -destination 'platform=macOS' -only-testing:AudioEngineTests/RecordingSessionIntegrationTests/testAutoStopSilenceProducesMP3 -only-testing:AudioEngineTests/RecordingSessionTests/testSilenceDetectorGraceUsesAudioDurationNotWallClock testmake test— 409 tests, 1 skipped, 0 failures