Skip to content

fix(listen): keep web + device recordings on separate conversations (#5388) - #11173

Merged
kodjima33 merged 4 commits into
BasedHardware:mainfrom
aryanorastar:fix/5388-web-device-concurrent-record
Aug 6, 2026
Merged

kodjima33 merged 4 commits into
BasedHardware:mainfrom
aryanorastar:fix/5388-web-device-concurrent-record

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Aug 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Simultaneous pendant + web (h.omi.me) recording no longer silently loses the web meeting (Bug: Simultaneous device + web app recording fails — both are lost #5388 / related Bug: 30-min conversation split into multiple short fragments during simultaneous device + web recording #5389).
  • Root cause: prepare() attached new listen sockets to the single Redis in_progress conversation. Web audio could write into a device session, and stop/finalize could complete the shared pointer.
  • Shrink-only changes:
    • Backend: refuse cross-source attach (should_attach_to_existing_in_progress) so omi and unknown sources do not share one in-progress conversation.
    • Web: pass client_conversation_id, keep conversation_session only when status is in_progress, and finalize by explicit ID via /v1/conversations/{id}/finalize instead of the global pointer.
    • Compatibility: ConversationSource.web is not present in the public app-client contract; source=web still maps through _missing_ to unknown.

Test plan

  • pytest tests/unit/test_transcribe_decisions.py (cross-source attach refusal coverage)
  • CI lanes: backend/web/OpenAPI green
  • Manual: pendant recording + start web meeting record → two conversations after stop

Follow-up (separate from this shrink fix)

  • Finalize-vs-drain race on immediate web socket close (tail-end audio timing)

Failure-Class: none

Fixes #5388

Review in cubic

…asedHardware#5388)

Web listen attached to the shared Redis in_progress pointer when the pendant
was already live, so meeting audio merged into the device session and stop
finalized the wrong conversation. Refuse cross-source attach, give web its own
client_conversation_id, and finalize by that id (desktop pattern).

Co-authored-by: Cursor <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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

4 issues found across 7 files

Confidence score: 3/5

  • In web/app/src/hooks/useRecording.ts, finalization can run before the WebSocket conversation session is established (and right after socket.disconnect()), so very short or tail-end audio may be dropped and transcripts can be incomplete—gate finalize on authoritative conversation_session and/or add a finalize retry after session creation.
  • In backend/routers/listen/conversations.py, unsupported listen sources may start a fresh conversation on each reconnect instead of reusing the prior session, which can fragment a single user session across multiple conversation IDs—canonicalize source parsing on reconnect with the same ConversationSource conversion path.
  • In backend/utils/transcribe_decisions.py, mixed-case or whitespace-padded source values can be treated as canonical for routing but persisted as unknown in cross-source creation, leading to inconsistent metadata and downstream logic drift—normalize source input before both classification and persistence.
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/conversations.py">

<violation number="1" location="backend/routers/listen/conversations.py:272">
P2: Unsupported listen sources now create a new conversation on every reconnect instead of reusing the existing session. Canonicalize the request source with the same `ConversationSource` conversion used when creating the conversation before calling the attach decision.</violation>
</file>

<file name="backend/utils/transcribe_decisions.py">

<violation number="1" location="backend/utils/transcribe_decisions.py:180">
P2: Mixed-case or whitespace-padded source values are classified as canonical sources here but persisted as `unknown` when the cross-source branch creates a conversation. Normalize the request source before both this comparison and `ConversationSource(...)`, or avoid case/whitespace normalization here until the persistence boundary does the same.</violation>
</file>

<file name="web/app/src/hooks/useRecording.ts">

<violation number="1" location="web/app/src/hooks/useRecording.ts:228">
P2: A very short recording can be lost because finalization is sent before the WebSocket has established its conversation. Waiting for the authoritative `conversation_session` (or retrying finalization after session creation) would prevent the 404 from being treated as a successful no-op.</violation>

<violation number="2" location="web/app/src/hooks/useRecording.ts:228">
P2: The web conversation is finalized via `/v1/conversations/{id}/finalize` immediately after `socket.disconnect()`. Unlike the desktop source (where the backend also finalizes on disconnect, giving ordered drain), a `web` conversation has no backend-side finalization on close, so the frontend `/finalize` request races with the listen session still draining buffered audio. If the request lands before trailing segments are flushed, the conversation can be marked processed/completed with the tail of the recording lost — the same failure class this PR addresses. Consider deferring the `/finalize` call until the backend session confirms it has finished writing (for example by waiting for a terminal/`finalize` acknowledgement from the socket, or relying on the backend's own disconnect finalization for web too) instead of firing it the instant the socket is closed.</violation>
</file>

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

Re-trigger cubic

# Cross-source sockets (pendant + web meeting) must not share one conversation (#5388).
if not should_attach_to_existing_in_progress(
existing_source=existing_source if isinstance(existing_source, str) else None,
request_source=self.host.request.source,

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: Unsupported listen sources now create a new conversation on every reconnect instead of reusing the existing session. Canonicalize the request source with the same ConversationSource conversion used when creating the conversation before calling the attach decision.

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

<comment>Unsupported listen sources now create a new conversation on every reconnect instead of reusing the existing session. Canonicalize the request source with the same `ConversationSource` conversion used when creating the conversation before calling the attach decision.</comment>

<file context>
@@ -262,6 +263,16 @@ async def prepare(self) -> Optional[str]:
+        # Cross-source sockets (pendant + web meeting) must not share one conversation (#5388).
+        if not should_attach_to_existing_in_progress(
+            existing_source=existing_source if isinstance(existing_source, str) else None,
+            request_source=self.host.request.source,
+        ):
+            await self.create_new_in_progress_conversation()
</file context>

Comment thread web/app/src/lib/transcriptionSocket.ts Resolved
Comment thread backend/utils/transcribe_decisions.py Outdated
"""Collapse empty/missing listen sources onto the default pendant source."""
if not isinstance(value, str) or not value.strip():
return 'omi'
return value.strip().lower()

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: Mixed-case or whitespace-padded source values are classified as canonical sources here but persisted as unknown when the cross-source branch creates a conversation. Normalize the request source before both this comparison and ConversationSource(...), or avoid case/whitespace normalization here until the persistence boundary does the same.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/utils/transcribe_decisions.py, line 180:

<comment>Mixed-case or whitespace-padded source values are classified as canonical sources here but persisted as `unknown` when the cross-source branch creates a conversation. Normalize the request source before both this comparison and `ConversationSource(...)`, or avoid case/whitespace normalization here until the persistence boundary does the same.</comment>

<file context>
@@ -173,6 +173,27 @@ def decide_existing_conversation_action(
+    """Collapse empty/missing listen sources onto the default pendant source."""
+    if not isinstance(value, str) or not value.strip():
+        return 'omi'
+    return value.strip().lower()
+
+
</file context>

Comment thread backend/models/conversation_enums.py Resolved
const conversationId = conversationIdRef.current || clientConversationIdRef.current;
conversationIdRef.current = null;
clientConversationIdRef.current = null;
const finalize = conversationId

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: A very short recording can be lost because finalization is sent before the WebSocket has established its conversation. Waiting for the authoritative conversation_session (or retrying finalization after session creation) would prevent the 404 from being treated as a successful no-op.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At web/app/src/hooks/useRecording.ts, line 228:

<comment>A very short recording can be lost because finalization is sent before the WebSocket has established its conversation. Waiting for the authoritative `conversation_session` (or retrying finalization after session creation) would prevent the 404 from being treated as a successful no-op.</comment>

<file context>
@@ -211,8 +221,14 @@ export function useRecording() {
+    const conversationId = conversationIdRef.current || clientConversationIdRef.current;
+    conversationIdRef.current = null;
+    clientConversationIdRef.current = null;
+    const finalize = conversationId
+      ? finalizeConversationById(conversationId)
+      : processInProgressConversation();
</file context>

const conversationId = conversationIdRef.current || clientConversationIdRef.current;
conversationIdRef.current = null;
clientConversationIdRef.current = null;
const finalize = conversationId

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: The web conversation is finalized via /v1/conversations/{id}/finalize immediately after socket.disconnect(). Unlike the desktop source (where the backend also finalizes on disconnect, giving ordered drain), a web conversation has no backend-side finalization on close, so the frontend /finalize request races with the listen session still draining buffered audio. If the request lands before trailing segments are flushed, the conversation can be marked processed/completed with the tail of the recording lost — the same failure class this PR addresses. Consider deferring the /finalize call until the backend session confirms it has finished writing (for example by waiting for a terminal/finalize acknowledgement from the socket, or relying on the backend's own disconnect finalization for web too) instead of firing it the instant the socket is closed.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At web/app/src/hooks/useRecording.ts, line 228:

<comment>The web conversation is finalized via `/v1/conversations/{id}/finalize` immediately after `socket.disconnect()`. Unlike the desktop source (where the backend also finalizes on disconnect, giving ordered drain), a `web` conversation has no backend-side finalization on close, so the frontend `/finalize` request races with the listen session still draining buffered audio. If the request lands before trailing segments are flushed, the conversation can be marked processed/completed with the tail of the recording lost — the same failure class this PR addresses. Consider deferring the `/finalize` call until the backend session confirms it has finished writing (for example by waiting for a terminal/`finalize` acknowledgement from the socket, or relying on the backend's own disconnect finalization for web too) instead of firing it the instant the socket is closed.</comment>

<file context>
@@ -211,8 +221,14 @@ export function useRecording() {
+    const conversationId = conversationIdRef.current || clientConversationIdRef.current;
+    conversationIdRef.current = null;
+    clientConversationIdRef.current = null;
+    const finalize = conversationId
+      ? finalizeConversationById(conversationId)
+      : processInProgressConversation();
</file context>

Comment thread web/app/src/hooks/useRecording.ts Resolved
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

OpenAPI contract failure was from adding ConversationSource.web without refreshing the committed public schema. Regenerated docs/api-reference/openapi.json (web enum member) — should clear Public Developer API contract.

…urce canonicalize

Refresh remaining OpenAPI surfaces and generated TS/Swift clients for
ConversationSource.web. Canonicalize attach decisions via ConversationSource
(match persistence), ignore non-in_progress conversation_session events, and
collapse to a single conversation id ref.

Co-authored-by: Cursor <[email protected]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Follow-up pushed for Cubic P2s + OpenAPI lane:

  1. OpenAPI — refreshed public / app-client / integration-public + generated TS/Swift clients (web enum).
  2. Source canonicalize — normalize_listen_source now uses ConversationSource (same as create persistence), so unknown/mixed-case tokens attach consistently instead of spawning a new convo every reconnect.
  3. conversation_session — only accept status === 'in_progress' before updating the finalize id.
  4. Refs — single conversationIdRef.

Deferred (pre-existing / out of shrink): finalize-vs-drain race on socket close; ultra-short stop before prepare completes (same class as prior processInProgressConversation path).

…ompatible (BasedHardware#5388)

Adding a new response enum member is a released-client breaking change under
check_app_client_openapi_compatibility. Web listen already persists as
unknown via ConversationSource._missing_; cross-source attach still refuses
omi↔unknown without expanding the public contract.

Co-authored-by: Cursor <[email protected]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

OpenAPI still red was not stale schemas — it was check_app_client_openapi_compatibility.py rejecting ConversationSource.web as 14 breaking response-union changes (released clients cannot decode a new enum member).

Fix: removed ConversationSource.web. Query source=web still maps to unknown via _missing_ (same as before this PR). Cross-source attach continues to refuse omi ↔ unknown, so pendant + web stay separate without expanding the released app-client contract.

Local: check_app_client_openapi_compatibility.py --base-ref origin/main → passed.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this well-targeted fix for #5388 — the cross-source attach refusal in prepare() and the client_conversation_id + finalize-by-ID pattern are the right approach for keeping pendant and web recordings on separate conversations.

A few observations for the maintainer:

  1. PR description is now stale. It still says "add ConversationSource.web," but that member was removed for OpenAPI compatibility and source=web now maps to unknown via _missing_. The behavior is correct (unknown != omi, so cross-source attach still refuses), but updating the description would help reviewers.

  2. Finalize-vs-drain race (pre-existing, acknowledged). The backend only auto-finalizes desktop-source conversations on clean disconnect (runtime.py close_code == 1000 path). Web recordings rely on the frontend /finalize call, which fires immediately after socket.disconnect() and may race with trailing buffered-audio segments. This is strictly better than before (correct conversation vs wrong conversation), but worth tracking as a follow-up so short tail-end audio isn't dropped.

  3. Unknown-source bucketing. Since source=web maps to unknown, any other unrecognized source would share that bucket with web. Not a blocker for #5388 (pendant is omi), just noting the coarseness is intentional to avoid an OpenAPI breaking change.

Unit tests for the cross-source decision logic are solid. Requesting human maintainer review since this touches conversation routing and finalization (user-data persistence).


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added needs-maintainer-review Needs a human maintainer to sign off before merge backend Backend Task (python) labels Aug 6, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level PR description is now updated to match the landed diff (no ConversationSource.web contract expansion; source=web stays mapped to unknown).\n\nAll scoped checks are green, and this is ready for human maintainer approval/merge when you’re comfortable.\n\nFollow-up race (finalize vs tail-drain) is tracked as separate out-of-scope hardening.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level All CI checks are green on the current head of #11173 (only the human approval gate remains).\n\nAlso, I updated the PR description to remove the stale wording about adding ConversationSource.web (the merged behavior keeps source=web mapping via missing to unknown, and cross-source attach still refuses omi vs unknown).\n\nWhen you’re comfortable, could you please proceed with approval to clear the remaining needs-maintainer-review gate? The finalize-vs-drain timing item is still tracked as an explicit follow-up/out-of-scope, per the PR.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Refuses cross-source in-progress attach so web and device recordings no longer collide; unit test covers the refusal.

@kodjima33
kodjima33 merged commit b6c1e7d into BasedHardware:main Aug 6, 2026
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Simultaneous device + web app recording fails — both are lost

3 participants