Skip to content

perf(sync): cut opus decode CPU ~55% by writing the WAV header once - #24631

Merged
Git-on-my-level merged 2 commits into
mainfrom
lane/synceff
Nov 4, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
lane/synceff

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

backend-sync efficiency, first lever (synceff lane).

  1. Opus sync decode: stop rewriting the WAV header every 10 ms frame. decode_opus_file_to_wav called wave.writeframes() per frame; CPython re-patches the RIFF header (seek, write, seek back) after each one. writeframesraw() defers that to close(), which writes the same header. WAV bytes are identical. Local bench, 180 s of 16 kHz opus: 609 ms -> 275 ms CPU (seek was 52% of decode time); decode_units end to end 320 ms after the fix. Every accepted upload, coverage check and batch decode goes through this function.

A 6Gi -> 5Gi memory cut was dropped after review: 16 sync workers each decoding a one-hour PCM unit can exceed 5 GiB, and a single measured peak doesn't qualify the limit. It will be revisited with a week of post-legacy-dark memory data.

Why this matters: backend-sync instance count tracks busy CPU (30 h correlation 0.73), with ~0.63 busy cores per instance, so CPU removed from decode becomes fewer instances. Evidence and measurements: omi-workspace data/run-2026-11-04-synceff/README.md.

Kill switches / rollback

  • SYNC_OPUS_RAW_FRAME_WRITES=0 restores per-frame writeframes() (registered as an ops_kill flag, default on).

Expected impact (to be measured after deploy)

Estimated ~1-1.6 busy cores less on backend-sync (about 2-3 instances, ~$8-12/d). After the roll: CPU per accepted upload and instance count vs the 11-04 18:30Z baseline.

Tests

  • New TestOpusRawFrameWrites: raw vs legacy mode produce identical bytes, sample counts and results for clean, corrupt-middle, truncated-prefix, truncated-frame and all-corrupt streams; header frame count; kill switch restores writeframes().
  • Disk-full contract runs in both modes, plus a new case where ENOSPC first surfaces at close() (buffered flush): still BackfillStoragePressure, no partial WAV kept.
  • A non-capacity I/O error at close fails closed (returns False, no WAV, raw upload kept). The live caller (capture_decode) already refuses any dropped file or frame-count mismatch, so this ends as a retry with custody retained.
  • make preflight (OMI_CHECKS_JOBS=1): all checks passed except product-invariants, which needs this body.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

decode_opus_file_to_wav wrote each 10 ms opus frame with wave.writeframes(),
which re-patches the RIFF header after every frame (seek, header write, seek
back). Use writeframesraw() and let close() write the header once. The WAV
bytes are identical (tests compare both modes on clean, corrupt-middle,
truncated and all-corrupt streams). Local bench, 180 s of 16 kHz opus: 609 ms
-> 275 ms CPU. ENOSPC still maps to BackfillStoragePressure, including when the
buffered data first fails at close(); a non-capacity I/O error at close fails
closed (no WAV, raw upload kept), which the live caller (capture_decode) turns
into a retryable refusal with custody retained.

Kill switch: SYNC_OPUS_RAW_FRAME_WRITES=0 restores per-frame writeframes().

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T19:21:53.722157Z b719cff PR opened
ℹ️ 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.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 5 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

View guided diff | Turn on auto-fix | Re-trigger cubic

…R 0006 exception, review 2026-12-04)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 344f813 into main Nov 4, 2026
58 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/synceff branch November 4, 2026 19:51
Git-on-my-level added a commit that referenced this pull request Nov 4, 2026
…44) (#24636)

## What

One-line repair on main: set `backend/config/flag_budget.json` `count`
from 243 to 244.

## Why

#24631 (`SYNC_OPUS_RAW_FRAME_WRITES`) and f513b1d
(`BATCH_PULL_BUSY_BORROW_ENABLED`) each added one name and bumped
`count` from 242 to 243 from the same base. Once both merged, main had
244 names with `count` 243.
`tests/unit/test_flag_budget.py::test_budget_file_declares_scope_and_count`
(`count == len(names)`) has failed in every backend PR since 19:51Z;
#24622's shard 3/8 failed on it.

## Verification

`pytest tests/unit/test_flag_budget.py`: 24 passed. This includes the
ceiling checks, so 244 stays within the budget's own limits.

## Failure class (fixes)

Failure-Class: none

A semantic merge race between two PRs that both edited a counter, not a
recurring product failure class.

## Product invariants affected

None.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/24636?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/24636?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F24636&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. -->
kriegcloud pushed a commit to kriegcloud/omi that referenced this pull request Nov 5, 2026
BasedHardware#24631 (SYNC_OPUS_RAW_FRAME_WRITES) and f513b1d (BATCH_PULL_BUSY_BORROW_ENABLED)
each added one name and bumped count 242 -> 243 from the same base. After both
merged, main has 244 names with count 243, and
test_flag_budget.py::test_budget_file_declares_scope_and_count fails in every
backend PR.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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