1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
//! The decode-time facts a transcription **run controls** — the RNG draw, the
//! genuinely observed language, the early-stop truncation, a swallowed child
//! error, the worker coordinates its RNG streams rode, and the id-ordinal span
//! it allocated — consolidated into ONE carried record (coremlit issue #14,
//! codex round 6).
//!
//! # Why one record
//!
//! Each of these facts is *born* at the attempt/decode layer, must *survive*
//! every aggregation boundary (temperature-fallback selection, the blank-audio
//! drop, a VAD chunk merge, a streaming finalize, an errored-and-dropped
//! chunk), and is finally *read* by [`Provenance`](crate::audio::whisper::provenance::Provenance)
//! to answer [`Provenance::is_reproducible`](crate::audio::whisper::provenance::Provenance::is_reproducible)
//! and to describe the run. Carrying them as six separate fields — plus two
//! ad-hoc decode-layer sinks and a scatter of `.any()`/`.find_map()`/`.first()`
//! re-aggregations at each merge — is exactly how three of them came to be lost
//! or fabricated at a boundary across six review rounds:
//!
//! - a rejected-because-early-stopped fallback attempt's truncation was read
//! only off the *accepted* attempt, so it vanished when a later attempt was
//! selected (R6-F1);
//! - a merge kept only the *first* child's worker coordinate, collapsing
//! `[0, 2]` and `[0, 1]` to the same record, and a missing/hand-built
//! coordinate defaulted to a fabricated worker `0` (R6-F2);
//! - a merge advanced its running id base per child but never *stored* the
//! aggregate, so a staged re-merge (VAD result → streaming finalize)
//! renumbered segments differently than a one-shot merge (R6-F3).
//!
//! [`TaskFacts`] gives the six facts one home, one [merge law](TaskFacts::merge)
//! that every merge entry point calls, and one serde contract — so a boundary
//! can no longer silently drop or invent one.
//!
//! # Explicit unknown, never a fabricated default
//!
//! Every fact this record carries has an **explicit-unknown** state distinct
//! from any observed value: `None` for [`TaskFacts::observed_language`] and
//! [`TaskFacts::worker_schedule`], and — since codex round 6's post-consolidation
//! F1 — `Option<bool>`'s `None` for [`TaskFacts::drew_from_rng`],
//! [`TaskFacts::early_stopped`], and (codex round 11) [`TaskFacts::had_swallowed_error`]
//! too. A record built from options with no decode to
//! speak for ([`Provenance::from_options`](crate::audio::whisper::provenance::Provenance::from_options)),
//! or a transcript assembled by hand, knows no worker coordinate, witnessed no
//! language, and **cannot observe** whether the decode drew from the sampler, a
//! callback truncated it, or a child error was swallowed — and says exactly that,
//! rather than the worker `0`, `""`-language, or the optimistic `drew = false` /
//! `not-truncated` / `nothing-swallowed` a default would forge.
//!
//! The distinction is not cosmetic, and it is why the merge is **Kleene**
//! three-valued logic rather than a free monoid over `Option<bool>`.
//!
//! - As an **epistemic unknown**, an unknown boolean forces
//! [`is_reproducible_under`](TaskFacts::is_reproducible_under) to answer
//! CONSERVATIVELY: a record that cannot know whether a transcript-controlling
//! event (an RNG draw, a callback truncation) occurred must NOT promise
//! byte-reproducibility. The old `false`-means-both representation handed that
//! promise to a genuinely truncated segment recorded through
//! [`Provenance::for_segment`](crate::audio::whisper::provenance::Provenance::for_segment),
//! whose constructor cannot see the truncation (F1). Only a fact POSITIVELY
//! observed as `Some(false)` — the shape a real decode carries out of the
//! window loop — earns the optimistic answer.
//! - Under [the merge law](TaskFacts::merge) the same unknown OR-s by
//! **Kleene's** rule (`kleene_or`): `Some(true)` absorbs, `Some(false) |
//! Some(false)` stays `Some(false)`, and an unknown mixed with
//! anything-but-true stays unknown (`None | Some(false) = None`) — a
//! contributor that cannot see the fact cannot certify the other's `false`.
//! The OR identity is therefore `Some(false)` (observed-clean), NOT `None`
//! (codex round 8, F2): the pre-round-8 free monoid that treated `None` as the
//! identity let `or_unknown(None, Some(false))` forge an observed-`false` out
//! of an unobserved contributor, so a merge of a genuinely-unknown record into
//! a known-clean one read back reproducible it never earned.
//!
//! Because `None` is no longer the OR identity, [`TaskFacts::unknown`] is no
//! longer the identity of a CONTRIBUTOR fold either. A fold seeds from a
//! separate "no contributor yet" (`TaskFactsAccumulator`) identity and takes the
//! first contributor verbatim, so an all-unknown `unknown()` can never
//! masquerade as the neutral element and silently null a known observation. A
//! **real run** that is watching starts its own fact sink at
//! [`TaskFacts::observed_clean`] (`Some(false)` for both booleans — it has
//! POSITIVELY seen nothing happen yet), so a run that decodes no window at all
//! keeps the reproducible `Some(false)`, while `unknown()` stays reserved for
//! the hand-built, deserialized-absent, and segment-/options-only records that
//! genuinely cannot see (codex round 8, F3).
/// Deserializes a **required but nullable** `Option` field — the same
/// required-field helper [`Provenance`](crate::audio::whisper::provenance::Provenance) uses, so
/// a dropped key is rejected rather than silently read back as `None`.
///
/// Serde's derive special-cases a *missing* `Option` field to `None` even with
/// no `serde(default)` on it, which for [`Self`](TaskFacts)'s explicit-unknown
/// fields would forge "no language observed" / "no worker coordinate" out of a
/// field the writer merely dropped. Naming a `deserialize_with` sends the derive
/// down its required-field path instead: the key must be present, and `null`
/// then carries its real meaning — explicit unknown — and nothing else.
/// **Kleene** (strong three-valued) logical OR over [`TaskFacts`]'s
/// explicit-unknown booleans: `Some(true)` absorbs, `Some(false) | Some(false)`
/// stays `Some(false)`, and an unknown (`None`) mixed with anything-but-true
/// stays unknown — `None | Some(false) = None`, because a contributor that
/// cannot see the fact cannot certify the OTHER contributor's `false` (codex
/// round 8, F2). The full table:
///
/// | a \ b | `Some(true)` | `Some(false)` | `None` |
/// |-------------|--------------|---------------|--------|
/// | `Some(true)` | `Some(true)` | `Some(true)` | `Some(true)` |
/// | `Some(false)` | `Some(true)` | `Some(false)` | `None` |
/// | `None` | `Some(true)` | `None` | `None` |
///
/// The OR **identity is `Some(false)`** (observed-clean), NOT `None`: a genuine
/// unknown poisons the fold, so it can no longer double as the neutral element
/// the way the pre-round-8 free monoid (`None`-as-identity) did — the very
/// conflation that let a merge forge an observed-`false` out of an unobserved
/// contributor. Kleene OR is nonetheless associative and commutative, which is
/// what keeps [the contributor merge](TaskFacts::merge) associative over the
/// tri-state; the fold's own identity moves to `TaskFactsAccumulator`.
const
/// What a transcript's decode knows about the number of segment-id ordinals it
/// **allocated** — the id span [`merge_transcription_results_with_options`](crate::audio::whisper::result::merge_transcription_results_with_options)
/// advances its running base by. **Two states**, because the fact has to tell an
/// EXACTLY-known total apart from a known LOWER BOUND on an otherwise-unknown
/// one, and the pre-round-12 `Option<usize>` could express only "exactly `n`"
/// (`Some(n)`) and "wholly unknown" (`None`) — never "unknown total, but at
/// least `k`" (coremlit issue #14, codex round 12).
///
/// That third state is not hypothetical. A VAD run that drops an errored chunk
/// keeps its SURVIVING chunks' known ordinal count as a lower bound while the
/// dropped chunk's contribution stays unknown; the pre-round-12 `None` — which
/// **absorbed** under [the merge](TaskFacts::merge) — threw that lower bound
/// away, so a staged re-merge, unable to recover the dropped chunk's ordinal
/// from the survivors' extent alone, renumbered a trailing chunk onto an id a
/// one-shot merge left free (the round-12 regression
/// `drop_on_merge_preserves_known_empty_span_after_unknown_prefix`: records
/// `A`=unknown-span-with-a-survivor, `B`=known-empty-span, `T`=a trailing
/// survivor, numbered `[0, 2]` one-shot but `[0, 1]` staged). Carrying the lower
/// bound explicitly makes [the merge](Self::merge) associative **by
/// construction** — every grouping stores the same value, and the id-base
/// advance derives from it — so one-shot and staged merges number identically.
///
/// - [`Exact(n)`](Self::Exact) — the decode allocated exactly `n` ordinals (the
/// old `Some(n)`): a real decode task's own count, or a sum of exacts.
/// - [`AtLeast(k)`](Self::AtLeast) — the exact total is unknown, but at least
/// `k` ordinals were allocated. [`AtLeast(0)`](Self::wholly_unknown) is the
/// WHOLLY-unknown value (the old `None` — a hand-built or deserialized-absent
/// record); an `AtLeast(k)` with `k > 0` carries a genuine lower bound (a
/// dropped-chunk VAD run's surviving span, or an overflowed sum's saturated
/// floor).
///
/// **Not** a reproducibility fact — an in-process merge coordinate — so it plays
/// no part in [`TaskFacts::is_reproducible_under`].
/// A carried record of the decode-time facts a transcription **run controls**,
/// as opposed to the ones its [`DecodingOptions`](crate::audio::whisper::options::DecodingOptions)
/// configure: whether it drew from the token sampler, the language it genuinely
/// observed, whether a progress callback truncated it, the worker coordinates
/// its RNG streams rode, and the segment-id span its decode allocated.
///
/// Lives on every [`TranscriptionResult`](crate::audio::whisper::result::TranscriptionResult)
/// and is embedded verbatim in [`Provenance`](crate::audio::whisper::provenance::Provenance).
/// Build the hand-built / all-unknown value with [`Self::unknown`] and layer
/// facts on with the `with_*` builders; merge two with [`Self::merge`], or fold
/// a whole sequence of contributors with [`Self::fold`].
///
/// [`Self::unknown`] is an **unknown contributor, never a fold identity** — but
/// it is not a blanket absorber. Under [the merge law](Self::merge) an unknown
/// nulls only what an unknown genuinely taints: an observed-`false` boolean
/// (`None | Some(false) = None` under Kleene OR) and an unknown worker schedule.
/// It does NOT erase every observation beside it — a `Some(true)` boolean
/// survives (`None | Some(true) = Some(true)`), an absent
/// [`observed_language`](Self::observed_language) adopts the sibling's ("first
/// observation wins"), and a [`decoded_span`](Self::decoded_span) SUMS:
/// `unknown()`'s [`AtLeast(0)`](SpanKnowledge::wholly_unknown) is the span
/// identity, so a sibling `Exact(3)` merges to `AtLeast(3)`, not away. It is
/// still no fold identity — the Kleene boolean identity is `Some(false)`, not
/// `None`, so seeding a fold with `unknown()` would null the first observed
/// clean draw. The neutral element of a contributor fold is [`Self::fold`] of no
/// contributors, and a real run watching for these facts seeds its own sink at
/// [`Self::observed_clean`].
///
/// ```
/// use coremlit::audio::whisper::task_facts::{SpanKnowledge, TaskFacts};
///
/// // A single run at worker 2 that observed Spanish, drew from the sampler,
/// // was not truncated, and allocated exactly 3 segment ordinals.
/// let facts = TaskFacts::unknown()
/// .with_drew_from_rng(true)
/// .with_observed_language(Some("es".to_string()))
/// .with_worker(2)
/// .with_decoded_span(SpanKnowledge::Exact(3));
/// assert_eq!(facts.decoded_span(), SpanKnowledge::Exact(3));
/// assert_eq!(facts.drew_from_rng(), Some(true));
/// assert_eq!(facts.observed_language(), Some("es"));
/// assert_eq!(facts.worker_schedule(), Some([2].as_slice()));
/// // A hand-built record knows no worker coordinate and cannot observe the draw,
/// // a truncation, or a swallowed error — explicit unknown throughout, never a
/// // fabricated 0/false.
/// assert_eq!(TaskFacts::unknown().worker_schedule(), None);
/// assert_eq!(TaskFacts::unknown().drew_from_rng(), None);
/// assert_eq!(TaskFacts::unknown().early_stopped(), None);
/// assert_eq!(TaskFacts::unknown().had_swallowed_error(), None);
///
/// // `unknown()` is an unknown CONTRIBUTOR, never a fold identity: an unknown
/// // beside an observed-`false` NULLS it. Merging `unknown()` into observed-clean
/// // reads the clean `Some(false)` draw and truncation back as unknown (`None |
/// // Some(false) = None` under Kleene OR), and the reproducibility promise goes
/// // with them. Fold a sequence with `TaskFacts::fold`, never `unknown()` reused
/// // as a seed.
/// let mut clean = TaskFacts::observed_clean();
/// assert!(clean.is_reproducible_under(false));
/// clean.merge(&TaskFacts::unknown());
/// assert_eq!(clean.drew_from_rng(), None, "unknown() absorbed the observation");
/// assert_eq!(clean.early_stopped(), None);
/// assert!(!clean.is_reproducible_under(false), "and flipped reproducibility");
///
/// // But `unknown()` is no blanket absorber: an unknown beside a genuine
/// // observation keeps it. Seeded as `self` and merged with a real contributor,
/// // a `Some(true)` draw survives, an absent language adopts the sibling's, and
/// // the span sums off the `AtLeast(0)` identity to a lower bound.
/// let mut seeded = TaskFacts::unknown();
/// seeded.merge(
/// &TaskFacts::unknown()
/// .with_drew_from_rng(true)
/// .with_observed_language(Some("es".to_string()))
/// .with_decoded_span(SpanKnowledge::Exact(3)),
/// );
/// assert_eq!(seeded.drew_from_rng(), Some(true), "Some(true) survives");
/// assert_eq!(seeded.observed_language(), Some("es"), "absent language adopts sibling");
/// assert_eq!(seeded.decoded_span(), SpanKnowledge::AtLeast(3), "AtLeast(0)+Exact(3)");
/// ```
/// Names every field of [`TaskFacts`] exactly once, generating (for tests) both
/// a `TASK_FACTS_FIELD_NAMES` roster and a compile-time exhaustiveness guard
/// that destructures `TaskFacts` WITHOUT `..`.
///
/// This is what keeps the record's completeness gates honest (coremlit issue
/// #14, codex round 6): add a field to the struct and this guard fails to
/// compile until it is named here, and the new name then lands in
/// `provenance::tests`' task-fact coverage as uncovered until it is exercised by
/// a mutation. So a new run-controlled fact cannot be added to the record and
/// left unread by [`Provenance::for_result`](crate::audio::whisper::provenance::Provenance::for_result).
task_facts_field_names!;
/// The **fold identity** for a merge over CONTRIBUTORS, kept distinct from
/// [`TaskFacts::unknown`] so an unknown contributor can never masquerade as the
/// neutral element (codex round 8, F2). Under the Kleene OR (`kleene_or`) the
/// boolean identity is `Some(false)`, not `None`, so `unknown()` is no longer a
/// left identity of [`TaskFacts::merge`] (`unknown().merge(Some(false))` nulls
/// to `None`). [`Empty`](Self::Empty) is the honest "no contributor merged yet"
/// element: the first contributor is taken **verbatim**, each subsequent one
/// folds in under the merge law, and [`into_facts`](Self::into_facts) of an
/// `Empty` accumulator is `unknown()` — the correct "nothing was observed"
/// answer for zero contributors.
///
/// Consumed by [`merge_transcription_results_with_options`](crate::audio::whisper::result::merge_transcription_results_with_options)'s
/// task-facts fold and by [`LocalAgreement`](crate::audio::whisper::stream::agreement::LocalAgreement)'s
/// finalize sink (codex round 8, F1).
pub