Skip to content

fix(batch): read gapped, unframed raw-live packs through their custody manifest - #25045

Merged
Git-on-my-level merged 3 commits into
mainfrom
lane/gappedpacks
Nov 14, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
lane/gappedpacks

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

What changed and why

The #25000 orphan repair's retained proof recovers nothing from the 10,942
sealed-and-received stale batch_live candidates: every sampled candidate's
retained raw-live objects are gapped and unframed, and
raw_audio_read.list_packs skipped every such pack. This change reads those
packs through the custody manifest the writer already committed, so listing,
decoding, and the retained proof all see the audio that is actually there.

Gap semantics (base 9c051da5be4b).

  • backend/utils/other/raw_audio.py:156-160 (CapturePack.append): gap_count
    increments when the next frame's server-projected timestamp differs from the
    previous frame's end by more than 2 ms, and again for every retained
    zero-sample frame. It is a count of discontinuities, not a duration.
  • backend/utils/other/raw_audio.py:196-199 (CapturePack.encoded):
    capture_start/capture_end span the whole wall interval, while the omi-wal
    payload is only the concatenation of captured packets. Decoded PCM is
    therefore shorter than the wall span by the total gap time.
  • backend/utils/other/live_audio_archive.py:253-260 (_write): frame_schema
    is set only when framed_pack(uid) (AUDIO_CUSTODY_FRAMED_PERCENT) admits the
    owner and every frame has samples. The default fleet therefore writes gapped
    packs with gap_count != 0 and no frame table in the media metadata.
  • backend/utils/other/audio_outbox.py:82-119 (commit_capture): the custody
    manifest is written for every durable pack under the same name as the media,
    but custody_manifest_path is recorded in the media metadata only when framed.
    The manifest is the writer's own record of each frame's byte range, sample
    count, and capture start, so it is the only truthful source for a gapped
    pack's internal gap positions.
  • backend/utils/other/raw_audio_read.py:72 (base): (not framed and int(metadata['gap_count']) != 0) skipped the pack outright.
  • backend/utils/other/raw_audio.py:113-116 (base): the opus omi-wal decoder
    decoded the container as one continuous stream, which would have closed the
    writer's gaps.

What the change does.

  • list_packs resolves a gapped, unframed pack's manifest from one
    audio-outbox/{uid}/{conversation_id}/ prefix listing and emits one entry per
    contiguous run, with raw_offset_samples into the unchanged pack and the
    frame's true start. Gaps stay explicit; nothing is closed or resampled
    across them.
  • _decode_pack measures the expected length from the sum of recorded samples
    and decodes through decode_capture_frames, which verifies each packet
    against the manifest's byte range and digest and skips retained zero-sample
    frames.
  • retained_record_units now honors raw_offset_samples and the fragment span.
    Without that, a multi-entry pack was read whole for every entry, duplicating
    audio and closing the writer's gaps.
  • A missing, ambiguous, or mismatched manifest keeps the pack excluded. No audio
    is fabricated, no timestamp is shifted, and no retained bytes are deleted.

Product invariants affected

none

Tuning

No numeric capacity, rate, or budget changed. The only new knob is the
default-on ops kill switch RAW_LIVE_GAPPED_PACKS_ENABLED; there is no percent
ramp. The extra I/O is one audio-outbox prefix listing per conversation that
actually contains a gapped, unframed pack, plus one small manifest read per such
pack; both are bounded by the existing max_count/deadline budget and the
existing 120 s pack-index cache.

New states and exits

No new repair disposition or exit. sealed_received_audio_seconds now counts
only captured samples (gap time excluded); sealed_received_stt_seconds still
spans the gap because that silence is what a batch provider is billed for. A
gapped pack whose manifest cannot be resolved keeps today's behavior: it is not
listed, and the row still exits storage_empty_received / operator_rerun.

How it was verified

