Skip to content

refactor: split oversized product source files - #9853

Merged
Git-on-my-level merged 16 commits into
mainfrom
codex/issue-9838-reduce-god-files
Jul 16, 2026
Merged

Git-on-my-level merged 16 commits into
mainfrom
codex/issue-9838-reduce-god-files

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Fixes #9838

Summary

  • Split all four ratcheted product files below 1,500 lines, with durable ownership seams and package architecture notes.
  • Replace fragile source-location tests with behavioral coverage for streaming translation, authenticated API retries, realtime continuation gating, and listen-session boundaries.
  • Restore listen behavior uncovered during the split review: bounded speaker excerpts, frame-local decode recovery, malformed text continuation, fair-use state transitions, onboarding language selection, and speaker-label event emission.
  • Make deleted product-source paths participate in preflight ratchet validation and make the desktop logic harness select the maintained Node runtime.

Root cause and guard

The oversized modules combined unrelated state transitions and transport concerns, making their contracts hard to exercise after extraction. The new modules keep one authoritative owner per boundary and the tests execute those boundaries through controllable fakes. The line-count ratchet now removes all four old baseline entries and also validates deleted source paths.

Verification

  • backend/test.sh
  • backend/scripts/typecheck.sh (0 errors)
  • backend/testing/e2e/run.sh -k listen_stt
  • desktop/macos/scripts/agent-logic-harness.sh
  • xcrun swift build -c debug --package-path Desktop
  • xcrun swift test --package-path Desktop --filter 'APIClient|RealtimeHubResumeOnceGateTests'
  • cargo test (367 passed)
  • make preflight

The named desktop QA bundle compiled but was not launched: this machine has no signing identity, and ad-hoc signing would reset Screen Recording permissions for the production/beta Omi apps.

Product invariants affected

  • INV-AUTH-1
  • INV-CHAT-1
  • INV-VOICE-1

Review in cubic

Failure-Class: none

@Git-on-my-level Git-on-my-level added the no-changelog-needed Skip desktop changelog enforcement for internal-only changes label Jul 16, 2026
@mintlify

mintlify Bot commented Jul 16, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
omi 🟢 Ready View Preview Jul 16, 2026, 12:03 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@mintlify

mintlify Bot commented Jul 16, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
omi 🟡 Building – Jul 16, 2026, 12:02 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Monitor follow-up complete.

Changed:

  • Updated chat-hermetic.yaml coverage from the deleted chat_completions.rs file to the new split Rust chat route modules.
  • Added a desktop changelog fragment for the macOS reliability/internal split work.

Verification passed:

  • PATH="/opt/homebrew/opt/node@22/bin:$PATH" ./desktop/macos/scripts/desktop-core-harness.sh --self-check --skip-backend-contracts
  • python3 .github/scripts/check-desktop-changelog.py --base origin/main --head HEAD
  • git diff --check
  • PATH="/opt/homebrew/opt/node@22/bin:$PATH" bash desktop/macos/scripts/test-tool-surfaces.sh
  • GitHub checks are green/skipped after push, including desktop-core-e2e-t0.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

@cursor sync main

@cursor

cursor Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Synced main into codex/issue-9838-reduce-god-files and pushed (37849bc92b).

What landed from main (9 commits), including:

Conflicts resolved:

  1. RealtimeHubController.swift — Kept the split module structure (~1,464 lines) and ported main’s PTT handoff changes into the extension files (+SessionLifecycle, +PushToTalk, +SessionDelegate, +ScreenEvidence).
  2. product_file_line_count_ratchet_baseline.json — Kept the PR split baseline (no monolithic RealtimeHubController.swift entry) with updated line counts from main.

Key ports from main into split modules:

  • requestSessionRefresh → typed requestSessionHandoff via RealtimeHubSessionHandoffPolicy
  • inputTurnActivityStartPending → admittedInputTurnID
  • screenAnswerPresented → screenFailurePresented
  • Removed continuity-fence and pendingCompletedAgentDelta* paths superseded by main

python3 desktop/macos/scripts/check-hub-controller-ratchet.py passes. CI should re-run on the push.

Open in Web Open in Cursor 

