Skip to content

fix(aws): nest endpointingSensitivity under turnDetectionConfiguration for Nova Sonic 2#6201

Open
St-Luciferr wants to merge 1 commit into
livekit:mainfrom
St-Luciferr:fix/nova-sonic-2-turn-detection
Open

fix(aws): nest endpointingSensitivity under turnDetectionConfiguration for Nova Sonic 2#6201
St-Luciferr wants to merge 1 commit into
livekit:mainfrom
St-Luciferr:fix/nova-sonic-2-turn-detection

Conversation

@St-Luciferr

Copy link
Copy Markdown

Summary

Nova Sonic 2 (amazon.nova-2-sonic-v1:0) rejects the sessionStart event with
ValidationException: Invalid input request because the plugin emits the
turn-detection setting as a flat endpointingSensitivity field β€” the legacy
Nova Sonic 1 shape. Nova 2 requires it nested under turnDetectionConfiguration
(AWS docs).
This breaks every Nova Sonic 2 session at startup and cascades into
speech not done in time after interruption and session shutdown.

Changes

  • Add a TurnDetectionConfiguration model and a turnDetectionConfiguration
    field on SessionStart.
  • Make SonicEventBuilder serialization model-aware: Nova Sonic 2 β†’ nested
    turnDetectionConfiguration; Nova Sonic 1 (amazon.nova-sonic-v1:0) β†’ legacy
    flat endpointingSensitivity (no regression). Detection uses a substring
    match ("nova-2-sonic" in model) so cross-region inference-profile ids such
    as us.amazon.nova-2-sonic-v1:0 are handled correctly.
  • Thread the model id into both SonicEventBuilder construction sites,
    including the session reconnect/restart path β€” otherwise a reconnected
    Nova Sonic 1 session would fall back to the default model id and wrongly emit
    the nested form.
  • Serialize the sessionStart event with exclude_none=True so only the
    relevant field is emitted.

Behavior notes

  • The plugin's serialization was unchanged across recent releases (verified back
    through 1.3.x), so this is an AWS-side validation tightening, not a recent
    plugin regression. On Nova Sonic 2 the flat field was previously silently
    ignored
    , so turn_detection=... was effectively a no-op there β€” it now
    actually applies.

Testing

@St-Luciferr St-Luciferr requested a review from a team as a code owner June 24, 2026 09:01
@CLAassistant

CLAassistant commented Jun 24, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Open in Devin Review

Comment on lines +50 to +51
class TestSessionStartTurnDetection:
"""Model-aware serialization of the turn-detection setting."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟑 Test module missing mandatory pytestmark category marker

AGENTS.md mandates that every test module declares a category marker (pytestmark = pytest.mark.unit, etc.): "Adding a test: give the new module a category marker (pytestmark = pytest.mark.unit, etc.) β€” collection fails with a hint if it lacks one." The new test file test_nova_sonic_turn_detection.py has no pytestmark declaration. This is a pure unit test (no network/credentials needed) and should be marked pytest.mark.unit.

Prompt for agents
Add a module-level pytestmark to the test file. Since this test is a fast, hermetic unit test with no external dependencies (it even mocks out the AWS SDK), it should be marked as a unit test.

Add the following near the top of the file (after the imports, before the helper function):

import pytest
pytestmark = pytest.mark.unit

This satisfies the AGENTS.md rule requiring all test modules to declare a category marker.
Open in Devin Review

Was this helpful? React with πŸ‘ or πŸ‘Ž to provide feedback.

Comment on lines +382 to +393
if self._nova_sonic_2 and endpointing_sensitivity is not None:
session_start = SessionStart(
inferenceConfiguration=inference,
turnDetectionConfiguration=TurnDetectionConfiguration(
endpointingSensitivity=endpointing_sensitivity
),
)
else:
session_start = SessionStart(
inferenceConfiguration=inference,
endpointingSensitivity=endpointing_sensitivity,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚩 Nova Sonic 2 with endpointing_sensitivity=None falls through to the legacy code path

When self._nova_sonic_2 is True but endpointing_sensitivity is None (line 382), the code falls to the else branch which sets endpointingSensitivity=None on SessionStart. With exclude_none=True, both endpointingSensitivity and turnDetectionConfiguration will be excluded from the JSON, resulting in a session start with no turn detection config at all. This is likely the intended behavior for disabling turn detection, but it's worth confirming with the Nova Sonic 2 API docs that omitting both fields is valid and doesn't cause a ValidationException.

Open in Devin Review

Was this helpful? React with πŸ‘ or πŸ‘Ž to provide feedback.

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.

Nova Sonic 2 sessionStart rejected: endpointingSensitivity must be nested under turnDetectionConfiguration

2 participants