Skip to content

v1.0.571+1490-android-cm

@Git-on-my-level Git-on-my-level tagged this 22 Oct 18:15
## What

Implements David's 2026-10-22 ruling (**P71**): for Omi BLE devices,
durably
store the device's **original Opus frames as captured**, next to the
decoded
PCM16, going forward. Existing PCM stays. Opus is ~60–100× smaller than
PCM16
(today `chunks/*.batch.enc` PCM alone is ~393 GiB/day).

The as-captured container already exists merged-dark from #21528
(raw-live
WAL packs, shared AES-GCM envelope, reader fallbacks, retirement proof).
This
PR turns its fleet phases on by default and gives Phase 2 its own ramp
knob;
it does not invent a new container.

## Changes

- **`backend/config/audio_archive.py`** — `LIVE` (dual-write original
Opus
WAL / lossless FLAC packs under `raw-live/`) and `READ` (readers prefer
  raw, decode PCM16 on read, fall back to stored PCM chunks) become
  **flag-only fleet phases, default on**. Kill switches:
`AUDIO_ARCHIVE_LIVE_ENABLED=false` / `AUDIO_ARCHIVE_READ_ENABLED=false`
(per service). No percent cohort gates them anymore — a percent gate
would
  keep LIVE silently dark wherever `AUDIO_ARCHIVE_PERCENT` is unset.
- **Phase 2 (`STOP_PCM`, stop the PCM write)** — stays default off and
now
  ramps on a dedicated **`AUDIO_ARCHIVE_STOP_PCM_PERCENT`** (default 0),
because `AUDIO_ARCHIVE_PERCENT` is pinned at 100 fleet-wide for
COALESCE.
  The skip still requires READ plus the unchanged `verified_pcm_paths`
  byte-exact coverage+identity proof (16 kHz mono opus/flac, zero gaps,
  whole-pack capture-PCM SHA or byte-identical decode). Multi-channel,
  non-16 kHz, aac/lc3 sources and any coverage hole keep the PCM write.
- **Manifests** — `AUDIO_ARCHIVE_LIVE/READ_ENABLED=true` across the six
  runtime_env services and both listen/pusher charts (dev+prod);
`AUDIO_ARCHIVE_STOP_PCM_PERCENT` declared beside `AUDIO_ARCHIVE_PERCENT`
in every surface (added to the existing workstream B
duplicate-declaration
  allowlist in `scripts/check_feature_flag_registry.py`).
- **Registry** — LIVE/READ rows are now default-on ops_kill kill
switches;
  STOP_PCM_ENABLED/`_PERCENT` rows carry the ramp. Docs updated
(`runbooks/sync-ingest-archive.md`, `docs/listen_pusher_pipeline.mdx`).
- **Tests** — fleet defaults + kill switches; live pack kill switch
(append
with consent writes nothing when LIVE=false); invalid percent fails
closed
  on both knobs; STOP_PCM isolation from the shared percent + cohort
  stability; batch payload still downloaded exactly once under READ.
  Existing tests already pin the round trip (packet-exact + sample-exact
  native-Opus replay through `archive_capture_bytes` → `read_pack`), the
reader fallbacks, the encryption envelope (`[4B BE len][12B
nonce][AES-256-GCM
  ct+tag]`, HKDF per-uid key) and the byte-exact PCM retirement proof —
  unchanged by this PR.

## Codec facts (inventory)

Omi BLE opus devices capture 16 kHz mono (`opus` 8 kB/s wire,
`opus_fs320`
16 kB/s; `opus_fs320` normalizes to `opus` before decode). One websocket
message = one self-describing Opus packet; the raw-live WAL container
prefixes each packet with a uint32le length, so per-frame device framing
is
fully recoverable (`packet_provenance` reads nb_frames from packet
headers).
pcm8/pcm16 are stored losslessly as FLAC in raw-live; aac/lc3 packs are
stored but never serve reads. Non-Opus/lossless or non-16 kHz sources
never
qualify for STOP_PCM.

## Phase 2 ramp plan (lead expands)

1. **0** until the LIVE+READ soak is clean (archive objects/bytes
growing
with intake, `omi_fallback_total{component=pusher,reason=upload_failed}`
   ≈ 0, batch STT success + shadow WER parity flat, playback/audio-merge
   build errors flat).
2. **5%** via `AUDIO_ARCHIVE_STOP_PCM_PERCENT` for ≥12 h.
3. **100%** after the lead reviews the 5% readout.
Metrics: `omi_audio_archive_pcm_writes_avoided_total` tracks the cohort
share; rollback = percent to 0 first, then the ENABLED flag; keep READ
on
   for raw-only history until PCM regeneration is verified.

## Exposure notes

- Storage: raw adds ~1/60–1/100 of PCM volume (~4–7 GiB/day vs 393)
while
  dual-writing; net reduction starts only at Phase 2.
- Reads: READ adds one metadata fetch per legacy spanless chunk read
before
the data fetch; for raw-covered spans it replaces per-chunk data fetches
  with one pack fetch per ~60 s span. Reviewed behavior from #21528,
  unchanged here.
- Per-user consent (`private_cloud_sync_enabled`) still gates every raw
  write; deletion purges `raw-live/` (conversation and account level).

## Verification

- `BACKEND_UNIT_TEST_FILE_LIST=… bash backend/test.sh` (11 files: sync
ingest archive, storage opus encoding, batch upload storage, runtime env
  validator + render, pusher config refs, rollout cohort deploy/parity,
  create_audio_files_from_chunks, round4 reconnect inventory, staging
  mirror): **75 passed**; storage_opus_encoding: 36 passed, 11 skipped.
- `bash backend/scripts/pre-deploy-check.sh` (venv 3.11): **341
passed**,
  checks passed.
- `python3 backend/deploy/compose_runtime_env.py`,
  `python3 scripts/render_feature_flag_registry.py`,
`python3 scripts/check_feature_flag_registry.py`: clean/idempotent post
  merge of latest main (130ab16a322).
- Layer measured: hermetic backend unit tests + static manifest/registry
  contracts. No deploy; no prod behavior change until the next service
  deploys pick this up.

## Product invariants affected

- INV-MEM-4

Failure-Class: none

(cf5f9fd: LIVE-default admission ran before the host consent attribute
read,
crashing receiver test doubles whose host lacked
`private_cloud_sync_enabled`;
same object shape as production, so the fix reads consent first via
getattr
and no-ops — defect introduced and fixed within this PR, no cataloged
class
applies.)

## Follow-up commits in this PR

- cf5f9fd15d — LIVE default-on made `LiveAudioArchive.append` evaluate
  admission before the host consent attribute; hosts without
`private_cloud_sync_enabled` (six receiver test files on CI) crashed the
receive loop. Consent is now read first (getattr, no-op default) —
hardens
  the fleet flip for any older host shape.
- fixture maintenance — `scripts/test_check_feature_flag_registry.py`
default
  `review_by 2026-10-15` crossed its 7-day overdue grace on 2026-10-22,
making the pre-push registry-fixture gate date-deterministically red on
main for every lane; default bumped to 2026-11-15 (dedicated grace tests
  pin their own dates). Known-red row logged with the swarm lead.

## Deploy needed (lead owns)

backend / backend-sync / backend-sync-backfill / backend-integration
(Cloud
Run) and listen + pusher (GKE charts) on the merged main. Killing the
feature = `AUDIO_ARCHIVE_LIVE_ENABLED=false` (+`READ_ENABLED=false`) on
the
affected service.

INV-DATA-1: no production account data was read; analysis is code-level
+
metadata-only storage reports cited from the ruling.
Assets 2
Loading