Simplify DegenerateOutputDetector and harden detector tests#2
Merged
Conversation
Follow-up cleanups on top of the Cohere/MLX decode-loop fix (PR #1): - Hoist `.lowercased()` out of the tri-gram loop in `DegenerateOutputDetector.evaluate` (was lowercasing each word 3x per iteration plus once more for the unique-word check; now once up front). - Drop the unreachable `if words.count >= 3` guard inside the `>= 30` branch. - Trim bug-story narration from the type-level doc comments (`CohereMLXBackendError`, `DegenerateOutputDetector`) - the changelog belongs in the PR, not the source. - Replace the `try?` chain on the fixture load in `testDegenerateOutputDetectorFlagsRepetitiveTranscripts` with `try` so a missing/broken fixture fails loudly instead of silently asserting on an empty string. - Make the integration test audio path overridable via `SCRIBE_MLX_INTEGRATION_AUDIO` (the dated default path is kept for back-compat). No behavior change. 365 tests still pass (1 integration test skipped).
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
Follow-up to #1 (Cohere/MLX decode-loop fix). Three parallel review agents (reuse, quality, efficiency) flagged a handful of cleanup opportunities in the detector and its tests. This PR applies the low-risk, no-behavior-change subset.
.lowercased()out of the tri-gram loop inDegenerateOutputDetector.evaluate- was lowercasing each word 3x per iteration plus once more for the unique-word check; now once up front (~6k -> ~1.5k transientStringallocations on a 1,477-word transcript).if words.count >= 3guard nested inside the>= 30branch.CohereMLXBackendErrorandDegenerateOutputDetector. The "583-second recording" / "Blaizzy fork" / gzip rationale belongs in the PR description, not in source where it will rot.try?chain on the fixture load intestDegenerateOutputDetectorFlagsRepetitiveTranscriptswithtryso a missing/broken fixture fails loudly instead of silently asserting on"".SCRIBE_MLX_INTEGRATION_AUDIO. The dated~/Scribe/2026-05-11-1756/audio.m4adefault is kept for back-compat.Skipped intentionally
degenerateOutput(reason: String, ...)to a structuredDegenerationReasonenum - invasive public API change for a diagnostic field.30/0.08/0.10/120to named constants - values already documented in the docstring with rationale; no other call sites.CohereRustBackendTests.swift->CohereMLXBackendTests.swift- pre-existing mismatch, out of scope.CohereMLXBackendErrorinsideCohereMLXBackend- purely stylistic.Test plan
swift buildcleanswift test- 365 tests pass, 1 integration test skipped (unchanged from main)SCRIBE_MLX_INTEGRATION_AUDIO=~/Scribe/2026-05-11-1756/audio.m4a SCRIBE_RUN_MLX_INTEGRATION=1 swift test --filter testFailingRecordingTranscribesWithoutDegenerationIntegrationstill passes on the failing recording (optional spot check)