Skip to content

feat(playback): count on-demand outcomes; turn it on for dev qualification - #24165

Merged
Git-on-my-level merged 2 commits into
mainfrom
lane/playback-on-demand-dev
Oct 31, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
lane/playback-on-demand-dev

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

David approved graduating PLAYBACK_ON_DEMAND_ENABLED on 2026-10-20
(DEC-BTR-004; feature-flags.yaml row: dev open/play/download,
changed-source and duplicate-task qualification, then one API+sync
train, done by 11-08, gate removed by 11-15). It is still false on
every host. This turns it on for every dev host so the qualification
can run; prod stays false in this change.

Why now (prod, ro-prod metrics, 10-31): the audio-merge queue has been
pinned at its ~20 dispatches/s cap since 10-26 12Z (71.9k attempts/h,
1.72M/day vs ~0.83M/day on 10-20..24) with a backlog that peaked at
765k on 10-29. Only ~423k/day of those runs write an artifact
(omi_playback_writes_total generated); about 65% end in uncounted
no-op outcomes. The cause is the eager enqueue path: every /urls poll
(3 s re-poll hint) re-creates the named merge task for any
conversation that has not converged to cached, once the ~1 h task-name
tombstone expires, and the eager fingerprint hashes volatile audio-file
IDs (runbooks/playback-write-amplification.md). The private-cloud-sync
bucket carries about +16.7M Class A ops/day over the 10-20..23
baseline (List 4.7M -> 8.0M, Write 2.6M -> 6.8M, metadata 1.5M ->
11M), ≈ $85/day before replication. On demand suppresses completion
and pipeline enqueues, makes /urls tasks converge after one build, and
switches to the stable source-manifest fingerprint.

Failure visibility: attempts, queue depth and bucket ops all fall when
dispatch or builds fail, so they cannot gate this graduation alone. The
audio-merge route now records every on-demand task's outcome in
omi_playback_artifacts_total{representation,outcome} (built, exists,
superseded, unavailable, failed_final, retry, locked,
destructive_deferred, chunks_missing, empty_audio, no_audio_files,
deleted_conversation, invalid_payload, error, other); an unhandled
exception counts as error and re-raises. Eager tasks are not counted
here (the existing deferred count is unchanged); the inline file
'built' count moved into the wrapper. The labeling lives in
utils/sync/repeat_work_metrics.py; sync.py keeps only the route
wrapper.

Line-Count-Exception: backend/routers/sync.py | 4134 -> 4152 | thin route wrapper so every on-demand outcome is counted at one seam instead of a dozen return points

Change: dev overlay sets the flag true on backend, backend-sync,
backend-sync-backfill, backend-integration, backend-listen and pusher;
dev listen and pusher chart values match; runtime_env.yaml recomposed;
registry re-rendered; two dev env fixtures follow the new value.

Dev qualification (before any prod change), per the registry note:

  • open/play/download of an existing and a new conversation returns
    playable audio; first-play build completes and later opens hit cache;
  • a changed source (late chunk / merge) rebuilds once and never serves
    stale audio;
  • concurrent /urls polls create one task (no duplicate builds);
  • audio-merge attempts per played conversation fall to ~1.
    Then prod: one change flipping the prod overlay and listen/pusher
    charts, rolled by the rollout lead with 24 h watches (unchanged
    bytes/seek, no stale-source reuse, no play failure or latency
    increase; on-demand failure share
    (failed_final+unavailable+chunks_missing+empty_audio+error over all
    on-demand outcomes) not above the dev baseline; audio-merge attempts < 400k/day and depth < 10k sustained;
    bucket Class A <= 10M/day). The switch has no uid cohort (global
    boolean), so prod goes host-wide, not 5/25/100.

Rollback: set the flag false (stored artifacts are never deleted on
rollback; eager paths resume). Raw audio and custody are untouched;
only the derived playback/ prefix is written.

Validation: backend/test.sh on the new test_playback_demand_outcomes,
test_audio_merge_tasks, test_audio_merge_destructive_deferral, runtime env validator, cross-service
deploy contract, listen helm defaults, audio fleet helm, Cloud Run env
drift, pusher cohost/config references, repeat-work cuts, playback
idempotency, audio fingerprint and chunk-archive listing: all passed.

Product invariants: INV-MEM-4. Memory admission and capability
contracts are unchanged.

🤖 Generated with Claude Code

David approved graduating PLAYBACK_ON_DEMAND_ENABLED on 2026-10-20
(DEC-BTR-004; feature-flags.yaml row: dev open/play/download,
changed-source and duplicate-task qualification, then one API+sync
train, done by 11-08, gate removed by 11-15). It is still false on
every host. This turns it on for every dev host so the qualification
can run; prod stays false in this change.

