Skip to content

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

Merged
mdmohsin7 merged 1 commit into
mainfrom
fix/speech-profile-first-question
Aug 13, 2026
Merged

mdmohsin7 merged 1 commit into
mainfrom
fix/speech-profile-first-question

Conversation

@mdmohsin7

@mdmohsin7 mdmohsin7 commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

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

Review in cubic

… session starts

PR #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

@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.

2 issues found across 2 files

Confidence score: 3/5

  • In backend/routers/listen/runtime.py (process_loop()/kickoff path), the onboarding Omi question segment can be queued before any audio timestamp exists and then dropped, so users who wait for audio may miss the first question entirely—preserve or replay pre-audio segments instead of discarding them.
  • In backend/routers/listen/runtime.py (send_onboarding spawned task), a disconnect between the client_state check and send_json can raise WebSocketDisconnect/RuntimeError and bubble out of the task, creating noisy failures during onboarding—wrap the send with closed-socket exception handling and exit cleanly.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/routers/listen/runtime.py">

<violation number="1" location="backend/routers/listen/runtime.py:353">
P2: When an onboarding client waits for audio after receiving the question, the new kickoff queues the Omi question segment and `process_loop()` drops it before the first audio timestamp exists. Preserve pre-audio segments or defer their processing until the first audio frame so the question is retained in the conversation transcript.</violation>

<violation number="2" location="backend/routers/listen/runtime.py:353">
P3: The spawned first-question task has no closed-socket handling: if the client disconnects between the client_state check and send_json inside the send_onboarding closure, the WebSocketDisconnect/RuntimeError propagates to the task's done-callback, which only logs it and does not set state.active = False (unlike asend_event/_send_ping). Wrap the websocket send in a try/except that sets self.state.active = False, or catch it around the spawned send.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

await request.websocket.send_json(event)

self.onboarding_handler = OnboardingHandler(request.uid, send_onboarding, self.transcripts.enqueue)
self.spawn(self.onboarding_handler.send_current_question(), name='onboarding_first_question')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When an onboarding client waits for audio after receiving the question, the new kickoff queues the Omi question segment and process_loop() drops it before the first audio timestamp exists. Preserve pre-audio segments or defer their processing until the first audio frame so the question is retained in the conversation transcript.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/routers/listen/runtime.py, line 353:

<comment>When an onboarding client waits for audio after receiving the question, the new kickoff queues the Omi question segment and `process_loop()` drops it before the first audio timestamp exists. Preserve pre-audio segments or defer their processing until the first audio frame so the question is retained in the conversation transcript.</comment>

<file context>
@@ -350,6 +350,7 @@ async def send_onboarding(event: Dict[str, Any]) -> None:
                     await request.websocket.send_json(event)
 
             self.onboarding_handler = OnboardingHandler(request.uid, send_onboarding, self.transcripts.enqueue)
+            self.spawn(self.onboarding_handler.send_current_question(), name='onboarding_first_question')
         return True
 
</file context>

await request.websocket.send_json(event)

self.onboarding_handler = OnboardingHandler(request.uid, send_onboarding, self.transcripts.enqueue)
self.spawn(self.onboarding_handler.send_current_question(), name='onboarding_first_question')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The spawned first-question task has no closed-socket handling: if the client disconnects between the client_state check and send_json inside the send_onboarding closure, the WebSocketDisconnect/RuntimeError propagates to the task's done-callback, which only logs it and does not set state.active = False (unlike asend_event/_send_ping). Wrap the websocket send in a try/except that sets self.state.active = False, or catch it around the spawned send.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/routers/listen/runtime.py, line 353:

<comment>The spawned first-question task has no closed-socket handling: if the client disconnects between the client_state check and send_json inside the send_onboarding closure, the WebSocketDisconnect/RuntimeError propagates to the task's done-callback, which only logs it and does not set state.active = False (unlike asend_event/_send_ping). Wrap the websocket send in a try/except that sets self.state.active = False, or catch it around the spawned send.</comment>

<file context>
@@ -350,6 +350,7 @@ async def send_onboarding(event: Dict[str, Any]) -> None:
                     await request.websocket.send_json(event)
 
             self.onboarding_handler = OnboardingHandler(request.uid, send_onboarding, self.transcripts.enqueue)
+            self.spawn(self.onboarding_handler.send_current_question(), name='onboarding_first_question')
         return True
 
</file context>

@mdmohsin7
mdmohsin7 merged commit 0c36d94 into main Aug 13, 2026
43 checks passed
@mdmohsin7
mdmohsin7 deleted the fix/speech-profile-first-question branch August 13, 2026 13:10
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