Sync main PTT handoff fixes (#9825) into the split RealtimeHubController
modules. Resolved conflicts in RealtimeHubController.swift and the product
line-count ratchet baseline while preserving the file-split ownership seams.

Co-authored-by: David Zhang <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@cursor address CI failure and merge conflicts

@cursor

cursor Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Addressed the CI failures and merge conflicts. Pushed aace15d609.

CI failures fixed

  1. Desktop Swift Build & Tests — duplicate type declarations:

    • RealtimeLocalProfileTurnPlan and RealtimeAcceptedSpawnPresentationPolicy existed in both RealtimeHubControllerSupport.swift and RealtimeHubSessionPolicies.swift
    • Removed the duplicates from ControllerSupport (canonical home is SessionPolicies)
  2. Hygiene / product-file-line-count-ratchet — RealtimeHubController+SessionLifecycle.swift was 1,509 lines:

    • Extracted voice-output helpers into RealtimeHubController+VoiceOutput.swift
    • SessionLifecycle is now 1,400 lines (under the 1,500 cap)
  3. APIClient merge conflict — kept the split transport boundary (APIClient.swift at 1,088 lines with performPatchRequest); feature APIs remain in APIClient+*.swift extensions (not re-inlined from main)

Merge conflicts resolved (latest main)

  • APIClient.swift — kept PR split version
  • test_pr_preflight.py — merged both changed_files and format_failure_class_suggest imports
  • test_desktop_rest_inventory.py — kept 1,500-line cap for split APIClient

Verification run locally

  • python3 desktop/macos/scripts/check-hub-controller-ratchet.py — OK
  • python3 .github/scripts/check_product_file_line_count_ratchet.py — OK
  • pytest tests/unit/test_desktop_rest_inventory.py — 9 passed
  • python3 .github/scripts/test_pr_preflight.py — 11 passed

CI should re-run on the push. The Swift build and Hygiene checks were the blockers from the prior sync.

Open in Web Open in Cursor 

Resolve merge conflicts and fix CI regressions from the main sync:

- Drop duplicate RealtimeHub policy types from ControllerSupport (live in
  SessionPolicies) to fix Swift compile errors.
- Keep split APIClient.swift transport boundary; feature APIs stay in
  APIClient+*.swift extensions.
- Extract voice-output helpers into RealtimeHubController+VoiceOutput.swift so
  SessionLifecycle stays under the 1,500-line product ratchet.
- Merge pr_preflight imports and retain the 1,500-line APIClient inventory cap.

Co-authored-by: David Zhang <[email protected]>
Restore the pre-warm screen-evidence capture and terminal completion policy lost when RealtimeHubController was split. Source-inspection coverage now reads the owning PushToTalk extension directly.

Verification: xcrun swift test -c debug --package-path Desktop --filter RealtimeHubBargeInContinuityTests; ./scripts/swift-test-suites.sh; all desktop/macos/tests/test-*.sh; make preflight.
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@cursor address merge conflicts

@cursor

cursor Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Resolved merge conflicts and synced with latest main. Pushed cf6cf8a5e8.

Conflicts resolved

  1. product_file_line_count_ratchet_baseline.json

    • sync.py → 1981 (current count)
    • Omitted transcribe.py and RealtimeHubController.swift (both split below 1,500 lines on this branch)
  2. RealtimeHubController.swift

    • Kept the split module (~1,464 lines); rejected main’s monolithic re-inline
  3. PTT agent routing (fix(desktop): stabilize PTT agent routing #9859) ported into split modules:

    • +SessionDelegate: spawn receipts now preserve native provider continuation (assistantText = "") instead of playing a canonical acknowledgement
    • Removed hasCanonicalSpawnReceipt from RealtimeProviderOutputPresentationPolicy.decide() calls
    • Simplified hubDidFinishTurn post-tool continuation logic
    • +VoiceOutput: removed playCanonicalSpawnAcknowledgement (superseded by native continuation)

Also merged

Remote branch updates (f3c864e2f7) that landed while this was in progress — barge-in continuity test fixes and related hub changes.

Verification

  • check-hub-controller-ratchet.py — OK
  • check_product_file_line_count_ratchet.py — OK
  • No conflict markers remain

CI should re-run on the push.

Open in Web Open in Cursor 

cursoragent and others added 2 commits July 16, 2026 15:06
Resolve merge conflicts after syncing latest main:

- Keep split RealtimeHubController modules; reject monolithic re-inline.
- Update product line-count baseline: sync.py at 1981, omit split
  transcribe.py and RealtimeHubController.swift entries.
- Port PTT agent routing (#9859) into split modules: preserve native
  provider continuation on spawn receipts, drop spawn acknowledgement
  playback, and simplify output presentation policy calls.

Co-authored-by: David Zhang <[email protected]>
Document the provider, gateway, feature-coordinator, and persistence boundaries required by the package architecture-map ratchet.

Verification: python3 .github/scripts/test_check_package_architecture_maps.py; python3 .github/scripts/check_package_architecture_maps.py --base origin/main; make preflight.
@Git-on-my-level
Git-on-my-level merged commit e8adfc5 into main Jul 16, 2026
34 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/issue-9838-reduce-god-files branch July 16, 2026 22:48
Git-on-my-level added a commit that referenced this pull request Jul 18, 2026
## Summary

- Replace the shared product-file line-count baseline with 15
deterministic, ownership-scoped JSON shards.
- Keep file caps and `raise_justifications` together in the same shard,
with no mutable global index/manifest.
- Preserve mandatory same-PR downward ratcheting; a post-merge writer is
deliberately **not** made authoritative.
- Load the legacy monolithic baseline at historical refs so this
migration preserves raise/removal validation for branches spanning the
transition.

## Why

The monolithic baseline received 35 commits in roughly 46 hours and
became a conflict hotspot for unrelated backend, Rust, and macOS work.
PR #9853 had to reconcile it repeatedly while rebasing.

The new `baseline_shard_relative()` uses only stable source-path
ownership rules:

- `backend/{database,routers,utils,other}`
- `desktop-rust`
- immediate `Desktop/Sources/<subsystem>` Swift shards, plus a `root`
shard

This avoids replacing the hotspot with a central registry. The checker
aggregates shards in memory and rejects duplicate, misplaced,
unsupported, or orphaned entries.

## Sol critique incorporated

- Keep same-PR downward updates: a nonblocking post-merge bot would
permit a source to regrow against its stale higher cap before the bot
writes the reduction.
- Rewrite only the shard(s) owning changed source paths.
- Keep each justification beside its cap and validate global
aggregation.
- Support legacy-at-base and sharded-at-head transition validation.

## Verification

- `python3 -m py_compile
.github/scripts/check_product_file_line_count_ratchet.py
.github/scripts/test_check_product_file_line_count_ratchet.py`
- `python3
.github/scripts/test_check_product_file_line_count_ratchet.py` — 8
passed
- `python3 .github/scripts/test_run_checks.py` — 20 passed
- `python3 .github/scripts/check_product_file_line_count_ratchet.py
--changed-files /tmp/omi-ratchet-changed-files.txt --base origin/main`
- confirmed the 44 file caps and 31 justifications match the legacy
baseline exactly across 15 shards

Failure-Class: none


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/9942?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="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
mdmohsin7 added a commit that referenced this pull request Aug 13, 2026
… session starts (#11505)

# fix(listen): send the first onboarding question when a speech-profile
session starts

## Problem

The speech profile page (onboarding and Settings > Profile > Speech
Profile) shows no question and its progress bar never moves. Audio still
streams and a conversation/recording appears later, so the session looks
half-alive.

The question flow is server-driven: the client renders whatever
`onboarding_question` event the backend pushes, and computes progress as
`question_index / total_questions`. PR #9853 split `transcribe.py` into
`routers/listen/`, and the split dropped the one-shot kickoff
`spawn(onboarding_handler.send_current_question(), ...)` that existed
since the flow shipped (#3859). `ListenSessionRuntime._bootstrap` still
constructs the `OnboardingHandler`, but nothing ever sends question 0 —
`OnboardingHandler.send_current_question` is only reachable after an
answer or a skip, which can never happen before the first question
exists. The client waits forever on an empty screen at 0%.

## Fix

Restore the kickoff at handler creation in `_bootstrap`, spawned through
the session task supervisor (same placement and semantics as the
pre-refactor code).

## Regression test

`test_bootstrap_sends_first_onboarding_question_before_any_audio` runs
the real `_bootstrap` with a real `OnboardingHandler` and a recording
websocket, and asserts that — with no segments having arrived — the
client receives exactly one `onboarding_question` event (question 0 of
`len(ONBOARDING_QUESTIONS)`) and the question transcript segment is
enqueued with the Omi speaker id. This test fails on `main` today and
would have caught the drop in #9853.

The existing `_bootstrap` onboarding test's stub handler grew a
`send_current_question` coroutine and a real task supervisor, since the
production path now calls it.

## Failure class

Failure-Class: none

No existing class matches "one-shot side effect dropped while splitting
a module"; this is the first known instance of that cause in this
subsystem, so it lands as an instance fix plus the behavioral guard test
above.

## Verification

- `BACKEND_UNIT_TEST_FILE_LIST=/tmp/omi-target.txt bash test.sh` (file =
`tests/unit/test_listen_runtime_regressions.py`): **20 passed**
(includes the new test and the two updated bootstrap tests).
- Full unit-suite run surfaced 7 unrelated files exiting status 1 with
**all assertions passing** (e.g. "13 passed" + status 1) — the fast-unit
CPU duration guard tripping under heavy parallel load on my machine;
those files pass when run normally and none touch the listen runtime.
- Not exercised against a live device end-to-end: the fix is
backend-only and the affected path needs a prod-like STT session; the
regression test drives the real `_bootstrap` + `OnboardingHandler`
wiring.

## Product invariants affected

none


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/11505?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="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
undivisible pushed a commit to undivisible/omi that referenced this pull request Aug 13, 2026
… session starts

PR BasedHardware#9853's split of transcribe.py into routers/listen/ dropped the
spawn(onboarding_handler.send_current_question()) kickoff, so onboarding-mode
sessions never received the first onboarding_question event: the speech
profile page showed no question and its progress bar stayed at 0% forever.

Restore the kickoff at handler creation in ListenSessionRuntime._bootstrap
and add the regression test that would have caught the drop.

Failure-Class: none
undivisible pushed a commit to undivisible/omi that referenced this pull request Sep 29, 2026
## Summary

- Replace the shared product-file line-count baseline with 15
deterministic, ownership-scoped JSON shards.
- Keep file caps and `raise_justifications` together in the same shard,
with no mutable global index/manifest.
- Preserve mandatory same-PR downward ratcheting; a post-merge writer is
deliberately **not** made authoritative.
- Load the legacy monolithic baseline at historical refs so this
migration preserves raise/removal validation for branches spanning the
transition.

## Why

The monolithic baseline received 35 commits in roughly 46 hours and
became a conflict hotspot for unrelated backend, Rust, and macOS work.
PR BasedHardware#9853 had to reconcile it repeatedly while rebasing.

The new `baseline_shard_relative()` uses only stable source-path
ownership rules:

- `backend/{database,routers,utils,other}`
- `desktop-rust`
- immediate `Desktop/Sources/<subsystem>` Swift shards, plus a `root`
shard

This avoids replacing the hotspot with a central registry. The checker
aggregates shards in memory and rejects duplicate, misplaced,
unsupported, or orphaned entries.

## Sol critique incorporated

- Keep same-PR downward updates: a nonblocking post-merge bot would
permit a source to regrow against its stale higher cap before the bot
writes the reduction.
- Rewrite only the shard(s) owning changed source paths.
- Keep each justification beside its cap and validate global
aggregation.
- Support legacy-at-base and sharded-at-head transition validation.

## Verification

- `python3 -m py_compile
.github/scripts/check_product_file_line_count_ratchet.py
.github/scripts/test_check_product_file_line_count_ratchet.py`
- `python3
.github/scripts/test_check_product_file_line_count_ratchet.py` — 8
passed
- `python3 .github/scripts/test_run_checks.py` — 20 passed
- `python3 .github/scripts/check_product_file_line_count_ratchet.py
--changed-files /tmp/omi-ratchet-changed-files.txt --base origin/main`
- confirmed the 44 file caps and 31 justifications match the legacy
baseline exactly across 15 shards

Failure-Class: none


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/9942?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="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.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

no-changelog-needed Skip desktop changelog enforcement for internal-only changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

God-file ratchet: freeze growth of 1500+ line product files — generalize the single-file precedent

2 participants