Repository navigation
perf(sync): cut opus decode CPU ~55% by writing the WAV header once - #24631
Merged
Merged
Conversation
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]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…R 0006 exception, review 2026-12-04) Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
backend-sync efficiency, first lever (synceff lane).
decode_opus_file_to_wavcalledwave.writeframes()per frame; CPython re-patches the RIFF header (seek, write, seek back) after each one.writeframesraw()defers that toclose(), 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_unitsend 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=0restores per-framewriteframes()(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
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 restoreswriteframes().close()(buffered flush): stillBackfillStoragePressure, no partial WAV kept.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