Why now (prod, ro-prod metrics, 10-31): the audio-merge queue has been
pinned at its ~20 dispatches/s cap since 10-26 12Z (71.9k attempts/h,
1.72M/day vs ~0.83M/day on 10-20..24) with a backlog that peaked at
765k on 10-29. Only ~423k/day of those runs write an artifact
(omi_playback_writes_total generated); about 65% end in uncounted
no-op outcomes. The cause is the eager enqueue path: every /urls poll
(3 s re-poll hint) re-creates the named merge task for any
conversation that has not converged to cached, once the ~1 h task-name
tombstone expires, and the eager fingerprint hashes volatile audio-file
IDs (runbooks/playback-write-amplification.md). The private-cloud-sync
bucket carries about +16.7M Class A ops/day over the 10-20..23
baseline (List 4.7M -> 8.0M, Write 2.6M -> 6.8M, metadata 1.5M ->
11M), ≈ $85/day before replication. On demand suppresses completion
and pipeline enqueues, makes /urls tasks converge after one build, and
switches to the stable source-manifest fingerprint.

Change: dev overlay sets the flag true on backend, backend-sync,
backend-sync-backfill, backend-integration, backend-listen and pusher;
dev listen and pusher chart values match; runtime_env.yaml recomposed;
registry re-rendered; two dev env fixtures follow the new value.

Dev qualification (before any prod change), per the registry note:
- open/play/download of an existing and a new conversation returns
  playable audio; first-play build completes and later opens hit cache;
- a changed source (late chunk / merge) rebuilds once and never serves
  stale audio;
- concurrent /urls polls create one task (no duplicate builds);
- audio-merge attempts per played conversation fall to ~1.
Then prod: one change flipping the prod overlay and listen/pusher
charts, rolled by the rollout lead with 24 h watches (unchanged
bytes/seek, no stale-source reuse, no play failure or latency
increase; audio-merge attempts < 400k/day and depth < 10k sustained;
bucket Class A <= 10M/day). The switch has no uid cohort (global
boolean), so prod goes host-wide, not 5/25/100.

Rollback: set the flag false (stored artifacts are never deleted on
rollback; eager paths resume). Raw audio and custody are untouched;
only the derived playback/ prefix is written.

Validation: backend/test.sh on runtime env validator, cross-service
deploy contract, listen helm defaults, audio fleet helm, Cloud Run env
drift, pusher cohost/config references, repeat-work cuts, playback
idempotency, audio fingerprint and chunk-archive listing: all passed.

Product invariants: INV-MEM-4. Memory admission and capability
contracts are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level Git-on-my-level changed the title chore(dev): turn on playback on demand for dev qualification feat(playback): count on-demand outcomes; turn it on for dev qualification Oct 31, 2026
…ation

David approved graduating PLAYBACK_ON_DEMAND_ENABLED on 2026-10-20
(DEC-BTR-004; feature-flags.yaml row: dev open/play/download,
changed-source and duplicate-task qualification, then one API+sync
train, done by 11-08, gate removed by 11-15). It is still false on
every host. This turns it on for every dev host so the qualification
can run; prod stays false in this change.

Why now (prod, ro-prod metrics, 10-31): the audio-merge queue has been
pinned at its ~20 dispatches/s cap since 10-26 12Z (71.9k attempts/h,
1.72M/day vs ~0.83M/day on 10-20..24) with a backlog that peaked at
765k on 10-29. Only ~423k/day of those runs write an artifact
(omi_playback_writes_total generated); about 65% end in uncounted
no-op outcomes. The cause is the eager enqueue path: every /urls poll
(3 s re-poll hint) re-creates the named merge task for any
conversation that has not converged to cached, once the ~1 h task-name
tombstone expires, and the eager fingerprint hashes volatile audio-file
IDs (runbooks/playback-write-amplification.md). The private-cloud-sync
bucket carries about +16.7M Class A ops/day over the 10-20..23
baseline (List 4.7M -> 8.0M, Write 2.6M -> 6.8M, metadata 1.5M ->
11M), ≈ $85/day before replication. On demand suppresses completion
and pipeline enqueues, makes /urls tasks converge after one build, and
switches to the stable source-manifest fingerprint.

Failure visibility: attempts, queue depth and bucket ops all fall when
dispatch or builds fail, so they cannot gate this graduation alone. The
audio-merge route now records every on-demand task's outcome in
omi_playback_artifacts_total{representation,outcome} (built, exists,
superseded, unavailable, failed_final, retry, locked,
destructive_deferred, chunks_missing, empty_audio, no_audio_files,
deleted_conversation, invalid_payload, error, other); an unhandled
exception counts as error and re-raises. Eager tasks are not counted
here (the existing deferred count is unchanged); the inline file
'built' count moved into the wrapper. The labeling lives in
utils/sync/repeat_work_metrics.py; sync.py keeps only the route
wrapper.

Line-Count-Exception: backend/routers/sync.py | 4134 -> 4152 | thin route wrapper so every on-demand outcome is counted at one seam instead of a dozen return points