Repository BasedHardware/omi, worktree
/Volumes/Ephemeral/scratch/worktrees/omi/omi-lane-gappedpacks-upstream-keep-clean,
branch lane/gappedpacks, base origin/main 9c051da5be4b.

  • Production object metadata only under ro-prod (no content reads, no uids
    or paths printed): of 2,000 listed raw-live/ objects, 1,169 had
    gap_count != 0; 1,168 of those were opus with no frame_schema, and 1,168
    had no pcm_sha256. A 25-object check confirmed each gapped pack has exactly
    one audio-custody-manifest-v1 object under the matching audio-outbox name.
    This establishes the field shape the fixtures reproduce; it is not a fleet
    repair measurement.
  • backend/tests/unit/test_raw_live_gapped_packs.py (new, 10 tests) drives the
    real writer (CapturePack + commit_capture) to produce the production
    object shape, then exercises listing, decode, proof spans, materialization,
    the zero-sample-frame case, the kill switch, a missing manifest, the
    continuous-pack regression, and the framed path.
  • Regression suites, all green: test_audio_custody_frames,
    test_audio_durable_outbox, test_audio_projection_raw_read,
    test_audio_chunk_archive_listing, test_audio_raw_read_metrics (287
    passed); test_record_orphan_repair, test_record_gap_fill,
    test_source_audio_listing, test_record_seal_*, test_record_partial,
    test_restore_recording_obligation (443 passed); test_sync_ingest_archive,
    test_batch_pipeline_custody_property, test_audio_cleanup_custody,
    test_batch_cleanup_custody, test_sync_playback_frame_alignment,
    test_conversation_frame_evidence (106 passed);
    scripts/test_check_feature_flag_registry.py (109 passed).
  • scripts/check_feature_flag_registry.py reports OK; the registry doc was
    regenerated from config/feature-flags.yaml.

Not verified: no production audio was decoded, no repair was planned or applied,
and the #25000 apply path is untouched and stays off. The fleet-wide
register-versus-park count remains unmeasured.

Tests

backend/tests/unit/test_raw_live_gapped_packs.py is the regression test that
would have caught this: before the change, list_packs returned [] for a
gapped, unframed pack and read_pack raised CoverageMismatch. It also pins
retained_proof's span accounting (audio_seconds excludes the gap,
stt_seconds includes it) and the materialized unit's silence fill at the true
capture positions.

UI-Evidence: none -- backend change only

Failure class (fixes)

Failure-Class: FC-capture-session-window-read-as-content-duration

The capture window (capture_start..capture_end) bounds the content; it is
not the content duration. The base decoder measured the expected decoded length
from that wall span, and a naive proof would have counted gap time as audio. The
content duration is the sum of the writer's recorded frames, which is what
sealed_received_audio_seconds now reports.

Rollback

Set RAW_LIVE_GAPPED_PACKS_ENABLED=false (or 0/off/no) to restore the
previous skip in both listing and decoding. The switch does not change the
writer, the manifest format, or the framed path, so a code rollback is also
safe: no stored bytes or metadata are rewritten.

View guided diff Turn on auto-fix

Git-on-my-level and others added 3 commits November 10, 2026 19:17
…y manifest

A live capture pack can carry gap_count != 0 without a declared frame_schema.
CapturePack.append counts a capture-clock discontinuity and a retained
zero-sample frame alike, while capture_start/capture_end span the whole wall
interval. LiveAudioArchive only declares frame_schema when the framed cohort
admits the owner, so the default fleet writes gapped packs with no frame table
in the media metadata. raw_audio_read skipped every such pack, and the decoder
measured its expected length from the wall span, so nothing could be listed or
decoded.

commit_capture always writes the custody manifest beside the media under the
same name, even when the media metadata omits custody_manifest_path. Read that
manifest for gapped, unframed packs and position each recorded frame on the
capture clock: listing emits one entry per contiguous run, decoding walks the
recorded frames and verifies each packet against the manifest, and gaps stay
explicit. retained_record_units now honors raw_offset_samples and the fragment
span, so a multi-entry pack is no longer read whole for every entry.

RAW_LIVE_GAPPED_PACKS_ENABLED is a default-on ops kill switch; off restores the
previous skip. No audio is fabricated, no timestamp is shifted, and no retained
bytes are deleted.
…e retained proof

