Skip to content

fix(batch): dark exits for orphaned in-progress batch-live captures (quiet empty exit + digest-approved repair) - #25000

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

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

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Requested by David (P0, user-visible data loss: lead2 freeze exemption 8c0822)

What changed and why

Some batch_live_v1 captures stay in_progress forever. Their live session ended, quiet finalization was never armed, and no batch job exists, so nothing server-side ever closes them. On Home they show as stuck or empty rows. This PR adds two dark exits:

  1. Quiet-check empty exit (QUIET_EMPTY_EXIT_ENABLED, default off). Only an exactly owned, proven-empty row qualifies: received=false, no audio/window metadata, no producer tokens or upload failure, an empty storage proof, and the existing expired-lease fence. Such a row exits through the existing lifecycle delete transaction. Every other shape (unowned, markerless, any token, pre-pointer chunks) takes exactly the base path. A row the check can't decide (unknown lease, missing marker) retires its quiet obligation instead of rearming forever, and the repair counts it as operator_review.
  2. Digest-approved orphan repair (BATCH_LIVE_ORPHAN_REPAIR_ENABLED, default off), an operator CLI that is never scheduled. Dry-run by default, it reports aggregate counts only, including retained-span audio seconds for STT sizing. Apply needs --apply --approve-plan-sha256 <digest>, at most 128 rows per page. A sealed capture with received audio is proven against immutable retained audio, then one fenced transaction stamps window/content, completes the capture barrier and creates the canonical batch job, which exits through the normal batch pipeline. Owner-level privacy (consent, deletion, protection) is checked before any row read. Capture-level privacy reads only the three privacy fields before refusing. Discovery is identity-only.

Raw audio and GCS objects are never deleted. No live.py, timer, due or dispatch changes (#24866). Runbook: backend/deploy/record-orphan-repair/README.md. Design: the orphan scope findings (group B of David's Processing rows).

Tuning

  • max_count new: 4096 on the repair's retained-archive listing. Before: 0 listings per orphan (no repair existed). After: at most 1 listing of up to 4096 objects per repaired capture, the same bound the record seal/no-job repair uses. A larger archive refuses the capture (parked), not a partial proof.

New states and exits

  • privacy_skipped: no data mutation and no storage proof. Exit: an operator re-run after the owner's consent or privacy state changes (runbook "Dispositions and exits"). The row stays as it is, so nothing loops.
  • operator_review (lease_unknown, barrier_mismatch): exit is an operator decision recorded in the runbook. The quiet obligation is retired, so nothing rearms.
  • registered: exit is the normal batch pipeline. empty_deleted: exit is the noise/discard terminal through the existing lifecycle delete.

Product invariants affected

  • Every new disposition names its exit; no row rearms forever.
  • Never delete raw audio.
  • Both switches default off; activation and any prod APPLY need explicit approval (APPLY and delete-empty: David).

How it was verified

  • Quiet finalization, orphan repair and recording-session suites through bin/omi-heavy with GCP credentials unset: 243 passed on the final head. Pyright: 0 errors. Repository preflight: 44 checks passed (serial, 900 s file budget).
  • Independent Luna reviews: correctness SHIP (round 2), custody/privacy SHIP (round 3 delta at fa502de, which ran 21 focused privacy/discovery tests).

Tests

test_conversation_quiet_finalization.py (the custody fence matrix, unowned-with-token and pre-pointer-chunks regressions, retire-instead-of-rearm), test_record_orphan_repair.py (privacy ordering with read-recording fakes, dry-run with/without --next-file, operator_review dispositions, audio deletion never called), recording-session tests.

UI evidence

UI-Evidence: none -- backend change only

Failure class (fixes)

Failure-Class: FC-session-owned-job-stranded-after-owner-death

Rollback: both switches are off by default. If enabled, set them false; committed jobs drain normally. Code rollback: revert both commits.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

@Git-on-my-level Git-on-my-level self-assigned this Nov 9, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T16:22:17.638622Z cad08bb New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa502de334

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +71 to +72
from database._client import get_firestore_client
from utils.other.storage import list_audio_chunks

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Move the new helper imports to module scope

The new function-local imports violate backend/AGENTS.md's explicit requirement: “All imports at module top level — never inside functions.” Move these imports, along with the additional get_firestore_client import inside the deletion guard, to the module-level import block. Preserve lazy client construction by continuing to call get_firestore_client() only when needed.

AGENTS.md reference: backend/AGENTS.md:L168-L168

Useful? React with 👍 / 👎.

Comment on lines +233 to +235
'server_batch_audio_end': proof['end'],
'started_at': datetime.fromtimestamp(proof['start'], timezone.utc),
'finished_at': datetime.fromtimestamp(proof['end'], timezone.utc),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Validate the existing capture tail before replacing its bounds

If a sealed orphan already has a committed audio window extending beyond the retained objects, the repair still selects register and replaces both server_batch_audio_end and finished_at with the shorter proof endpoint. For example, a row ending at timestamp 200 with retained audio covering only 100–113 is admitted and rewritten to end at 113. The normal live.admit_recording tail checks then pass because both the conversation and registration snapshot contain that rewritten endpoint, silently accepting a truncated recording instead of preserving the missing-tail obligation. Validate the retained units against the original committed endpoint before applying this patch, and refuse repair when that tail is missing.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cad08bbc09

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +171 to +175
elif quiet_empty_exit_enabled():
# A failed empty admission has no attempt budget. Keep custody and
# hand it to repair rather than repeatedly dispatching a refusal.
checks_db.stop_quiet_check(
job_id,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the quiet obligation when a live session wins the race

With QUIET_EMPTY_EXIT_ENABLED=true, a reconnect between evaluation and deletion can renew the recording lease, causing delete_empty_recording_conversation() to correctly return false. This branch nevertheless retires the reserved successor check. Reconnecting callers do not necessarily protect themselves by arming again: arm_quiet_check() reuses the existing generation when its wake is already earlier than the requested deadline. If that session subsequently crashes before teardown, its durable recovery obligation has been canceled; for an unowned V2 capture, the named orphan-repair exit also cannot help because candidate_refusal() requires record_lane_owner == 'batch_live_v1'. Recheck the refusal transactionally and preserve/reschedule the check when a renewed lease or newly arrived content prevented deletion.

Useful? React with 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 3bc38b2 into main Nov 9, 2026
61 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/orphans branch November 9, 2026 17:31
Git-on-my-level added a commit that referenced this pull request Nov 14, 2026
…y manifest (#25045)

## 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.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/25045?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/25045?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F25045&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