Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more
fix(meetings): preserve speaker overlap and turn order
argus-vault64f0ddaa4d0b
diff --git a/MEETING_SPEAKER_OVERLAP_TURN_ORDER_IMPLEMENTATION_PLAN.md b/MEETING_SPEAKER_OVERLAP_TURN_ORDER_IMPLEMENTATION_PLAN.mdnew file mode 100644index 00000000..410ea7bb--- /dev/null+++ b/MEETING_SPEAKER_OVERLAP_TURN_ORDER_IMPLEMENTATION_PLAN.md@@ -0,0 +1,122 @@+# Speaker Overlap and Turn Order Implementation Plan++Status: implemented after router adversarial review; focused verification passed+Scope: canonical Parakeet + Nemotron final transcript attribution, product turn construction, and+speaker labels. Timeline normalization is already complete and is not reopened here.++## Problem statement++The latest 78.8-second Chrome recording produced two valid Nemotron speaker slots and 278 Parakeet+word units. Of those, 263 were assigned, 13 were marked ambiguous because both slots intersected the+word, and two were outside all speaker activity. The product then:++1. treats any second-slot intersection larger than the manifest's one-microsecond mapping tolerance+ as real speaker overlap;+2. renders every nil speaker ID as `Unknown speaker`, collapsing genuine overlap, no activity, and+ timing uncertainty into one label;+3. drops outside-activity ASR text from the visible transcript; and+4. groups all segments by speaker/state before merging, so A → B → A can become one long A row with+ B displayed inside its time interval.++## Invariants++- Preserve every admitted ASR word exactly once and in chronological order.+- Never invent a speaker identity when evidence is genuinely ambiguous.+- A segment between two same-speaker segments breaks the turn, even if the gap is small.+- Cross-track segments do not merge with each other and do not reorder either track's local turns.+- Speaker activity intervals for one token are unioned before overlap is measured; duplicates never+ increase evidence.+- Model cadence, overlap thresholds, and dominance thresholds are named, backend-versioned policy,+ not generic manifest tolerances or unexplained literals.+- Sidecar evidence remains word-granular and retains ambiguity candidates and dispositions.+- Existing session JSON remains decodable; no enum case is removed or renamed.++## Phase 1 — Chronological turn construction++Replace `mergeCanonicalSegments`' grouping by full merge key with a per-track chronological fold:++1. group only by track;+2. sort each track by `(start, end, id)`;+3. compare each segment only with the immediately preceding output segment on that track;+4. merge only when the full attribution/state key matches, the gap is at most the named+ `canonicalTurnMergeGapSeconds = 3`, and total turn duration is at most the named+ `canonicalTurnMaximumDurationSeconds = 30`;+5. otherwise append a new turn; and+6. globally sort the completed per-track turns by `(start, end, trackID, id)` for publication.++Add regressions for A → B → A, A → ambiguous → A, overlapping turns, deterministic IDs, adjacent+same-speaker words, maximum gap, maximum duration, and stable global ordering across tracks.++## Phase 2 — Typed product labels++Add an optional, backward-compatible product attribution state and create one shared transcript+speaker-label resolver used by UI rows, accessibility, text export and copy operations:++- known speaker ID / `.assigned`: resolved speaker name;+- `.overlappingSpeakers`: `Overlapping speakers`;+- `.unassigned`: `Unassigned`;+- `.timingUncertain`: `Timing uncertain`.++Row label visibility compares the resolved label, not only `speakerID`, so adjacent nil-speaker rows+with different meanings each show their label. JSON export keeps `speakerID: nil` and the existing+overlap field, preserving machine-readable meaning without a schema break.++Older segments without the field fall back to the existing speaker-ID/overlap interpretation.+Timing-uncertain text remains nil-speaker but changes from `.ambiguous` to `.none`; it is not+evidence of simultaneous speakers and stays distinguishable from ordinary unassigned text.++## Phase 3 — Preserve the existing outside-activity safety policy++Keep `.outsideActivity` text suppressed in this change. Surfacing it could expose silence/noise ASR+hallucinations and requires a separate evidence policy. Echo-suppressed, outside-activity,+inadmissible and invalid-timing units remain excluded and fully accounted for in the sidecar.++## Phase 4 — Backend-specific overlap dominance++Replace token-presence assignment with union-overlap scoring for each word:++1. clip activity intervals to the word and union intervals per speaker token;+2. calculate coverage seconds and coverage fraction for every token;+3. use Nemotron's documented 80 ms output cadence as a named maximum boundary-noise duration;+4. scale the boundary-noise threshold for short words as+ `min(80 ms, 20% of the word duration)`, so 80 ms can never be discarded from a 150 ms word;+5. if every candidate is at or below that threshold, return `.unassigned` rather than creating a+ confident assignment from near-zero evidence;+6. assign the sole candidate above the threshold;+7. with multiple candidates, assign the leader only when it covers at least 50% of the word, the+ runner-up covers at most 20%, and the leader has at least twice the runner-up coverage;+8. otherwise return `.ambiguous` with deterministically sorted above-threshold candidates; and+9. keep whole-epoch utterance fallback conservative: multiple candidates remain ambiguous.++The ratios are conservative initial product policy, isolated in a configuration value and covered+at exact boundaries. Add DEBUG-only structured measurements for multi-candidate words—duration,+leader overlap, runner-up overlap and decision—without transcript text or participant identity.++Increment the Parakeet+Nemotron backend version to `2` and the meeting pipeline version to `12` so+new attribution and turn semantics have explicit lineage.++## Phase 5 — Verification++Required focused tests:++- `MeetingParakeetNemotronBackendTests`: one-frame sliver, sole sub-frame activity, 60/40 overlap,+ full overlap, exact thresholds, duplicate intervals, deterministic ties and utterance fallback;+- `MeetingTranscriptAssemblerTests`: ambiguous, unassigned and timing-uncertain attribution states,+ while outside-activity text remains suppressed;+- canonical merge tests: A/B/A, ambiguous breaker, adjacency, bounds and cross-track order;+- exporter/UI projection tests: Speaker N, Overlapping speakers, Unassigned, alias resolution and+ label transitions; and+- golden replay assertions derived from the latest session: no turn contains an intervening+ same-track turn, product text order matches sidecar word order, and all accepted words appear once.++Run the focused suites, full integration `build-for-testing`, signed Debug build, stable-identity+install preflight, and a real Chrome replay. Existing incorrectly merged sessions require Retry to+re-run backend version 2 scoring and rebuild turn rows from word evidence; label improvements apply+immediately to their retained ambiguous rows through the backward-compatible fallback.++## Explicit non-goals++- Naming anonymous slots from calendar or accessibility metadata.+- Merging speaker identity across epochs.+- Changing Nemotron model weights or quality measurements.+- Reopening timeline normalization, PCM retention, or compression work.diff --git a/Sources/Fluid/Services/Meeting/Backend/MeetingParakeetNemotronBackend.swift b/Sources/Fluid/Services/Meeting/Backend/MeetingParakeetNemotronBackend.swiftindex 7f248f14..abfec56e 100644--- a/Sources/Fluid/Services/Meeting/Backend/MeetingParakeetNemotronBackend.swift+++ b/Sources/Fluid/Services/Meeting/Backend/MeetingParakeetNemotronBackend.swift@@ -13,7 +13,7 @@ import Foundationfinal class MeetingParakeetNemotronBackend: MeetingTranscriptionBackend {static let descriptor = MeetingBackendDescriptor(id: .parakeetNemotron,- version: "1",+ version: "2",execution: .local,supportedLanguageCodes: ["en"],supportedTrackKinds: Set(MeetingAudioTrackKind.allCases),@@ -450,7 +450,7 @@ final class MeetingParakeetNemotronBackend: MeetingTranscriptionBackend {text: text,analysisStart: start,analysisEnd: end,- speaker: Self.assignment(start: start, end: end, activity: activity),+ speaker: Self.assignment(start: start, end: end, activity: activity, allowDominance: true),analysisSpanIDs: spanIDs,confidence: nil))@@ -469,7 +469,7 @@ final class MeetingParakeetNemotronBackend: MeetingTranscriptionBackend {text: text,analysisStart: epochStart,analysisEnd: physicalEnd,- speaker: Self.assignment(start: epochStart, end: physicalEnd, activity: activity),+ speaker: Self.assignment(start: epochStart, end: physicalEnd, activity: activity, allowDominance: false),analysisSpanIDs: spanIDs,confidence: nil)]@@ -546,22 +546,141 @@ final class MeetingParakeetNemotronBackend: MeetingTranscriptionBackend {return span.analysisInterval.start + fraction * span.analysisInterval.duration}- /// One overlapping slot assigns; two or more are reported ambiguous; none is unassigned.- private nonisolated static func assignment(+ /// Nemotron emits diarization decisions on this cadence (plan §4); a boundary sliver shorter+ /// than one output hop is model noise, not evidence of a second speaker.+ private nonisolated static let nemotronCadenceMaximumFloorSeconds: TimeInterval = 0.08++ /// Conservative initial product policy for multi-candidate words, isolated here so the ratios+ /// are named and covered at exact boundaries instead of living as unexplained literals.+ private nonisolated enum SpeakerDominancePolicy {+ static let minimumLeaderCoverageFraction: Double = 0.5+ static let maximumRunnerUpCoverageFraction: Double = 0.2+ static let minimumLeaderToRunnerUpRatio: Double = 2.0+ }++ /// The cadence floor scaled down for short words, so an 80ms boundary hop can never be+ /// discarded outright from a 150ms word: never more than 20% of the unit's own duration.+ private nonisolated static func boundaryNoiseThresholdSeconds(duration: TimeInterval) -> TimeInterval {+ min(self.nemotronCadenceMaximumFloorSeconds, 0.2 * duration)+ }++ /// Clips each activity interval to the unit and unions same-token intervals before measuring+ /// coverage, so duplicate or fragmented diarizer segments for one slot never double-count.+ private nonisolated static func coverageSeconds(start: TimeInterval,end: TimeInterval,activity: [MeetingBackendSpeakerActivity]+ ) -> [MeetingBackendSpeakerToken: TimeInterval] {+ var intervalsByToken: [MeetingBackendSpeakerToken: [(start: TimeInterval, end: TimeInterval)]] = [:]+ for entry in activity {+ let clippedStart = max(entry.start, start)+ let clippedEnd = min(entry.end, end)+ guard clippedEnd > clippedStart else { continue }+ intervalsByToken[entry.token, default: []].append((clippedStart, clippedEnd))+ }+ var coverage: [MeetingBackendSpeakerToken: TimeInterval] = [:]+ for (token, intervals) in intervalsByToken {+ coverage[token] = Self.unionDurationSeconds(intervals)+ }+ return coverage+ }++ private nonisolated static func unionDurationSeconds(+ _ intervals: [(start: TimeInterval, end: TimeInterval)]+ ) -> TimeInterval {+ let sorted = intervals.sorted { $0.start < $1.start }+ guard var runStart = sorted.first?.start else { return 0 }+ var runEnd = sorted[0].end+ var total: TimeInterval = 0+ for interval in sorted.dropFirst() {+ if interval.start > runEnd {+ total += runEnd - runStart+ runStart = interval.start+ runEnd = interval.end+ } else {+ runEnd = max(runEnd, interval.end)+ }+ }+ total += runEnd - runStart+ return total+ }++ /// Coverage-based slot attribution (plan §4 "Backend-specific overlap dominance"): a candidate+ /// must clear the scaled cadence-noise floor to count at all; a sole surviving candidate+ /// assigns; multiple candidates assign only under a conservative dominance margin, and remain+ /// ambiguous otherwise. `allowDominance` is `false` for the whole-epoch utterance fallback,+ /// which has no word-level precision to justify picking a winner among real candidates.+ nonisolated static func assignment(+ start: TimeInterval,+ end: TimeInterval,+ activity: [MeetingBackendSpeakerActivity],+ allowDominance: Bool) -> MeetingBackendSpeakerAssignment {- let tolerance = MeetingAnalysisManifestSchema.mappingToleranceSeconds- var tokens = Set<MeetingBackendSpeakerToken>()- for entry in activity where min(entry.end, end) - max(entry.start, start) > tolerance {- tokens.insert(entry.token)+ let duration = end - start+ let threshold = Self.boundaryNoiseThresholdSeconds(duration: duration)+ let coverage = Self.coverageSeconds(start: start, end: end, activity: activity)+ let aboveThreshold = coverage.filter { $0.value > threshold }+ let ranked = aboveThreshold.sorted { lhs, rhs in+ if lhs.value != rhs.value { return lhs.value > rhs.value }+ return lhs.key.label < rhs.key.label}- let sorted = tokens.sorted { $0.label < $1.label }- switch sorted.count {- case 0: return .unassigned- case 1: return .assigned(sorted[0])- default: return .ambiguous(sorted)++ switch ranked.count {+ case 0:+ return .unassigned+ case 1:+ return .assigned(ranked[0].key)+ default:+ let leader = ranked[0]+ let runnerUp = ranked[1]+ let leaderFraction = duration > 0 ? leader.value / duration : 0+ let runnerUpFraction = duration > 0 ? runnerUp.value / duration : 0+ let decision: MeetingBackendSpeakerAssignment+ if allowDominance,+ leaderFraction >= SpeakerDominancePolicy.minimumLeaderCoverageFraction,+ runnerUpFraction <= SpeakerDominancePolicy.maximumRunnerUpCoverageFraction,+ leader.value >= runnerUp.value * SpeakerDominancePolicy.minimumLeaderToRunnerUpRatio+ {+ decision = .assigned(leader.key)+ } else {+ decision = .ambiguous(ranked.map(\.key).sorted { $0.label < $1.label })+ }+ #if DEBUG+ Self.logMultiCandidateDecision(+ duration: duration,+ candidateCoverageSeconds: ranked.map(\.value),+ decision: decision+ )+ #endif+ return decision}}++ #if DEBUG+ /// Structured, DEBUG-only measurement of a multi-candidate word decision. Deliberately carries+ /// only durations, coverage seconds and the resulting decision kind — never transcript text,+ /// unit/word identity, file paths, or participant identity.+ private nonisolated static func logMultiCandidateDecision(+ duration: TimeInterval,+ candidateCoverageSeconds: [TimeInterval],+ decision: MeetingBackendSpeakerAssignment+ ) {+ let decisionLabel: String+ switch decision {+ case .assigned: decisionLabel = "dominant"+ case .ambiguous: decisionLabel = "ambiguous"+ case .unassigned: decisionLabel = "unassigned"+ }+ let overlaps = candidateCoverageSeconds+ .map { String(format: "%.3f", $0) }+ .joined(separator: ",")+ DebugLogger.shared.info(+ String(+ format: "[speakerCoverage] duration=%.3fs candidates=%d overlaps=[%@] decision=%@",+ duration, candidateCoverageSeconds.count, overlaps, decisionLabel+ ),+ source: "MeetingParakeetNemotronBackend"+ )+ }+ #endif}diff --git a/Sources/Fluid/Services/Meeting/Backend/MeetingTranscriptAssembler.swift b/Sources/Fluid/Services/Meeting/Backend/MeetingTranscriptAssembler.swiftindex f330dffd..3f5f8825 100644--- a/Sources/Fluid/Services/Meeting/Backend/MeetingTranscriptAssembler.swift+++ b/Sources/Fluid/Services/Meeting/Backend/MeetingTranscriptAssembler.swift@@ -308,6 +308,10 @@ nonisolated struct MeetingTranscriptAssembler {dispositions.map { ($0.unitID, $0.disposition) },uniquingKeysWith: { first, _ in first })+ let dispositionReasonByUnitID = Dictionary(+ dispositions.map { ($0.unitID, $0.reasonCode) },+ uniquingKeysWith: { first, _ in first }+ )// Ambiguous-admitted units produce a segment but mint no speaker: their candidates are// reported, never resolved into a product identity.let speakers = self.makeSpeakers(@@ -322,12 +326,22 @@ nonisolated struct MeetingTranscriptAssembler {let segments = emitted.map { unit, presentation -> MeetingTranscriptSegment inlet disposition = dispositionByUnitID[unit.id]+ let reasonCode = dispositionReasonByUnitID[unit.id] ?? nil+ let isSpeakerAmbiguous = disposition == .ambiguousUnassigned+ && reasonCode == MeetingUnitDispositionReason.ambiguousSpeaker.rawValue+ let isTimingUncertain = disposition == .ambiguousUnassigned+ && reasonCode == MeetingUnitDispositionReason.timingUncertain.rawValuelet speakerID: SessionSpeakerID? = {guard disposition == .emitted,case let .assigned(token) = unit.speakerelse { return nil }return speakerIDsByToken[token]}()+ let attributionState: MeetingTranscriptAttributionState = {+ if isSpeakerAmbiguous { return .overlappingSpeakers }+ if isTimingUncertain { return .timingUncertain }+ return speakerID != nil ? .assigned : .unassigned+ }()return MeetingTranscriptSegment(id: Self.stableUUID("segment:\(manifest.attemptID.uuidString):\(unit.id)"),start: Self.mediaTime(presentation.start),@@ -337,9 +351,10 @@ nonisolated struct MeetingTranscriptAssembler {text: unit.text,revision: 0,status: .final,- overlap: disposition == .ambiguousUnassigned ? .ambiguous : .none,+ overlap: isSpeakerAmbiguous ? .ambiguous : .none,completeness: .complete,- isLikelyEcho: nil+ isLikelyEcho: nil,+ attributionState: attributionState)}.sorted {diff --git a/Sources/Fluid/Services/Meeting/MeetingModels.swift b/Sources/Fluid/Services/Meeting/MeetingModels.swiftindex d85f5767..0f1f80b8 100644--- a/Sources/Fluid/Services/Meeting/MeetingModels.swift+++ b/Sources/Fluid/Services/Meeting/MeetingModels.swift@@ -91,6 +91,19 @@ nonisolated enum MeetingTranscriptOverlap: String, Codable, Sendable {case ambiguous}+/// Why a segment does or does not carry a resolved speaker. Additive alongside `speakerID` and+/// `overlap`; optional so pre-fix manifests still decode.+nonisolated enum MeetingTranscriptAttributionState: String, Codable, Sendable {+ /// A single speaker was confidently resolved.+ case assigned+ /// Two or more speakers overlapped and could not be separated.+ case overlappingSpeakers+ /// No speaker evidence at all, without overlap or timing ambiguity.+ case unassigned+ /// Timing was uncertain, so the text is visible but never confidently assigned.+ case timingUncertain+}+nonisolated enum MeetingTranscriptCoverageGapReason: String, Codable, Sendable {case unprotectedMicrophone// Canonical-assembly reasons (C2b2). Additive: old sessions keep decoding, and legacy output@@ -760,6 +773,8 @@ nonisolated struct MeetingTranscriptSegment: Codable, Identifiable, Equatable, Svar completeness: MeetingTranscriptCompleteness/// Optional so pre-fix manifests still decode; a non-optional default would `keyNotFound`.var isLikelyEcho: Bool? = nil+ /// Optional so pre-fix manifests still decode; a non-optional default would `keyNotFound`.+ var attributionState: MeetingTranscriptAttributionState? = nilvar isEcho: Bool {self.isLikelyEcho == true@@ -941,6 +956,8 @@ nonisolated struct MeetingSession: Codable, Identifiable, Equatable, Sendable {}guard self.transcriptSegments[segmentIndex].speakerID != speakerID else { return }self.transcriptSegments[segmentIndex].speakerID = speakerID+ self.transcriptSegments[segmentIndex].attributionState = .assigned+ self.transcriptSegments[segmentIndex].overlap = .noneself.transcriptSegments[segmentIndex].revision += 1self.updatedAt = Date()}diff --git a/Sources/Fluid/Services/Meeting/MeetingProcessingConfiguration.swift b/Sources/Fluid/Services/Meeting/MeetingProcessingConfiguration.swiftindex a1e4d0a7..2f88303b 100644--- a/Sources/Fluid/Services/Meeting/MeetingProcessingConfiguration.swift+++ b/Sources/Fluid/Services/Meeting/MeetingProcessingConfiguration.swift@@ -25,7 +25,7 @@ nonisolated struct MeetingFinalProcessingConfiguration: Equatable, Sendable {static let defaultLanguageCode = "en"/// Mirrors `MeetingProcessingPipeline.pipelineVersion`; that class is `@MainActor`, so a/// MainActor test guards this literal against drift instead of referencing it here.- static let defaultPipelineVersion = 11+ static let defaultPipelineVersion = 12let asrModel: Stringlet languageCode: Stringdiff --git a/Sources/Fluid/Services/Meeting/MeetingProcessingPipeline.swift b/Sources/Fluid/Services/Meeting/MeetingProcessingPipeline.swiftindex 19e9e369..08707587 100644--- a/Sources/Fluid/Services/Meeting/MeetingProcessingPipeline.swift+++ b/Sources/Fluid/Services/Meeting/MeetingProcessingPipeline.swift@@ -656,7 +656,8 @@ private final class MeetingProviderLanguagePin {final class MeetingProcessingPipeline: MeetingProcessingControlling {/// Bump whenever classification rules change so a resumed run can't mix rules mid-session./// Era-awareness did NOT bump this: the mic pass re-runs every time, and multi-era tracks cannot predate this build.- static let pipelineVersion = 11+ /// Version 12: Parakeet+Nemotron backend moved to coverage-union overlap dominance (plan §4).+ static let pipelineVersion = 12/// Per-turn engines starve on short turns, and an all-empty chunk collapses to unlabeled.static let perTurnTurnMergeGapSeconds = 5.0@@ -1626,37 +1627,55 @@ final class MeetingProcessingPipeline: MeetingProcessingControlling {let status: Stringlet completeness: Stringlet isLikelyEcho: Bool?+ let attributionState: String?+ }++ /// Backend-versioned canonical turn policy: how far apart two same-key segments on the+ /// same track may sit and still count as one continuous turn.+ nonisolated static let canonicalTurnMergeGapSeconds: TimeInterval = 3+ /// Backend-versioned canonical turn policy: the longest a merged turn may span before a+ /// new turn starts even with a matching key and no gap.+ nonisolated static let canonicalTurnMaximumDurationSeconds: TimeInterval = 30++ private nonisolated static func canonicalSegmentMergeKey(+ _ segment: MeetingTranscriptSegment+ ) -> CanonicalSegmentMergeKey {+ CanonicalSegmentMergeKey(+ trackID: segment.sourceTrackID,+ speakerID: segment.speakerID,+ overlap: segment.overlap.rawValue,+ status: segment.status.rawValue,+ completeness: segment.completeness.rawValue,+ isLikelyEcho: segment.isLikelyEcho,+ attributionState: segment.attributionState?.rawValue+ )}/// Canonical evidence remains word-granular in the sidecar, but product session JSON and UI- /// rows stay turn-granular. Merge only segments with identical attribution and state, bounded- /// by the same 3-second/30-second policy used by aligned legacy meeting turns.+ /// rows stay turn-granular. Folds each track chronologically and merges only a segment with+ /// the immediately preceding turn on that same track — never across an intervening+ /// different-key segment — so A → B → A stays three turns instead of collapsing the two A+ /// segments around B. A merge additionally requires an identical full attribution/state key+ /// and the named gap/duration turn bounds.nonisolated static func mergeCanonicalSegments(_ segments: [MeetingTranscriptSegment],- maximumGapSeconds: TimeInterval = 3,- maximumDurationSeconds: TimeInterval = 30+ maximumGapSeconds: TimeInterval = MeetingProcessingPipeline.canonicalTurnMergeGapSeconds,+ maximumDurationSeconds: TimeInterval = MeetingProcessingPipeline.canonicalTurnMaximumDurationSeconds) -> [MeetingTranscriptSegment] {- let grouped = Dictionary(grouping: segments) {- CanonicalSegmentMergeKey(- trackID: $0.sourceTrackID,- speakerID: $0.speakerID,- overlap: $0.overlap.rawValue,- status: $0.status.rawValue,- completeness: $0.completeness.rawValue,- isLikelyEcho: $0.isLikelyEcho- )- }+ let byTrack = Dictionary(grouping: segments, by: \.sourceTrackID)var merged: [MeetingTranscriptSegment] = []- for members in grouped.values {+ for (_, members) in byTrack {let ordered = members.sorted {($0.start, $0.end, $0.id.uuidString) < ($1.start, $1.end, $1.id.uuidString)}guard var current = ordered.first else { continue }+ var currentKey = Self.canonicalSegmentMergeKey(current)var memberIDs = [current.id]for next in ordered.dropFirst() {+ let nextKey = Self.canonicalSegmentMergeKey(next)let gap = next.start.seconds - current.end.secondslet combinedDuration = max(current.end.seconds, next.end.seconds) - current.start.seconds- if gap <= maximumGapSeconds, combinedDuration <= maximumDurationSeconds {+ if nextKey == currentKey, gap <= maximumGapSeconds, combinedDuration <= maximumDurationSeconds {current.end = Self.mediaTime(max(current.end.seconds, next.end.seconds))current.text = Self.joinTranscriptText(current.text, next.text)memberIDs.append(next.id)@@ -1666,6 +1685,7 @@ final class MeetingProcessingPipeline: MeetingProcessingControlling {} else {merged.append(current)current = next+ currentKey = nextKeymemberIDs = [next.id]}}diff --git a/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift b/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swiftindex d9e837b2..ad6423b5 100644--- a/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift+++ b/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift@@ -163,7 +163,13 @@ final class MeetingSessionCoordinator: ObservableObject {private enum TranscriptCorrection {case rename(speakerID: SessionSpeakerID, previousName: String)- case reassign(segmentID: MeetingTranscriptSegmentID, previousSpeakerID: SessionSpeakerID?, previousRevision: Int)+ case reassign(+ segmentID: MeetingTranscriptSegmentID,+ previousSpeakerID: SessionSpeakerID?,+ previousOverlap: MeetingTranscriptOverlap,+ previousAttributionState: MeetingTranscriptAttributionState?,+ previousRevision: Int+ )case merge(sourceID: SessionSpeakerID,targetID: SessionSpeakerID,@@ -853,9 +859,17 @@ final class MeetingSessionCoordinator: ObservableObject {throw MeetingDomainError.segmentNotFound}let previousSpeakerID = segment.speakerID+ let previousOverlap = segment.overlap+ let previousAttributionState = segment.attributionStatelet previousRevision = segment.revisiontry session.reassignSegment(id: segmentID, to: speakerID)- return .reassign(segmentID: segmentID, previousSpeakerID: previousSpeakerID, previousRevision: previousRevision)+ return .reassign(+ segmentID: segmentID,+ previousSpeakerID: previousSpeakerID,+ previousOverlap: previousOverlap,+ previousAttributionState: previousAttributionState,+ previousRevision: previousRevision+ )}}@@ -1105,9 +1119,17 @@ final class MeetingSessionCoordinator: ObservableObject {guard let index = session.speakers.firstIndex(where: { $0.id == speakerID }) else { return false }session.speakers[index].displayName = previousNamereturn true- case let .reassign(segmentID, previousSpeakerID, previousRevision):+ case let .reassign(+ segmentID,+ previousSpeakerID,+ previousOverlap,+ previousAttributionState,+ previousRevision+ ):guard let index = session.transcriptSegments.firstIndex(where: { $0.id == segmentID }) else { return false }session.transcriptSegments[index].speakerID = previousSpeakerID+ session.transcriptSegments[index].overlap = previousOverlap+ session.transcriptSegments[index].attributionState = previousAttributionStatesession.transcriptSegments[index].revision = previousRevisionreturn truecase let .merge(sourceID, _, movedSegments):diff --git a/Sources/Fluid/Services/Meeting/MeetingTranscriptExporter.swift b/Sources/Fluid/Services/Meeting/MeetingTranscriptExporter.swiftindex 669a8ac9..702a6db8 100644--- a/Sources/Fluid/Services/Meeting/MeetingTranscriptExporter.swift+++ b/Sources/Fluid/Services/Meeting/MeetingTranscriptExporter.swift@@ -8,11 +8,55 @@ nonisolated enum MeetingTranscriptExporter {.filter { includeEchoes || !$0.isEcho }.sorted { $0.start.seconds < $1.start.seconds }return segments.map { segment in- let speaker = Self.resolvedSpeakerName(segment.speakerID, in: session, speakerNames: speakerNames)+ let speaker = Self.speakerLabel(for: segment, in: session, speakerNames: speakerNames)return "[\(Self.timestampText(segment.start.seconds))] \(speaker): \(segment.text)"}.joined(separator: "\n\n")}+ /// Single resolver for the label shown next to a segment, shared by text export and+ /// `MeetingTranscriptionView` so the transcript and the UI never disagree on what a segment+ /// is called. `attributionState` (when present) is authoritative; its absence means the+ /// segment predates the state and falls back to inferring from `speakerID`/`overlap`.+ static func speakerLabel(+ for segment: MeetingTranscriptSegment,+ in session: MeetingSession,+ speakerNames: [SessionSpeakerID: String]+ ) -> String {+ guard let state = segment.attributionState else {+ if let name = Self.resolvedSpeakerName(segment.speakerID, in: session, speakerNames: speakerNames) {+ return name+ }+ return segment.overlap == .ambiguous ? "Overlapping speakers" : "Unassigned"+ }+ switch state {+ case .assigned:+ return Self.resolvedSpeakerName(segment.speakerID, in: session, speakerNames: speakerNames) ?? "Unassigned"+ case .overlappingSpeakers:+ return "Overlapping speakers"+ case .unassigned:+ return "Unassigned"+ case .timingUncertain:+ return "Timing uncertain"+ }+ }++ /// Presentation grouping key: labels alone are insufficient because two distinct speakers can+ /// legitimately share a display name. The semantic attribution state keeps adjacent nil-speaker+ /// rows such as overlap and timing uncertainty from collapsing into one visual run.+ static func speakerLabelIdentity(+ for segment: MeetingTranscriptSegment,+ in session: MeetingSession,+ speakerNames: [SessionSpeakerID: String]+ ) -> String {+ let label = self.speakerLabel(for: segment, in: session, speakerNames: speakerNames)+ return [+ segment.speakerID?.uuidString ?? "nil",+ segment.attributionState?.rawValue ?? "legacy",+ segment.overlap.rawValue,+ label,+ ].joined(separator: "|")+ }+static func json(for session: MeetingSession) throws -> Data {let speakers = session.activeSpeakers.map {ExportedSpeaker(id: $0.id, displayName: $0.displayName, isLocalUser: $0.isLocalUser)@@ -35,7 +79,8 @@ nonisolated enum MeetingTranscriptExporter {status: $0.status.rawValue,overlap: $0.overlap.rawValue,completeness: $0.completeness.rawValue,- isLikelyEcho: $0.isEcho+ isLikelyEcho: $0.isEcho,+ attributionState: $0.attributionState?.rawValue)}let document = ExportedTranscript(@@ -57,16 +102,17 @@ nonisolated enum MeetingTranscriptExporter {}/// A segment may still point at a speaker that was merged away; walk the alias chain- /// defensively even though post-merge segments are already repointed to the target.+ /// defensively even though post-merge segments are already repointed to the target. `nil`+ /// means no known speaker could be resolved, letting callers apply their own fallback label.private static func resolvedSpeakerName(_ speakerID: SessionSpeakerID?,in session: MeetingSession,speakerNames: [SessionSpeakerID: String]- ) -> String {+ ) -> String? {guard let resolvedID = speakerID.map({ Self.resolvedAliasID($0, in: session) }) else {- return "Unknown speaker"+ return nil}- return speakerNames[resolvedID] ?? "Unknown speaker"+ return speakerNames[resolvedID]}/// The same alias-chain walk as `resolvedSpeakerName`, but returning the id itself so JSON@@ -119,6 +165,7 @@ private struct ExportedSegment: Codable {var overlap: Stringvar completeness: Stringvar isLikelyEcho: Bool+ var attributionState: String?}private struct ExportedTranscript: Codable {diff --git a/Sources/Fluid/UI/MeetingTranscriptionView.swift b/Sources/Fluid/UI/MeetingTranscriptionView.swiftindex 68cc4221..7995b1aa 100644--- a/Sources/Fluid/UI/MeetingTranscriptionView.swift+++ b/Sources/Fluid/UI/MeetingTranscriptionView.swift@@ -2562,12 +2562,22 @@ private struct MeetingResultCanvas: View {self.showsProbableEchoes ? sorted : sorted.filter { !$0.isEcho }}- /// Sorted once with per-row display state — no per-row re-sorting.+ /// Sorted once with per-row display state — no per-row re-sorting. Compares the resolved+ /// displayed label (not the raw speaker id) so consecutive nil-speaker rows in different+ /// attribution states — e.g. `unassigned` then `timingUncertain` — each still show a label.private func rows(for visibleSegments: [MeetingTranscriptSegment]) -> [(segment: MeetingTranscriptSegment, showsLabel: Bool, isLocal: Bool)] {- visibleSegments.enumerated().map { index, segment in- let showsLabel = index == 0 || segment.speakerID != visibleSegments[index - 1].speakerID+ let speakerNames = self.speakerNames+ var previousLabelIdentity: String?+ return visibleSegments.map { segment in+ let labelIdentity = MeetingTranscriptExporter.speakerLabelIdentity(+ for: segment,+ in: self.session,+ speakerNames: speakerNames+ )+ let showsLabel = labelIdentity != previousLabelIdentity+ previousLabelIdentity = labelIdentityreturn (segment, showsLabel, self.isLocalSegment(segment))}}@@ -2644,7 +2654,11 @@ private struct MeetingResultCanvas: View {ForEach(rows, id: \.segment.id) { row inMeetingTranscriptSegmentRow(segment: row.segment,- speakerName: row.segment.speakerID.flatMap { speakerNames[$0] } ?? "Unknown speaker",+ speakerName: MeetingTranscriptExporter.speakerLabel(+ for: row.segment,+ in: self.session,+ speakerNames: speakerNames+ ),speakerTint: row.segment.speakerID.flatMap { speakerTints[$0] },onRenameSpeakerTapped: row.segment.speakerID.map { speakerID in{ self.presentAssignSpeakers(focusing: speakerID) }diff --git a/Tests/FluidDictationIntegrationTests/MeetingParakeetNemotronBackendTests.swift b/Tests/FluidDictationIntegrationTests/MeetingParakeetNemotronBackendTests.swiftindex c5952775..2677c9af 100644--- a/Tests/FluidDictationIntegrationTests/MeetingParakeetNemotronBackendTests.swift+++ b/Tests/FluidDictationIntegrationTests/MeetingParakeetNemotronBackendTests.swift@@ -269,28 +269,43 @@ final class MeetingParakeetNemotronBackendTests: XCTestCase {XCTAssertEqual(selectedDefault.descriptor.id, .parakeetNemotron)}+ // MARK: - Canonical turn merge (chronological fold)++ private func canonicalSegment(+ id: UUID = UUID(),+ trackID: UUID,+ start: Double,+ end: Double,+ speakerID: UUID?,+ text: String,+ overlap: MeetingTranscriptOverlap = .none,+ status: MeetingTranscriptStatus = .final,+ completeness: MeetingTranscriptCompleteness = .complete,+ isLikelyEcho: Bool? = nil+ ) -> MeetingTranscriptSegment {+ MeetingTranscriptSegment(+ id: id,+ start: MeetingMediaTime(value: Int64((start * 1000).rounded()), timescale: 1000),+ end: MeetingMediaTime(value: Int64((end * 1000).rounded()), timescale: 1000),+ sourceTrackID: trackID,+ speakerID: speakerID,+ text: text,+ revision: 0,+ status: status,+ overlap: overlap,+ completeness: completeness,+ isLikelyEcho: isLikelyEcho+ )+ }+func testCanonicalProductPublicationMergesWordEvidenceIntoTurns() {let trackID = UUID()let speakerID = UUID()- func segment(_ text: String, _ start: Double, _ end: Double, speaker: UUID?) -> MeetingTranscriptSegment {- MeetingTranscriptSegment(- id: UUID(),- start: MeetingMediaTime(value: Int64((start * 1000).rounded()), timescale: 1000),- end: MeetingMediaTime(value: Int64((end * 1000).rounded()), timescale: 1000),- sourceTrackID: trackID,- speakerID: speaker,- text: text,- revision: 0,- status: .final,- overlap: .none,- completeness: .complete- )- }let input = [- segment("Hello", 0, 0.2, speaker: speakerID),- segment(",", 0.21, 0.25, speaker: speakerID),- segment("world", 0.3, 0.6, speaker: speakerID),- segment("Other", 0.4, 0.7, speaker: UUID()),+ self.canonicalSegment(trackID: trackID, start: 0, end: 0.2, speakerID: speakerID, text: "Hello"),+ self.canonicalSegment(trackID: trackID, start: 0.21, end: 0.25, speakerID: speakerID, text: ","),+ self.canonicalSegment(trackID: trackID, start: 0.3, end: 0.6, speakerID: speakerID, text: "world"),+ self.canonicalSegment(trackID: trackID, start: 0.4, end: 0.7, speakerID: UUID(), text: "Other"),]let first = MeetingProcessingPipeline.mergeCanonicalSegments(input)@@ -301,6 +316,154 @@ final class MeetingParakeetNemotronBackendTests: XCTestCase {XCTAssertEqual(first.map(\.id), second.map(\.id), "merged turn IDs are deterministic")}+ func testCanonicalMergeKeepsABAAsThreeTurnsInsteadOfBridgingAcrossB() {+ let trackID = UUID()+ let speakerA = UUID()+ let speakerB = UUID()+ // A ends at 1.0, B runs 1.2-1.5, A resumes 1.6-2.0. The two A segments are within the+ // 3s gap/30s duration bounds of each other, but B sits chronologically between them on+ // the same track, so they must not bridge across it.+ let input = [+ self.canonicalSegment(trackID: trackID, start: 0, end: 1.0, speakerID: speakerA, text: "First"),+ self.canonicalSegment(trackID: trackID, start: 1.2, end: 1.5, speakerID: speakerB, text: "Interject"),+ self.canonicalSegment(trackID: trackID, start: 1.6, end: 2.0, speakerID: speakerA, text: "Second"),+ ]++ let turns = MeetingProcessingPipeline.mergeCanonicalSegments(input)++ XCTAssertEqual(turns.count, 3)+ XCTAssertEqual(turns.map(\.text), ["First", "Interject", "Second"])+ XCTAssertEqual(turns.map(\.speakerID), [speakerA, speakerB, speakerA])+ }++ func testCanonicalMergeKeepsAAmbiguousAAsThreeTurns() {+ let trackID = UUID()+ let speakerA = UUID()+ // The ambiguous segment has no resolved speaker and a different overlap state, so its+ // key differs from both surrounding A segments even though all three are on one track.+ let input = [+ self.canonicalSegment(trackID: trackID, start: 0, end: 1.0, speakerID: speakerA, text: "First"),+ self.canonicalSegment(+ trackID: trackID, start: 1.1, end: 1.4, speakerID: nil, text: "Maybe", overlap: .ambiguous+ ),+ self.canonicalSegment(trackID: trackID, start: 1.5, end: 2.0, speakerID: speakerA, text: "Second"),+ ]++ let turns = MeetingProcessingPipeline.mergeCanonicalSegments(input)++ XCTAssertEqual(turns.count, 3)+ XCTAssertEqual(turns.map(\.text), ["First", "Maybe", "Second"])+ XCTAssertEqual(turns.map(\.overlap), [.none, .ambiguous, .none])+ }++ func testCanonicalMergeCombinesAdjacentSameKeySegments() {+ let trackID = UUID()+ let speakerA = UUID()+ let input = [+ self.canonicalSegment(trackID: trackID, start: 0, end: 1.0, speakerID: speakerA, text: "First"),+ self.canonicalSegment(trackID: trackID, start: 1.5, end: 2.0, speakerID: speakerA, text: "Second"),+ ]++ let turns = MeetingProcessingPipeline.mergeCanonicalSegments(input)++ XCTAssertEqual(turns.count, 1)+ XCTAssertEqual(turns.first?.text, "First Second")+ XCTAssertEqual(turns.first?.end.seconds ?? -1, 2.0, accuracy: 0.0001)+ }++ func testCanonicalMergeRespectsMaximumGapBoundary() {+ let trackID = UUID()+ let speakerA = UUID()+ let gap = MeetingProcessingPipeline.canonicalTurnMergeGapSeconds+ let withinBound = [+ self.canonicalSegment(trackID: trackID, start: 0, end: 1.0, speakerID: speakerA, text: "First"),+ self.canonicalSegment(+ trackID: trackID, start: 1.0 + gap, end: 1.0 + gap + 0.5, speakerID: speakerA, text: "Second"+ ),+ ]+ let beyondBound = [+ self.canonicalSegment(trackID: trackID, start: 0, end: 1.0, speakerID: speakerA, text: "First"),+ self.canonicalSegment(+ trackID: trackID, start: 1.0 + gap + 0.01, end: 1.0 + gap + 0.51, speakerID: speakerA,+ text: "Second"+ ),+ ]++ XCTAssertEqual(+ MeetingProcessingPipeline.mergeCanonicalSegments(withinBound).count, 1,+ "a gap exactly at the named maximum still merges"+ )+ XCTAssertEqual(+ MeetingProcessingPipeline.mergeCanonicalSegments(beyondBound).count, 2,+ "a gap past the named maximum starts a new turn"+ )+ }++ func testCanonicalMergeRespectsMaximumDurationBoundary() {+ let trackID = UUID()+ let speakerA = UUID()+ let maxDuration = MeetingProcessingPipeline.canonicalTurnMaximumDurationSeconds+ let withinBound = [+ self.canonicalSegment(trackID: trackID, start: 0, end: 1.0, speakerID: speakerA, text: "First"),+ self.canonicalSegment(+ trackID: trackID, start: 1.5, end: maxDuration, speakerID: speakerA, text: "Second"+ ),+ ]+ let beyondBound = [+ self.canonicalSegment(trackID: trackID, start: 0, end: 1.0, speakerID: speakerA, text: "First"),+ self.canonicalSegment(+ trackID: trackID, start: 1.5, end: maxDuration + 0.01, speakerID: speakerA, text: "Second"+ ),+ ]++ XCTAssertEqual(+ MeetingProcessingPipeline.mergeCanonicalSegments(withinBound).count, 1,+ "a combined duration exactly at the named maximum still merges"+ )+ XCTAssertEqual(+ MeetingProcessingPipeline.mergeCanonicalSegments(beyondBound).count, 2,+ "a combined duration past the named maximum starts a new turn even with no gap"+ )+ }++ func testCanonicalMergeOrdersTurnsDeterministicallyAcrossTracks() {+ let trackA = UUID()+ let trackB = UUID()+ // Two tracks whose turns interleave in time; publication must be sorted globally by+ // (start, end, sourceTrackID, id), independent of input order. Each segment on a track+ // gets a distinct speaker so none of them merge with each other — this test is about+ // publication order, not turn merging.+ let shuffled = [+ self.canonicalSegment(trackID: trackB, start: 0.5, end: 1.0, speakerID: UUID(), text: "B-second"),+ self.canonicalSegment(trackID: trackA, start: 0, end: 0.4, speakerID: UUID(), text: "A-first"),+ self.canonicalSegment(trackID: trackA, start: 1.2, end: 1.6, speakerID: UUID(), text: "A-second"),+ self.canonicalSegment(trackID: trackB, start: 0, end: 0.3, speakerID: UUID(), text: "B-first"),+ ]++ let first = MeetingProcessingPipeline.mergeCanonicalSegments(shuffled)+ let second = MeetingProcessingPipeline.mergeCanonicalSegments(shuffled.shuffled())+ let expectedIDs = shuffled.sorted {+ ($0.start, $0.end, $0.sourceTrackID.uuidString, $0.id.uuidString)+ < ($1.start, $1.end, $1.sourceTrackID.uuidString, $1.id.uuidString)+ }.map(\.id)++ XCTAssertEqual(first.map(\.id), expectedIDs, "global order uses the documented stable sort key")+ XCTAssertEqual(first.map(\.id), second.map(\.id), "turn IDs are deterministic regardless of input order")+ }++ func testCanonicalMergeNeverCombinesAcrossTracksEvenWithSameSpeakerID() {+ let trackA = UUID()+ let trackB = UUID()+ let speakerID = UUID()+ let turns = MeetingProcessingPipeline.mergeCanonicalSegments([+ self.canonicalSegment(trackID: trackA, start: 0, end: 1, speakerID: speakerID, text: "A"),+ self.canonicalSegment(trackID: trackB, start: 1, end: 2, speakerID: speakerID, text: "B"),+ ])++ XCTAssertEqual(turns.count, 2, "track provenance is a hard merge boundary")+ XCTAssertEqual(Set(turns.map(\.sourceTrackID)), [trackA, trackB])+ }+// MARK: - Plan validationfunc testPlanRejectsMissingModelUnsupportedLanguageAndUnsupportedOptions() async throws {@@ -699,6 +862,147 @@ final class MeetingParakeetNemotronBackendTests: XCTestCase {XCTAssertEqual(outside.disposition, .outsideActivity)}+ func testCoverageUnionDoesNotDoubleCountDuplicateSpeakerIntervals() {+ let (slot0, slot1) = self.attributionTokens()+ let activity = [+ MeetingBackendSpeakerActivity(token: slot0, start: 0, end: 0.4),+ MeetingBackendSpeakerActivity(token: slot0, start: 0, end: 0.4),+ MeetingBackendSpeakerActivity(token: slot1, start: 0, end: 0.1),+ ]++ guard case let .ambiguous(tokens) = MeetingParakeetNemotronBackend.assignment(+ start: 0, end: 1, activity: activity, allowDominance: true+ ) else { return XCTFail("unioned 40% versus 10% coverage must not become an 80% dominant assignment") }+ XCTAssertEqual(tokens.map(\.label), ["slot-0", "slot-1"])+ }++ func testAllCandidatesAtOrBelowScaledFloorAreUnassigned() {+ let (slot0, slot1) = self.attributionTokens()+ let decision = MeetingParakeetNemotronBackend.assignment(+ start: 0,+ end: 1,+ activity: [+ MeetingBackendSpeakerActivity(token: slot0, start: 0, end: 0.08),+ MeetingBackendSpeakerActivity(token: slot1, start: 0.92, end: 1),+ ],+ allowDominance: true+ )+ guard case .unassigned = decision else { return XCTFail("sub-frame evidence must not assign a speaker") }+ }++ func testSoleAboveFloorCandidateAssigns() {+ let (slot0, slot1) = self.attributionTokens()+ let decision = MeetingParakeetNemotronBackend.assignment(+ start: 0,+ end: 1,+ activity: [+ MeetingBackendSpeakerActivity(token: slot0, start: 0, end: 0.2),+ MeetingBackendSpeakerActivity(token: slot1, start: 0.95, end: 1),+ ],+ allowDominance: true+ )+ guard case let .assigned(token) = decision else { return XCTFail("the sole significant speaker must assign") }+ XCTAssertEqual(token, slot0)+ }++ func testShortWordDoesNotDiscardEightyMillisecondRunnerUp() {+ let (slot0, slot1) = self.attributionTokens()+ let decision = MeetingParakeetNemotronBackend.assignment(+ start: 0,+ end: 0.15,+ activity: [+ MeetingBackendSpeakerActivity(token: slot0, start: 0, end: 0.15),+ MeetingBackendSpeakerActivity(token: slot1, start: 0.07, end: 0.15),+ ],+ allowDominance: true+ )+ guard case let .ambiguous(tokens) = decision else {+ return XCTFail("80ms is material evidence inside a 150ms word")+ }+ XCTAssertEqual(tokens.map(\.label), ["slot-0", "slot-1"])+ }++ func testSixtyFortyAndFullOverlapRemainAmbiguousWithDeterministicOrder() {+ let (slot0, slot1) = self.attributionTokens()+ for activity in [+ [+ MeetingBackendSpeakerActivity(token: slot0, start: 0, end: 0.6),+ MeetingBackendSpeakerActivity(token: slot1, start: 0.6, end: 1),+ ],+ [+ MeetingBackendSpeakerActivity(token: slot1, start: 0, end: 1),+ MeetingBackendSpeakerActivity(token: slot0, start: 0, end: 1),+ ],+ ] {+ guard case let .ambiguous(tokens) = MeetingParakeetNemotronBackend.assignment(+ start: 0, end: 1, activity: activity, allowDominance: true+ ) else { return XCTFail("material two-speaker coverage must remain ambiguous") }+ XCTAssertEqual(tokens.map(\.label), ["slot-0", "slot-1"])+ }+ }++ func testClearLeaderAndExactDominanceBoundaryAssign() {+ let (slot0, slot1) = self.attributionTokens()+ for leaderEnd in [0.8, 0.5] {+ let runnerEnd = leaderEnd == 0.5 ? 0.2 : 0.15+ let decision = MeetingParakeetNemotronBackend.assignment(+ start: 0,+ end: 1,+ activity: [+ MeetingBackendSpeakerActivity(token: slot0, start: 0, end: leaderEnd),+ MeetingBackendSpeakerActivity(token: slot1, start: 0, end: runnerEnd),+ ],+ allowDominance: true+ )+ guard case let .assigned(token) = decision else {+ return XCTFail("coverage at or beyond every named dominance boundary must assign")+ }+ XCTAssertEqual(token, slot0)+ }+ }++ func testClearPluralityBelowHalfRemainsConservativelyAmbiguous() {+ let (slot0, slot1) = self.attributionTokens()+ let decision = MeetingParakeetNemotronBackend.assignment(+ start: 0,+ end: 1,+ activity: [+ MeetingBackendSpeakerActivity(token: slot0, start: 0, end: 0.45),+ MeetingBackendSpeakerActivity(token: slot1, start: 0, end: 0.10),+ ],+ allowDominance: true+ )+ guard case let .ambiguous(tokens) = decision else {+ return XCTFail("a plurality below the explicit 50% coverage floor must not become confident")+ }+ XCTAssertEqual(tokens.map(\.label), ["slot-0", "slot-1"])+ }++ func testUtteranceFallbackNeverUsesDominanceAcrossTwoSignificantSpeakers() {+ let (slot0, slot1) = self.attributionTokens()+ let decision = MeetingParakeetNemotronBackend.assignment(+ start: 0,+ end: 1,+ activity: [+ MeetingBackendSpeakerActivity(token: slot0, start: 0, end: 0.8),+ MeetingBackendSpeakerActivity(token: slot1, start: 0, end: 0.15),+ ],+ allowDominance: false+ )+ guard case let .ambiguous(tokens) = decision else {+ return XCTFail("epoch-covering utterance timing is too coarse for dominance")+ }+ XCTAssertEqual(tokens.map(\.label), ["slot-0", "slot-1"])+ }++ private func attributionTokens() -> (MeetingBackendSpeakerToken, MeetingBackendSpeakerToken) {+ let epoch = MeetingAnalysisEpochID(trackID: UUID(), ordinal: 0)+ return (+ MeetingBackendSpeakerToken(analysisEpochID: epoch, label: "slot-0"),+ MeetingBackendSpeakerToken(analysisEpochID: epoch, label: "slot-1")+ )+ }+func testProviderAndDiarizerTimesMapThroughActualSpanSampleRanges() async throws {let chunk0 = self.makeChunk(sequence: 0, start: 100, end: 101, path: "tracks/microphone/chunk_0.caf")let chunk1 = self.makeChunk(sequence: 1, start: 101, end: 102, path: "tracks/microphone/chunk_1.caf")diff --git a/Tests/FluidDictationIntegrationTests/MeetingTranscriptAssemblerTests.swift b/Tests/FluidDictationIntegrationTests/MeetingTranscriptAssemblerTests.swiftindex 424de835..6f46beb8 100644--- a/Tests/FluidDictationIntegrationTests/MeetingTranscriptAssemblerTests.swift+++ b/Tests/FluidDictationIntegrationTests/MeetingTranscriptAssemblerTests.swift@@ -554,6 +554,7 @@ final class MeetingTranscriptAssemblerTests: XCTestCase {XCTAssertEqual(matching.count, 1)XCTAssertNil(matching[0].speakerID)XCTAssertEqual(matching[0].overlap, .ambiguous)+ XCTAssertEqual(matching[0].attributionState, .overlappingSpeakers)// Ambiguity candidates are reported, never resolved into product speakers.XCTAssertTrue(result.speakers.isEmpty)}@@ -576,7 +577,10 @@ final class MeetingTranscriptAssemblerTests: XCTestCase {XCTAssertEqual(record.reasonCode, "timingUncertain")let segment = try XCTUnwrap(result.segments.first)XCTAssertNil(segment.speakerID)- XCTAssertEqual(segment.overlap, .ambiguous)+ // Timing uncertainty is not speaker overlap: the segment carries no cross-speaker overlap+ // marker, only the distinct `timingUncertain` attribution state.+ XCTAssertEqual(segment.overlap, .none)+ XCTAssertEqual(segment.attributionState, .timingUncertain)XCTAssertTrue(result.speakers.isEmpty)}@@ -1262,4 +1266,58 @@ final class MeetingTranscriptAssemblerTests: XCTestCase {XCTAssertTrue(result.coverageGaps.isEmpty)XCTAssertFalse(result.isComplete)}++ // MARK: - Attribution state++ func testNormallyEmittedSegmentsCarryAssignedOrUnassignedAttributionState() throws {+ let (plan, manifest, span) = try self.onlineMicFixture()+ let assignedUnit = self.unit(id: "u-assigned", span: span, text: "clear", analysisStart: 1, analysisEnd: 2)+ let unassignedUnit = self.unit(+ id: "u-unassigned", span: span, text: "noEvidence", analysisStart: 3, analysisEnd: 4,+ speaker: .unassigned+ )+ let result = try MeetingTranscriptAssembler().assemble(MeetingAssemblyInput(+ plan: plan,+ manifest: manifest,+ evidence: self.evidence(plan: plan, units: [assignedUnit, unassignedUnit]),+ coverageReceipts: self.receipts(for: manifest),+ echoVerdicts: ["u-assigned": .notEcho, "u-unassigned": .notEcho]+ ))+ XCTAssertEqual(self.dispositions(result)["u-assigned"]?.disposition, .emitted)+ XCTAssertEqual(self.dispositions(result)["u-unassigned"]?.disposition, .emitted)++ let assignedSegment = try XCTUnwrap(result.segments.first { $0.text == "clear" })+ XCTAssertNotNil(assignedSegment.speakerID)+ XCTAssertEqual(assignedSegment.overlap, .none)+ XCTAssertEqual(assignedSegment.attributionState, .assigned)++ let unassignedSegment = try XCTUnwrap(result.segments.first { $0.text == "noEvidence" })+ XCTAssertNil(unassignedSegment.speakerID)+ XCTAssertEqual(unassignedSegment.overlap, .none)+ XCTAssertEqual(unassignedSegment.attributionState, .unassigned)+ }++ /// `attributionState` must stay optional: a non-optional defaulted property makes the+ /// synthesized decoder require the key, and the store silently drops sessions that fail to+ /// decode.+ func testSegmentWithoutAttributionStateKeyStillDecodes() throws {+ let legacySegmentJSON = """+ {+ "id": "3F2504E0-4F89-11D3-9A0C-0305E82C3301",+ "start": { "value": 0, "timescale": 1000 },+ "end": { "value": 1000, "timescale": 1000 },+ "sourceTrackID": "3F2504E0-4F89-11D3-9A0C-0305E82C3302",+ "text": "legacy segment",+ "revision": 0,+ "status": "final",+ "overlap": "none",+ "completeness": "complete"+ }+ """+ let segment = try JSONDecoder().decode(+ MeetingTranscriptSegment.self,+ from: Data(legacySegmentJSON.utf8)+ )+ XCTAssertNil(segment.attributionState)+ }}diff --git a/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swift b/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swiftindex c6451c81..5d7e3958 100644--- a/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swift+++ b/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swift@@ -577,7 +577,7 @@ extension MeetingSessionModelTests {"schemaVersion", "title", "languageCode", "startedAt", "endedAt", "durationSeconds","mode", "applicationDisplayName", "speakers", "id", "displayName", "isLocalUser","segments", "startSeconds", "endSeconds", "speakerID", "text", "revision", "status",- "overlap", "completeness", "isLikelyEcho",+ "overlap", "completeness", "isLikelyEcho", "attributionState",]private func collectDictionaryKeys(in value: Any, into keys: inout Set<String>) {@@ -593,7 +593,7 @@ extension MeetingSessionModelTests {}}- func testTextFormatMatchesTimestampFormatAndUnknownSpeaker() {+ func testTextFormatMatchesTimestampFormatAndLegacyUnassignedSpeaker() {var session = MeetingModelFixture.makeSession()var unknownSpeakerSegment = session.transcriptSegments[0]unknownSpeakerSegment.id = UUID()@@ -601,6 +601,8 @@ extension MeetingSessionModelTests {unknownSpeakerSegment.end = MeetingModelFixture.mediaTime(70)unknownSpeakerSegment.speakerID = nilunknownSpeakerSegment.text = "No speaker text"+ // No attributionState set (nil): exercises the legacy fallback path.+ unknownSpeakerSegment.attributionState = nil// Inserted out of chronological order to prove the exporter sorts by start.session.transcriptSegments.insert(unknownSpeakerSegment, at: 0)@@ -608,10 +610,146 @@ extension MeetingSessionModelTests {XCTAssertEqual(lines, ["[00:04] Speaker 1: Initial provisional text",- "[01:05] Unknown speaker: No speaker text",+ "[01:05] Unassigned: No speaker text",])}+ /// Legacy fallback (no `attributionState`): a nil speaker with ambiguous overlap reads as+ /// "Overlapping speakers" rather than plain "Unassigned".+ func testLegacyNilAttributionStateWithAmbiguousOverlapFallsBackToOverlappingSpeakers() {+ var session = MeetingModelFixture.makeSession()+ var segment = session.transcriptSegments[0]+ segment.id = UUID()+ segment.speakerID = nil+ segment.overlap = .ambiguous+ segment.attributionState = nil+ segment.text = "Crosstalk"+ session.transcriptSegments = [segment]++ XCTAssertTrue(MeetingTranscriptExporter.text(for: session).contains("Overlapping speakers: Crosstalk"))+ }++ /// Legacy fallback still prefers a resolvable speaker name over any overlap-derived label.+ func testLegacyNilAttributionStateWithValidSpeakerResolvesName() {+ var session = MeetingModelFixture.makeSession()+ var segment = session.transcriptSegments[0]+ segment.attributionState = nil+ session.transcriptSegments = [segment]++ XCTAssertTrue(MeetingTranscriptExporter.text(for: session).contains("Speaker 1: Initial provisional text"))+ }++ func testAssignedAttributionStateShowsResolvedSpeakerName() {+ var session = MeetingModelFixture.makeSession()+ var segment = session.transcriptSegments[0]+ segment.attributionState = .assigned+ session.transcriptSegments = [segment]++ XCTAssertTrue(MeetingTranscriptExporter.text(for: session).contains("Speaker 1: Initial provisional text"))+ }++ func testOverlappingSpeakersAttributionStateLabel() {+ var session = MeetingModelFixture.makeSession()+ var segment = session.transcriptSegments[0]+ segment.speakerID = nil+ segment.attributionState = .overlappingSpeakers+ segment.text = "Crosstalk"+ session.transcriptSegments = [segment]++ XCTAssertTrue(MeetingTranscriptExporter.text(for: session).contains("Overlapping speakers: Crosstalk"))+ }++ func testUnassignedAttributionStateLabel() {+ var session = MeetingModelFixture.makeSession()+ var segment = session.transcriptSegments[0]+ segment.speakerID = nil+ segment.attributionState = .unassigned+ segment.text = "No evidence"+ session.transcriptSegments = [segment]++ XCTAssertTrue(MeetingTranscriptExporter.text(for: session).contains("Unassigned: No evidence"))+ }++ func testTimingUncertainAttributionStateLabel() {+ var session = MeetingModelFixture.makeSession()+ var segment = session.transcriptSegments[0]+ segment.speakerID = nil+ segment.attributionState = .timingUncertain+ segment.text = "Late text"+ session.transcriptSegments = [segment]++ XCTAssertTrue(MeetingTranscriptExporter.text(for: session).contains("Timing uncertain: Late text"))+ }++ /// The `assigned` state still walks the alias chain, so a renamed/merged speaker resolves the+ /// same way as the legacy path.+ func testAssignedAttributionStateResolvesThroughAliasChain() throws {+ var session = MeetingModelFixture.makeSession()+ let targetID = UUID()+ session.speakers.append(MeetingModelFixture.speaker(id: targetID, name: "Speaker 2"))+ try session.mergeSpeakers(MeetingModelFixture.speakerID, into: targetID)+ session.transcriptSegments = session.transcriptSegments.map {+ var segment = $0+ segment.attributionState = .assigned+ return segment+ }++ XCTAssertTrue(MeetingTranscriptExporter.text(for: session).contains("Speaker 2: Initial provisional text"))+ }++ func testJSONExportIncludesAttributionStateRawValue() throws {+ var session = MeetingModelFixture.makeSession()+ var segment = session.transcriptSegments[0]+ segment.attributionState = .timingUncertain+ session.transcriptSegments = [segment]++ let data = try MeetingTranscriptExporter.json(for: session)+ let json = try XCTUnwrap(JSONSerialization.jsonObject(with: data) as? [String: Any])+ let segments = try XCTUnwrap(json["segments"] as? [[String: Any]])+ let firstSegment = try XCTUnwrap(segments.first)++ XCTAssertEqual(firstSegment["attributionState"] as? String, "timingUncertain")+ }++ func testJSONExportOmitsAttributionStateWhenLegacyNil() throws {+ var session = MeetingModelFixture.makeSession()+ var segment = session.transcriptSegments[0]+ segment.attributionState = nil+ session.transcriptSegments = [segment]++ let data = try MeetingTranscriptExporter.json(for: session)+ let json = try XCTUnwrap(JSONSerialization.jsonObject(with: data) as? [String: Any])+ let segments = try XCTUnwrap(json["segments"] as? [[String: Any]])++ XCTAssertNil(segments.first?["attributionState"])+ }++ func testSpeakerLabelIdentityDistinguishesSameNameSpeakersAndNilStates() {+ var session = MeetingModelFixture.makeSession()+ let duplicateNameID = UUID()+ session.speakers.append(MeetingModelFixture.speaker(id: duplicateNameID, name: "Speaker 1"))+ var first = session.transcriptSegments[0]+ first.attributionState = .assigned+ var second = first+ second.id = UUID()+ second.speakerID = duplicateNameID+ let names = Dictionary(uniqueKeysWithValues: session.activeSpeakers.map { ($0.id, $0.displayName) })++ XCTAssertNotEqual(+ MeetingTranscriptExporter.speakerLabelIdentity(for: first, in: session, speakerNames: names),+ MeetingTranscriptExporter.speakerLabelIdentity(for: second, in: session, speakerNames: names)+ )++ first.speakerID = nil+ first.attributionState = .overlappingSpeakers+ second.speakerID = nil+ second.attributionState = .timingUncertain+ XCTAssertNotEqual(+ MeetingTranscriptExporter.speakerLabelIdentity(for: first, in: session, speakerNames: names),+ MeetingTranscriptExporter.speakerLabelIdentity(for: second, in: session, speakerNames: names)+ )+ }+/// `isLikelyEcho` must stay optional: a non-optional defaulted property makes the synthesized/// decoder require the key, and the store silently drops sessions that fail to decode.func testSegmentWithoutEchoKeyStillDecodes() throws {@@ -1402,6 +1540,21 @@ final class MeetingSessionModelTests: XCTestCase {XCTAssertEqual(segment.revision, originalRevision + 1)}+ func testReassignAmbiguousSegmentMakesManualSpeakerAssignmentAuthoritative() throws {+ var session = MeetingModelFixture.makeSession()+ let targetID = UUID()+ session.speakers.append(MeetingModelFixture.speaker(id: targetID, name: "Speaker 2"))+ session.transcriptSegments[0].speakerID = nil+ session.transcriptSegments[0].overlap = .ambiguous+ session.transcriptSegments[0].attributionState = .overlappingSpeakers++ try session.reassignSegment(id: session.transcriptSegments[0].id, to: targetID)++ XCTAssertEqual(session.transcriptSegments[0].speakerID, targetID)+ XCTAssertEqual(session.transcriptSegments[0].overlap, .none)+ XCTAssertEqual(session.transcriptSegments[0].attributionState, .assigned)+ }+func testReassignSegmentToSameSpeakerIsNoOp() throws {var session = MeetingModelFixture.makeSession()let segmentID = session.transcriptSegments[0].id