The retained proof reads every chunk through read_reference, which decoded
raw-live packs with decode_capture. A gapped pack's retained zero-sample
frames are not decodable opus packets, so the proof still failed on exactly
the packs this change targets. Resolve the writer's custody manifest in
read_reference and decode through decode_capture_frames for omi-wal packs;
gapped flac/pcm16 packs keep the ordinary decoder because their encoded bytes
are the contiguous captured PCM.

Also key the conversation manifest index by the writer's shared name so a
single-segment pack name matches, and compare the next overlap against the
raw fragment's tail rather than the whole pack.
…ode-deepseek-v4/cba7b8268396

# Conflicts:
#	config/feature-flags.yaml
@Git-on-my-level
Git-on-my-level merged commit 511588c into main Nov 14, 2026
59 of 60 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/gappedpacks branch November 14, 2026 11:34
Git-on-my-level added a commit that referenced this pull request Nov 20, 2026
## What changed and why

Quarantine recovery re-reads only the mismatched retained source, once,
under the same privacy and generation fences. Both reads must disagree
with the manifest's SHA-256 of decoded PCM before recovery commits
`failed_held` with `retained_digest_changed`. The successful CAS emits
the bounded `omi_fallback_total` reason; the task receives 200 and
duplicate deliveries and automatic redrive do not retry the source. A
matching confirmation resumes ordinary recovery. Storage outages,
missing inputs, invalid manifests, and switched-off target 409s keep
their existing paths.

The SHA-256 check, custody, expiry/deletion policy, and reviewed
operator redrive are unchanged. Set
`BATCH_PIPELINE_RETAINED_DIGEST_HOLD_ENABLED=false` to restore the
legacy single-read 500 for new mismatches without altering existing held
rows. Recovery, merge, projection, expiry, and metrics readers are
listed in `backend/utils/batch_pipeline/CONTRACT.md`.

State exit: retained_digest_changed is a refusal reason on the existing
terminal failed_held state. Normal retained dead-letter expiry still
applies, and only a reviewed operator redrive can requeue the row.

### Cause evidence

An offline native-Opus probe reproduced the exact digest failure with
identical object bytes and generation. Admission's
`source_metadata=True` read used the frame table to skip a zero-sample
diagnostic packet; recovery used the plain decoder, which decoded that
packet. The asymmetric branch arrived in #25045, before #25675. A
rewrite to a different generation cannot satisfy the pinned read. This
proves a decoder path can cause the error without a rewrite; it does not
identify the affected production cohort or establish the rollout
trigger. This change does not alter decoder selection or regenerate
manifests.

## Product invariants affected

none

## How it was verified

- M1, Python 3.11: `env PYTHON=.venv/bin/python bash test-preflight.sh`
passed all 18 checks.
- M1, `BACKEND_PYTEST_WORKERS=2 bash test.sh` with 10 selected unit
files: digest, invalid/missing inputs, artifacts, serving, held
dead-letter, projection exception taxonomy, pipeline sim, flag budget,
and quarantine recovery. All selected files passed after rerunning the
three affected fixture/flag files.
- Held-custody, recovery-admission, and recovery-custody conformance:
112 simulator cases passed; 56 Firestore emulator cases skipped because
no loopback emulator was running.
- `make preflight` passed all 44 checks; the offline native-Opus decoder
probe passed.
- Not verified: the post-deploy one-hour error window. No production
reads, writes, merges, or deploys for this PR.

## Tests

`backend/tests/unit/test_batch_pipeline_retained_digest_hold.py`
exercises the real FastAPI handler, manifest materialization, and
recovery transactions with synthetic pinned reads. It covers confirmed
mismatch, delivery replay, transient mismatch, read outage, rollback,
stale intent, changed URI, privacy revocation, and automatic versus
reviewed redrive.

## UI evidence

UI-Evidence: none -- backend recovery only

## Failure class (fixes)

Failure-Class: FC-batch-fault-domain-head-of-line-poison


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/25761?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<a
href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/25761?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F25761&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant