diff --git a/Sources/verbemo/Audio/AudioSlicer.swift b/Sources/verbemo/Audio/AudioSlicer.swift index bd786747..d946938c 100644 --- a/Sources/verbemo/Audio/AudioSlicer.swift +++ b/Sources/verbemo/Audio/AudioSlicer.swift @@ -3,9 +3,8 @@ import Foundation /// Cuts one audio file into consecutive pieces small enough to upload. /// -/// This exists for OpenAI, which refuses anything over 25 MB per request — a -/// limit an hour-long meeting passes at the mix's own bitrate. Nobody should -/// have to know that, so the engine slices, transcribes each piece, and shifts +/// OpenAI's engine chooses the tighter size or duration limit, then +/// slices, transcribes each piece, and shifts /// the timings back onto the session's clock; the transcript comes out looking /// like one pass. /// @@ -19,6 +18,8 @@ enum AudioSlicer { /// Where this piece starts in the source, in seconds. What gets added /// back to every timestamp the engine returns for it. let offset: TimeInterval + /// Source samples covered, excluding padding added by the AAC encoder. + let duration: TimeInterval } enum SliceError: Error, CustomStringConvertible { @@ -63,7 +64,7 @@ enum AudioSlicer { limit: Int64, margin: Double = 0.85 ) -> TimeInterval? { - guard bytes > limit, duration > 0, bytes > 0 else { return nil } + guard bytes > limit, duration.isFinite, duration > 0, bytes > 0 else { return nil } let allowed = Double(limit) * margin let seconds = duration * allowed / Double(bytes) // Never below a minute: a limit that small means the numbers are wrong, @@ -86,15 +87,18 @@ enum AudioSlicer { } let format = file.processingFormat let rate = format.sampleRate - guard file.length > 0, rate > 0 else { throw SliceError.unreadable(source, nil) } + guard file.length > 0, rate.isFinite, rate > 0, seconds.isFinite, seconds > 0 else { + throw SliceError.unreadable(source, nil) + } let duration = Double(file.length) / rate - guard duration > seconds else { return [Slice(url: source, offset: 0)] } + guard duration > seconds else { return [Slice(url: source, offset: 0, duration: duration)] } try FileManager.default.createDirectory( at: directory, withIntermediateDirectories: true) let sliceFrames = AVAudioFramePosition(seconds * rate) + guard sliceFrames > 0 else { throw SliceError.unreadable(source, nil) } // A second at a time, like the mixer: small enough that a long meeting // never holds more than a few hundred kilobytes of audio in memory. let blockFrames = AVAudioFrameCount(rate) @@ -152,7 +156,7 @@ enum AudioSlicer { try? FileManager.default.removeItem(at: url) break } - slices.append(Slice(url: url, offset: Double(start) / rate)) + slices.append(Slice(url: url, offset: Double(start) / rate, duration: Double(written) / rate)) index += 1 } return slices diff --git a/Sources/verbemo/Transcription/OpenAIEngine.swift b/Sources/verbemo/Transcription/OpenAIEngine.swift index b6960410..80ee52e2 100644 --- a/Sources/verbemo/Transcription/OpenAIEngine.swift +++ b/Sources/verbemo/Transcription/OpenAIEngine.swift @@ -11,10 +11,8 @@ import Foundation /// returns, which is why both are `.mixed` engines and share everything /// downstream. /// -/// Two things about the API leak into the code. Requests are capped at 25 MB, -/// which the mix passes at around 55 minutes, so a long meeting is cut into -/// pieces and the timings shifted back onto the session clock; the person who -/// recorded it never hears about any of this. And `chunking_strategy` is +/// Uploads are bounded by size and a defensive duration cap (see below), +/// with timings shifted back onto the session clock. `chunking_strategy` is /// required for anything over 30 seconds — the API refuses outright without /// it, so it is always sent. /// @@ -25,6 +23,8 @@ actor OpenAITranscriptionEngine: TranscriptionEngine { enum EngineError: TranscriptionFailure, CustomStringConvertible { case noAPIKey case empty + case invalidAudio + case uploadLimit /// Only "there was no speech in this audio" is permanent; a silent /// recording will still be silent tomorrow. HTTP answers are @@ -46,6 +46,10 @@ actor OpenAITranscriptionEngine: TranscriptionEngine { + " (chmod 600) or set OPENAI_API_KEY" case .empty: return "openai returned no speech" + case .invalidAudio: + return "openai needs readable audio with a positive finite duration and upload limits" + case .uploadLimit: + return "openai audio exceeds the upload limits after encoding" } } } @@ -55,6 +59,12 @@ actor OpenAITranscriptionEngine: TranscriptionEngine { /// documentation states and what a larger file is refused with. static let defaultRequestLimit: Int64 = 25 * 1_048_576 + /// Defensive, not a documented API contract: amanu PR #18 reported a + /// 1400s rejection. Cut at 1390s to leave 10s for AAC padding. Official + /// docs checked 2026-10-22 only establish 25 MB; see docs/testing/openai-duration-cap.md. + static let defaultDurationLimit: TimeInterval = 1390 + private static let durationSlack: TimeInterval = 10 + nonisolated let name = "openai" nonisolated let model: String nonisolated let input: TranscriptionInput = .mixed @@ -69,12 +79,14 @@ actor OpenAITranscriptionEngine: TranscriptionEngine { /// against real audio and the real API without a meeting long enough to /// pass 25 MB — an hour of it, every time anyone wanted to check. private let requestLimit: Int64 + private let durationLimit: TimeInterval private let http: CloudHTTP /// Throws rather than failing at transcribe time — a missing key should /// show up in the log the moment the engine is picked, not an upload later. init( requestLimit: Int64 = OpenAITranscriptionEngine.defaultRequestLimit, + durationLimit: TimeInterval = OpenAITranscriptionEngine.defaultDurationLimit, apiKey: String? = nil, session: URLSession = .shared, retry: CloudHTTP.RetryPolicy = .standard, @@ -85,6 +97,7 @@ actor OpenAITranscriptionEngine: TranscriptionEngine { expected = MeetingLanguages.expected(primary: Config.transcriptionLanguage()) model = Config.openAITranscriptionModel() self.requestLimit = requestLimit + self.durationLimit = durationLimit http = CloudHTTP(service: .openAI, session: session, retry: retry, sleep: sleep) } @@ -100,7 +113,7 @@ actor OpenAITranscriptionEngine: TranscriptionEngine { var segments: [TranscriptSegment] = [] for (index, slice) in slices.enumerated() { - let cache = cacheURL(in: dir, audio: audio, piece: index, of: slices.count) + let cache = cacheURL(in: dir, audio: audio, slice: slice, piece: index, of: slices.count) let response: Response if let cached = try? Data(contentsOf: cache), let decoded = try? JSONDecoder().decode(Response.self, from: cached) { @@ -130,15 +143,42 @@ actor OpenAITranscriptionEngine: TranscriptionEngine { // MARK: - slicing private func sliced(_ audio: URL) async throws -> [AudioSlicer.Slice] { - let whole = [AudioSlicer.Slice(url: audio, offset: 0)] - let attributes = try? FileManager.default.attributesOfItem(atPath: audio.path) - guard let bytes = attributes?[.size] as? Int64, bytes > requestLimit else { - return whole + let attributes = try FileManager.default.attributesOfItem(atPath: audio.path) + let bytes = attributes[.size] as? Int64 ?? 0 + let duration = Self.duration(of: audio) + let slices: [AudioSlicer.Slice] + if let length = try Self.pieceLength( + bytes: bytes, duration: duration, requestLimit: requestLimit, durationLimit: durationLimit + ) { + slices = try await AudioSlicer.slice(audio, every: length, into: Self.sliceDirectory(audio)) + } else { + slices = [AudioSlicer.Slice(url: audio, offset: 0, duration: duration)] + } + // Average source bitrate is only an estimate; check the encoded files before any upload. + for slice in slices { + let size = try slice.url.resourceValues(forKeys: [.fileSizeKey]).fileSize ?? 0 + let encodedDuration = try await AVURLAsset(url: slice.url).load(.duration).seconds + guard size > 0, encodedDuration.isFinite, encodedDuration > 0 else { + throw EngineError.invalidAudio + } + guard size <= requestLimit, encodedDuration <= durationLimit + Self.durationSlack else { + throw EngineError.uploadLimit + } } - guard let length = AudioSlicer.sliceLength( - bytes: bytes, duration: Self.duration(of: audio), limit: requestLimit - ) else { return whole } - return try await AudioSlicer.slice(audio, every: length, into: Self.sliceDirectory(audio)) + return slices + } + + /// Adapted from Dmitry Tsoy's Amanu PR #18: the tighter ceiling wins (see docs/history/openai-duration-cap-upstream.md). + static func pieceLength( + bytes: Int64, duration: TimeInterval, + requestLimit: Int64 = defaultRequestLimit, + durationLimit: TimeInterval = defaultDurationLimit + ) throws -> TimeInterval? { + guard bytes > 0, requestLimit > 0, duration.isFinite, duration > 0, + durationLimit.isFinite, durationLimit > 0 else { throw EngineError.invalidAudio } + let bySize = AudioSlicer.sliceLength(bytes: bytes, duration: duration, limit: requestLimit) + guard bySize != nil || duration > durationLimit else { return nil } + return min(bySize ?? durationLimit, durationLimit) } private static func sliceDirectory(_ audio: URL) -> URL { @@ -190,14 +230,14 @@ actor OpenAITranscriptionEngine: TranscriptionEngine { // MARK: - shaping /// Where one piece's response is cached: named for the model, the - /// language sent, the request limit that decided the cut, and which piece - /// of how many it is. - func cacheURL(in dir: URL, audio: URL, piece index: Int, of count: Int) -> URL { + /// language sent, and actual source boundaries. A changed cut must never + /// reuse a response just because the piece number and count still match. + func cacheURL(in dir: URL, audio: URL, slice: AudioSlicer.Slice, piece index: Int, of count: Int) -> URL { ProviderCache.url( in: dir, provider: .openAI, parts: [ audio.lastPathComponent, model, Self.languageField(for: expected) ?? "detect", - "\(requestLimit)", "\(count)", + "\(requestLimit)", "\(count)", "slices-v2", "\(slice.offset)", "\(slice.duration)", ], suffix: count > 1 ? "\(index + 1)" : nil) } diff --git a/Tests/verbemoTests/Transcription/OpenAIEngineTests.swift b/Tests/verbemoTests/Transcription/OpenAIEngineTests.swift index 25fafb51..5f43761a 100644 --- a/Tests/verbemoTests/Transcription/OpenAIEngineTests.swift +++ b/Tests/verbemoTests/Transcription/OpenAIEngineTests.swift @@ -1,3 +1,4 @@ +import AVFoundation import Foundation import Testing @@ -7,11 +8,183 @@ import Testing /// from one request becomes segments on the session's clock, and a meeting too /// long for one request is cut up and put back together. struct OpenAIEngineTests { + @Test("A small long AAC recording is sliced, and a retry reuses only completed pieces", .freshHome) + func longAudioRetry() async throws { + let dir = FileManager.default.temporaryDirectory + .appendingPathComponent("verbemo-openai-\(UUID().uuidString)") + try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true) + defer { try? FileManager.default.removeItem(at: dir) } + let audio = dir.appendingPathComponent("mixed.m4a") + try TestAudio.write(to: audio, seconds: 1401, sampleRate: 48_000, settings: [ + AVFormatIDKey: kAudioFormatMPEG4AAC, AVSampleRateKey: 48_000, + AVNumberOfChannelsKey: 1, AVEncoderBitRateKey: 64_000, + ]) { _, frame in Float(frame % 80) / 200 - 0.2 } + let original = try Data(contentsOf: audio) + #expect(original.count < 25 * 1_048_576) + let service = StubHTTP { _, count in + if count == 2 { return .json(500, #"{"error":{"message":"try again"}}"#) } + return .json(200, """ + {"text":"piece\(count)","duration":1,"segments":[ + {"start":0.1,"end":0.8,"text":"piece\(count)","speaker":"A"}]} + """) + } + let engine = try OpenAITranscriptionEngine( + apiKey: "test-key", session: service.session, retry: .once) + await #expect(throws: CloudHTTP.Failure.self) { try await engine.transcribe(audio) } + try #require(service.requests.count == 2) + #expect(ProviderCache.files(in: dir).count == 1) + #expect(try Data(contentsOf: audio) == original) + + let pieces = try FileManager.default.contentsOfDirectory( + at: dir.appendingPathComponent("openai-slices"), includingPropertiesForKeys: nil) + #expect(pieces.count == 2) + for piece in pieces { + let duration = try await AVURLAsset(url: piece).load(.duration).seconds + #expect(duration > 0 && duration < 1400) + #expect(try Data(contentsOf: piece).count < 25 * 1_048_576) + } + + let resumed = try OpenAITranscriptionEngine( + apiKey: "test-key", session: service.session, retry: .once) + let segments = try await resumed.transcribe(audio) + #expect(service.requests.count == 3) + #expect(segments.map(\.text) == ["piece1", "piece3"]) + #expect(segments.map(\.speaker) == ["1A", "2A"]) + #expect(segments.map(\.start) == [0.1, 1390.1]) + #expect(segments.map(\.end) == [0.8, 1390.8]) + #expect(try Data(contentsOf: audio) == original) + #expect(!FileManager.default.fileExists(atPath: dir.appendingPathComponent("openai-slices").path)) + let cached = try await resumed.transcribe(audio) + #expect(cached.map(\.text) == segments.map(\.text)) + #expect(service.requests.count == 3) + } + private static func response(_ json: String) throws -> OpenAITranscriptionEngine.Response { try JSONDecoder().decode( OpenAITranscriptionEngine.Response.self, from: Data(json.utf8)) } + @Test("Unreadable audio is retained and rejected before any upload", .freshHome) + func invalidAudioIsNotUploaded() async throws { + let dir = try Self.folder() + defer { try? FileManager.default.removeItem(at: dir) } + let audio = dir.appendingPathComponent("mixed.m4a") + let original = Data("not audio".utf8) + try original.write(to: audio) + let service = Self.service() + let engine = try OpenAITranscriptionEngine(apiKey: "test-key", session: service.session) + await #expect(throws: (any Error).self) { try await engine.transcribe(audio) } + #expect(service.requests.isEmpty) + #expect(try Data(contentsOf: audio) == original) + } + + private static func folder() throws -> URL { + let dir = FileManager.default.temporaryDirectory + .appendingPathComponent("verbemo-openai-\(UUID().uuidString)") + try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true) + return dir + } + + private static func service() -> StubHTTP { + StubHTTP { _, count in + .json(200, """ + {"text":"piece\(count)","duration":1,"segments":[ + {"start":0.1,"end":0.8,"text":"piece\(count)","speaker":"A"}]} + """) + } + } + + @Test("The tighter size or duration ceiling wins") + func pieceLength() throws { + #expect(try OpenAITranscriptionEngine.pieceLength(bytes: 20 * 1_048_576, duration: 2530) == 1390) + #expect(try OpenAITranscriptionEngine.pieceLength(bytes: 55 * 1_048_576, duration: 7200) == 1390) + #expect(try OpenAITranscriptionEngine.pieceLength(bytes: 100 * 1_048_576, duration: 1500) == 318.75) + #expect(try OpenAITranscriptionEngine.pieceLength(bytes: 100 * 1_048_576, duration: 1200) == 255) + #expect(try OpenAITranscriptionEngine.pieceLength(bytes: 10 * 1_048_576, duration: 1200) == nil) + #expect(try OpenAITranscriptionEngine.pieceLength(bytes: 10 * 1_048_576, duration: 1390) == nil) + #expect(try OpenAITranscriptionEngine.pieceLength(bytes: 10 * 1_048_576, duration: 1390.01) == 1390) + } + + @Test("Invalid duration cannot bypass slicing", arguments: [0.0, -1, .nan, .infinity, -.infinity]) + func invalidDuration(duration: Double) { + #expect(throws: OpenAITranscriptionEngine.EngineError.self) { + try OpenAITranscriptionEngine.pieceLength(bytes: 1_000_000, duration: duration) + } + } + + @Test("Changing boundaries with the same piece count does not reuse stale responses", .freshHome) + func cacheFollowsBoundaries() async throws { + let dir = try Self.folder() + defer { try? FileManager.default.removeItem(at: dir) } + let audio = dir.appendingPathComponent("mixed.caf") + try TestAudio.writeTone(to: audio, seconds: 110, frequency: 440) + let service = Self.service() + let first = try OpenAITranscriptionEngine( + durationLimit: 60, apiKey: "test-key", session: service.session) + // The old key had no slice boundaries, even when the piece count matched. + for index in 1...2 { + let legacy = ProviderCache.url(in: dir, provider: .openAI, parts: [ + "mixed.caf", first.model, + OpenAITranscriptionEngine.languageField( + for: MeetingLanguages.expected(primary: Config.transcriptionLanguage())) ?? "detect", + "26214400", "2", + ], suffix: "\(index)") + try Data(#"{"text":"stale","duration":110}"#.utf8).write(to: legacy) + } + let original = try await first.transcribe(audio) + #expect(original.map(\.text) == ["piece1", "piece2"]) + #expect(original.map(\.start) == [0.1, 60.1]) + let changed = try OpenAITranscriptionEngine( + durationLimit: 65, apiKey: "test-key", session: service.session) + let updated = try await changed.transcribe(audio) + #expect(updated.map(\.text) == ["piece3", "piece4"]) + #expect(updated.map(\.start) == [0.1, 65.1]) + #expect(updated.map(\.speaker) == ["1A", "2A"]) + let cached = try await changed.transcribe(audio) + #expect(cached.map(\.text) == updated.map(\.text)) + #expect(service.requests.count == 4) + } + + @Test("Size-limited AAC parts fit after encoding", .freshHome, arguments: [1390.0, 90.0]) + func encodedSize(durationLimit: Double) async throws { + let dir = try Self.folder() + defer { try? FileManager.default.removeItem(at: dir) } + let audio = dir.appendingPathComponent("mixed.m4a") + try TestAudio.write(to: audio, seconds: 180, settings: [ + AVFormatIDKey: kAudioFormatMPEG4AAC, AVSampleRateKey: 48_000, + AVNumberOfChannelsKey: 1, AVEncoderBitRateKey: 64_000, + ]) { _, frame in Float(frame % 80) / 200 - 0.2 } + #expect(try Data(contentsOf: audio).count > 600_000) + let service = StubHTTP { _, _ in .json(500, "{}") } + let engine = try OpenAITranscriptionEngine( + requestLimit: 600_000, durationLimit: durationLimit, + apiKey: "test-key", session: service.session, retry: .once) + await #expect(throws: CloudHTTP.Failure.self) { try await engine.transcribe(audio) } + let pieces = try FileManager.default.contentsOfDirectory( + at: dir.appendingPathComponent("openai-slices"), includingPropertiesForKeys: nil) + #expect(pieces.count >= 3) + for piece in pieces { + #expect(try Data(contentsOf: piece).count <= 600_000) + let duration = try await AVURLAsset(url: piece).load(.duration).seconds + #expect(duration > 0 && duration < durationLimit + 10) + } + #expect(FileManager.default.fileExists(atPath: audio.path)) + } + + @Test("An encoded piece over the byte budget is never uploaded", .freshHome) + func oversizedEncodingIsNotUploaded() async throws { + let dir = try Self.folder() + defer { try? FileManager.default.removeItem(at: dir) } + let audio = dir.appendingPathComponent("mixed.caf") + try TestAudio.writeTone(to: audio, seconds: 61, frequency: 440) + let service = Self.service() + let engine = try OpenAITranscriptionEngine( + requestLimit: 1000, apiKey: "test-key", session: service.session) + await #expect(throws: OpenAITranscriptionEngine.EngineError.self) { try await engine.transcribe(audio) } + #expect(service.requests.isEmpty) + #expect(FileManager.default.fileExists(atPath: audio.path)) + } + @Test("Diarized segments keep their speakers and land on the session clock") func segmentsAreShifted() throws { let decoded = try Self.response(""" @@ -115,10 +288,15 @@ struct OpenAIEngineTests { let audio = folder.appendingPathComponent("mixed.m4a") var pieces: [URL] = [] for index in 0..<3 { - pieces.append(await engine.cacheURL(in: folder, audio: audio, piece: index, of: 3)) + pieces.append(await engine.cacheURL( + in: folder, audio: audio, + slice: AudioSlicer.Slice(url: audio, offset: Double(index) * 60, duration: 60), + piece: index, of: 3)) } #expect(Set(pieces).count == 3) - #expect(!pieces.contains(await engine.cacheURL(in: folder, audio: audio, piece: 0, of: 1))) + #expect(!pieces.contains(await engine.cacheURL( + in: folder, audio: audio, slice: AudioSlicer.Slice(url: audio, offset: 0, duration: 180), + piece: 0, of: 1))) } /// 25 MB is the API's ceiling; the pieces have to come in under it with diff --git a/docs/history/openai-duration-cap-upstream.md b/docs/history/openai-duration-cap-upstream.md new file mode 100644 index 00000000..e69fdb2b --- /dev/null +++ b/docs/history/openai-duration-cap-upstream.md @@ -0,0 +1,14 @@ +# OpenAI duration-cap upstream provenance + +The tighter-ceiling approach and protective 1390-second cut originate in +Dmitry Tsoy's [Amanu PR #18](https://github.com/gsamat/amanu/pull/18), source +commit `31b8ec434224ad6ead27c37dec8db51694a1b757`, reviewed at head +`101b41816fe7cd359a453d3d4653a19df028e20b` on 2026-10-22. + +That PR reports a service rejection above 1400 seconds; it is historical +evidence, not a documented current API guarantee. The link records attribution +and is not a Verbemo runtime, support, update or release destination. + +See [current behavior and verification](../testing/openai-duration-cap.md). +The unrelated upstream MicRecorder change was not imported. Original license +files and copyright notices remain unchanged. diff --git a/docs/testing/openai-duration-cap.md b/docs/testing/openai-duration-cap.md new file mode 100644 index 00000000..93a07da2 --- /dev/null +++ b/docs/testing/openai-duration-cap.md @@ -0,0 +1,82 @@ +# OpenAI upload duration guard (#6) + +Contract checked on **2026-10-22** for `gpt-4o-transcribe-diarize`: + +- [OpenAI's file transcription guide](https://developers.openai.com/api/docs/guides/speech-to-text) + documents a **25 MB** file limit. This fix retains Verbemo's existing + `25 * 1_048_576` byte threshold and 15% size margin when slicing. +- [The transcription API reference](https://developers.openai.com/api/reference/resources/audio/subresources/transcriptions/methods/create) + requires `chunking_strategy` for this model above 30 seconds. Verbemo continues + to send `auto` and request `diarized_json` for timed speaker segments. +- Neither those pages nor [the model page](https://developers.openai.com/api/docs/models/gpt-4o-transcribe-diarize) + specifies a 1400-second maximum. That number is an **observed rejection** + reported in [Amanu PR #18](../history/openai-duration-cap-upstream.md), not a + documented or independently verified current service guarantee. +- **1390 seconds** is therefore a defensive cut length, leaving ten seconds + below that observed rejection for AAC padding. The shorter of this duration + and the existing size-based estimate wins. Every encoded file is checked + before uploading: positive finite duration, at most 1400 seconds, and at most + the byte threshold. Unexpected encoding expansion fails locally and retains + the source audio rather than sending an oversized request. + +The guide also marks this model deprecated, with shutdown on February 26, 2027. +Model migration is separate work; this fix keeps the selected model and response +format unchanged. + +## Cache and recovery + +The cache key includes a slicing version and each piece's actual source offset +and duration (sample coverage, excluding AAC padding), alongside the existing +audio name, model, language, byte limit, count and piece number. Changing a cut +with the same number of pieces cannot reuse an answer for the previous range. +Old keys without boundaries are not trusted; interrupted runs with only those +keys will upload again once. New successful responses remain reusable after a +later piece fails, including after constructing a new engine. + +Speaker labels remain separate per request, and timestamps are shifted by +source offsets rather than padded encoded durations. Source audio is never +deleted by this engine. Existing coordinator scratch cleanup still owns cache +retirement after a transcript is saved or explicitly regenerated. + +## Verification scope + +`OpenAIEngineTests` uses generated audio and `StubHTTP` with a dummy key. It +covers a real 1401-second AAC file below the byte limit, both ceiling orders, +short inputs and the duration boundary, invalid durations/unreadable input, +actual encoded sizes and container durations, retry after a second-piece error, +legacy caches, changed boundaries with unchanged piece counts, and an encoded +piece that cannot fit the byte budget. `FormEngineHTTPTests` covers the short +one-request path; `TranscriptionScratchTests` covers existing cleanup. + +No real OpenAI request, personal recording, recognition-quality evaluation, or +packaged-app flow was used for this change. HTTP stubs establish local request, +cache and assembly behavior, not live service acceptance. Windows is outside +this macOS issue's scope. + +Local verification on 2026-10-22 (Apple Silicon, Swift 6.4, Xcode 27.1), based +on `f08bf3458731ffb570b2de52b28df67e388c9e87`: + +| Command | Result | +| --- | --- | +| `swift test --no-parallel --filter 'OpenAIEngineTests\|FormEngineHTTPTests\|TranscriptionScratchTests'` | 22 tests in 3 suites passed, 24.840 s | +| `swift test --no-parallel` | Final report: 1031 tests in 145 suites passed, 132.521 s; 23 opt-in/asset-dependent tests skipped | +| `swift build` | Debug build passed | +| `python3 -m unittest discover -s Tests/scripts -p 'test_*.py'` | 114 tests passed, 81.794 s | +| `python3 Tests/scripts/test_independent_product.py --all` | Passed; upstream references live in history/provenance | +| `git diff --check` | Passed | + +Skipped cases cover native model/corpus downloads and inference, LocalVQE +assets/integration, private audio evaluation, calendar acceptance and window +screenshots. The two new regressions for long under-limit audio and unreadable +audio were observed failing before the production change; existing focused +tests passed in that same run. Independent read-only review found no issues. + +## Upstream credit + +The tighter-ceiling approach and 1390-second guard are adapted from Dmitry +Tsoy's [Amanu PR #18](../history/openai-duration-cap-upstream.md), source commit +`31b8ec434224ad6ead27c37dec8db51694a1b757`, reviewed at PR head +`101b41816fe7cd359a453d3d4653a19df028e20b`. Cache-boundary identity, validation +and regression coverage are adapted for current Verbemo. The unrelated +`MicRecorder` change is excluded. Existing copyright and MIT license files +are preserved.