Skip to content

fix: make disconnect() have stable reference to prevent unexpected cleanup#21

Merged
jackbridger merged 1 commit intomainfrom
fix/stable-disconnect-reference
Jan 14, 2026
Merged

fix: make disconnect() have stable reference to prevent unexpected cleanup#21
jackbridger merged 1 commit intomainfrom
fix/stable-disconnect-reference

Conversation

@jackbridger
Copy link
Copy Markdown
Contributor

Summary

  • Fixed a bug where mute(), unmute(), and disconnect() functions wouldn't update reactive state
  • The root cause was disconnect having onError in its dependency array, causing it to get a new identity when users passed inline callbacks
  • When disconnect was used in a useEffect dependency array, this triggered unexpected cleanup calls that nullified clientRef.current
  • Added helpful warning logs when functions are called without an active client

Test plan

  • Connect to a voice session
  • Click "Mute" - should now properly update isMuted state
  • Click "Disconnect" - should properly end the session and update status

Fixes the bug reported where calling mute(), unmute(), or disconnect() would execute without errors but not update the corresponding reactive state values.

🤖 Generated with Claude Code

…eanup

The disconnect useCallback had onError in its dependency array, which caused
it to get a new identity whenever onError changed. This was problematic when
users had disconnect in a useEffect dependency array with inline callbacks:

1. Component renders with inline onError callback
2. disconnect gets new identity (onError changed)
3. useEffect cleanup runs, calling disconnect()
4. clientRef.current becomes null
5. Subsequent mute()/unmute()/disconnect() calls fail silently

The fix removes onError from disconnect's dependencies since the error is
thrown and can be caught by the caller. Also adds helpful warning logs when
functions are called without an active client.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2085a4c616

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/index.tsx
Comment on lines 426 to 429
await client.disconnect();
} catch (error) {
console.error('Failed to disconnect from agent:', error);
onError?.(error as Error);
throw error;
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 Badge Call onError when disconnect fails

In disconnect’s catch block the error is only logged and rethrown, whereas previously onError was invoked. Callers that rely on onError for user-visible error handling (and often call disconnect() from a useEffect cleanup without awaiting it) will now miss disconnect failures entirely, which is a behavioral regression from the previous API contract.

Useful? React with 👍 / 👎.

@jackbridger jackbridger merged commit a7113b1 into main Jan 14, 2026
3 checks passed
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