Skip to content

Fix: connection close sequence#32

Merged
sebvanleuven merged 11 commits intomainfrom
fix/conection_close
Feb 11, 2026
Merged

Fix: connection close sequence#32
sebvanleuven merged 11 commits intomainfrom
fix/conection_close

Conversation

@sebvanleuven
Copy link
Contributor

@sebvanleuven sebvanleuven commented Feb 10, 2026

Improving the connection close sequence, so we can call the interrupt in onClose without recursion and double calling.


Summary by cubic

Fix the connection close flow to prevent recursion and double notifications. Standardizes close reasons, makes teardown idempotent, speeds up WebSocket shutdown, and emits close events explicitly.

  • Bug Fixes

    • Emit CONNECTION_CLOSED on client.close (NORMAL); map server SESSION_ENDED to SERVER_CLOSED; emit WEBRTC_FAILURE only on unexpected WebRTC closure; use ConnectionClosedCode everywhere.
    • Guard teardown with a _closing flag; remove ICE-based close handling; lower noisy logs to debug (ICE/data channel); use is_streaming for state checks.
    • Clear message history on close; do not send end_sequence on interrupt; mark Session as closed and signal close event before teardown for consistent state.
    • Set WebSocket close_timeout to 2s to reduce hang time on disconnects.
  • New Features

    • Expose Session.send_user_audio to forward user audio directly.

Written for commit dd234cf. Summary will update on new commits.

@sebvanleuven sebvanleuven requested a review from ao-anam February 10, 2026 12:59
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/anam/client.py">

<violation number="1" location="src/anam/client.py:551">
P2: `interrupt()` calls the async `end_sequence()` on a possibly-None stream without awaiting it. This can raise `AttributeError` when no agent audio stream exists and also skips sending the end-of-sequence signal because the coroutine isn’t awaited. Guard for None and await the call.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/anam/client.py">

<violation number="1" location="src/anam/client.py:371">
P2: close() now skips cleanup when `_is_streaming` is False, so calling close after a CONNECTION_CLOSED event leaves the streaming client and session state uncleared. This can leak resources and keep stale session info.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@sebvanleuven sebvanleuven merged commit 0d60e7b into main Feb 11, 2026
8 checks passed
@sebvanleuven sebvanleuven deleted the fix/conection_close branch February 11, 2026 14:14
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.

2 participants