Change: dev overlay sets the flag true on backend, backend-sync,
backend-sync-backfill, backend-integration, backend-listen and pusher;
dev listen and pusher chart values match; runtime_env.yaml recomposed;
registry re-rendered; two dev env fixtures follow the new value.

Dev qualification (before any prod change), per the registry note:
- open/play/download of an existing and a new conversation returns
  playable audio; first-play build completes and later opens hit cache;
- a changed source (late chunk / merge) rebuilds once and never serves
  stale audio;
- concurrent /urls polls create one task (no duplicate builds);
- audio-merge attempts per played conversation fall to ~1.
Then prod: one change flipping the prod overlay and listen/pusher
charts, rolled by the rollout lead with 24 h watches (unchanged
bytes/seek, no stale-source reuse, no play failure or latency
increase; on-demand failure share
(failed_final+unavailable+chunks_missing+empty_audio+error over all
on-demand outcomes) not above the dev baseline; audio-merge attempts < 400k/day and depth < 10k sustained;
bucket Class A <= 10M/day). The switch has no uid cohort (global
boolean), so prod goes host-wide, not 5/25/100.

Rollback: set the flag false (stored artifacts are never deleted on
rollback; eager paths resume). Raw audio and custody are untouched;
only the derived playback/ prefix is written.

Validation: backend/test.sh on the new test_playback_demand_outcomes,
test_audio_merge_tasks, test_audio_merge_destructive_deferral, runtime env validator, cross-service
deploy contract, listen helm defaults, audio fleet helm, Cloud Run env
drift, pusher cohost/config references, repeat-work cuts, playback
idempotency, audio fingerprint and chunk-archive listing: all passed.

Product invariants: INV-MEM-4. Memory admission and capability
contracts are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 1d6de0d into main Oct 31, 2026
56 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/playback-on-demand-dev branch October 31, 2026 13:08
Git-on-my-level added a commit that referenced this pull request Nov 1, 2026
## Summary

Turns `PLAYBACK_ON_DEMAND_ENABLED` on in **prod**, the graduation David
approved on 2026-10-20 (DEC-BTR-004). #24165 added the outcome counter
and turned the flag on in dev.

With on-demand playback, audio-merge artifacts are built only when
someone opens, plays or downloads a conversation, not eagerly on every
`/urls` poll. Prod audio-merge attempts are still about 1.1M/day, down
from 1.7M after #24192. The pre-10-26 baseline was 0.83M/day.

**Approved:** David ruled 2a on 2026-11-01: Plans & Cost flips this
off-peak on test evidence, with 24h watches and rollback on the first
breach.

## Change
- `backend/deploy/runtime_env/prod.overlay.yaml`:
`PLAYBACK_ON_DEMAND_ENABLED: 'true'` (rollout) on backend-listen,
pusher, backend, backend-sync, backend-sync-backfill and
backend-integration, the same six hosts as the dev overlay.
- `backend/charts/backend-listen/prod_omi_backend_listen_values.yaml`
and `backend/charts/pusher/prod_omi_pusher_values.yaml`: `"true"`.
- Composed `runtime_env.yaml` and re-rendered the feature-flag registry.

## Rollout
Roll off-peak in the deploy tool's lever order: **listen, then pusher,
then the Cloud Run backend train** (backend, backend-sync,
backend-sync-backfill, backend-integration).

Functionally any order is safe:
- The merge handler accepts eager and on-demand tasks.
- A host still eager keeps enqueuing as before, so the saving is partial
until every host is on.

## Rollback
Set `PLAYBACK_ON_DEMAND_ENABLED=false`: revert this PR, or set the
overlay value to false and re-roll. Eager playback resumes on the next
`/urls` poll.

## 24h watches (rollback on the first breach)
Source is Cloud Monitoring
`prometheus.googleapis.com/omi_playback_artifacts_total/counter`,
written by the backend-sync GMP sidecar
(`job=omi-cloud-run-application-metrics`). The in-cluster sync exporter
does not import `omi_playback_*`, so read Cloud Monitoring directly. The
series appears on the first increment.

| Watch | Threshold |
|---|---|
| `failed_final` + `error` share of on-demand outcomes | < 2% |
| `retry` share | not rising hour over hour |
| `omi_playback_writes_total` `built` | p95 ≤ 60 s |
| Client playback errors | no rise |
| Cloud Tasks `audio-merge` attempts | falling toward plays, < 400k/day
|
| Queue depth | < 10k |
| `omi-private-cloud-sync` Class A ops | ≤ 10M/day |

## Expected saving
About −$32 to −$83/day (mid −$55), scaled from the 10-31 audio-merge
cost basis to ~1.05M removable attempts/day after #24192.

## Tests
`backend/test.sh` on the runtime_env validator, pusher config
references, playback demand outcomes, playback idempotency, repeat-work
cuts, config train, cross-service deploy contract and runtime env
render: 22 passed, 3 skipped.

Product invariants: INV-MEM-4 (raw audio retained forever; this changes
only when derived playback artifacts are built, never source chunks).

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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