Skip to content

fix: avoid fatal status for normal Rime TTS shutdown - #2406

Closed
YiminW wants to merge 3 commits into
TEN-framework:mainfrom
YiminW:docs/tts-review-metadata
Closed

YiminW wants to merge 3 commits into
TEN-framework:mainfrom
YiminW:docs/tts-review-metadata

Conversation

@YiminW

@YiminW YiminW commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Problem

Rime TTS reports code -1000 when its websocket closes normally during extension shutdown, which misclassifies a normal close as an unrecoverable error.

Goal

Suppress the fatal disconnect callback for deliberate shutdown and bump the Rime TTS package version to 0.4.15.

Design rationale

The websocket processing cleanup path now reports fatal disconnect only when the session is not already closing. Normal shutdown is handled by the caller and does not emit -1000.

Validation

  • Version consistency check passed for manifest.json and pyproject.toml.
  • git diff --check passed.
  • Extension tests could not start locally because ten_runtime is unavailable.

@github-actions

Copy link
Copy Markdown

[P2] Exercise both shutdown and unexpected disconnect paths
ai_agents/agents/ten_packages/extension/rime_tts/rime_tts.py:202
The new guard is not exercised by the extension-local tests: test_connection_lifecycle.py tests replacement callback suppression using objects constructed with __new__, while the other tests replace RimeTTSClient entirely. Consequently a regression that reports a fatal error on deliberate close, or suppresses a genuine connection failure, would pass the suite. Add deterministic fake-WebSocket tests that run the real processing task and assert no fatal callback after close() or cancellation, but a fatal callback when the task ends unexpectedly; also cover shutdown while the connection or receive is blocked.

[P2] Assert both audio-end accounting fields across terminal paths
ai_agents/agents/ten_packages/extension/rime_tts/manifest.json:4
The required extension-local accounting coverage is missing: the flush test calculates and prints the expected duration but never compares it with the emitted value, and no test asserts request_event_interval_ms. This leaves incorrect duration and event timing undetected for this release. Drive the extension with known PCM and a controlled clock, and assert both fields and at-most-once termination for success, partial-audio error, flush, and no-audio completion.

[P2] Register an independent Rime TTFB observer
ai_agents/agents/ten_packages/extension/rime_tts/manifest.json:4
rime_tts is absent from both guarder TTFB hook registries, so install_ttfb_reference returns None and cannot compare this extension's reported TTFB with the actual first text send and first nonempty audio arrival. The local metric test injects the TTFB event through a mocked client, so it cannot detect an incorrect production measurement either. Add and register a Rime WebSocket observer, with protocol and request-isolation tests and reference-enabled run evidence.

@github-actions

Copy link
Copy Markdown

[P2] Report a normal disconnect when cancelling a synthesizer
ai_agents/agents/ten_packages/extension/rime_tts/rime_tts.py:205
_session_closing is also set by RimeTTSynthesizer.cancel(), which cancel_tts() calls on a flush before creating a replacement connection. The cancelled channel tasks lead the old processing task into this finally block, but the new guard suppresses its only disconnect callback; the flush path does not call suppress_connection_callbacks_for_replacement(). As a result observers see the old connection stay connected until the replacement reports its state, and never receive its disconnected transition. Normal close() likewise no longer reports a disconnect. Report a nonfatal/normal disconnect for deliberate closure, while ensuring an old synthesizer cannot overwrite the replacement's state; add a flush/replacement ordering test for the emitted statuses.

@github-actions

Copy link
Copy Markdown

[P2] Report a normal disconnect on deliberate close instead of suppressing it
ai_agents/agents/ten_packages/extension/rime_tts/rime_tts.py:204

The new not self._session_closing guard removes the -1000, but it also removes the only disconnect report on these paths. on_connection_disconnected is what produces the disconnected connection status. _session_closing is set by close() (extension on_stop) and also by RimeTTSynthesizer.cancel(), which RimeTTSClient.cancel() calls on flush. On flush, cancel() cancels the channel tasks, CancelledError escapes _await_channel_tasks(), and the finally block now reports nothing for the old live connection. The replacement synthesizer then reports connecting/connected with no disconnected before it. The status sequence becomes connected → connecting → connected, and shutdown never reports disconnected at all. reset_synthesizer() avoids this because suppress_connection_callbacks_for_replacement() sends code=0, but the flush path through cancel() does not. Fix: when _session_closing is set and self.ws existed, call the callback with code=0 (the same payload as suppress_connection_callbacks_for_replacement). Keep FATAL_ERROR for an unexpected end of the task. Also guard against reporting twice when the callback was already cleared or already fired.

[P2] Add regression tests for the closing-vs-unexpected disconnect split
ai_agents/agents/ten_packages/extension/rime_tts/rime_tts.py:204

The PR changes how disconnects are classified. It adds no test, and it notes that extension tests were not run. The WebSocket test matrix in tests.md requires disconnect/cancel ordering coverage. tests/test_connection_lifecycle.py already builds a RimeTTSynthesizer stub without the runtime, so a test is cheap to add. It should assert three things:

  1. close() while connected reports exactly one non-fatal disconnect and no FATAL_ERROR.
  2. RimeTTSClient.cancel() during streaming reports the old connection's disconnect before the replacement's connecting.
  3. An unexpected end of _process_websocket with _session_closing == False (for example, retries exhausted in _process_ws_exception) still reports FATAL_ERROR.

Version bump 0.4.14 → 0.4.15 matches in manifest.json and pyproject.toml. No new imports.


Outside the TTS extension scope: this PR also adds review rules 13–14 to .agents/skills/ten-tts-review/ (SKILL.md and references/common.md). The title and description don't mention them. Consider moving them to a separate docs: PR so the Rime fix can be reviewed and reverted on its own.

@YiminW

YiminW commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Recreating this PR from the TEN-framework repository branch instead of the fork branch.

@YiminW YiminW closed this Nov 14, 2026
@github-actions

Copy link
Copy Markdown

TTS review: rime_tts

[P2] Add a regression test for the shutdown/fatal-disconnect split
ai_agents/agents/ten_packages/extension/rime_tts/rime_tts.py:204
The change decides whether -1000 goes out based on _session_closing alone, and no extension-local test covers it. The PR says local tests could not run. tests/test_connection_lifecycle.py already drives RimeTTSynthesizer directly with a fake on_disconnected, so a test here needs no ten_runtime service. It should assert both sides of the condition:

  1. close() and cancel() (flush) must not report FATAL_ERROR.
  2. An unexpected end of _process_websocket with _session_closing == False must still report FATAL_ERROR exactly once. Examples are process_exception returning the exception after 5 retries, or an exception escaping _await_channel_tasks.

Without the second assertion, a future change that sets _session_closing earlier could hide real fatal disconnects. The WebSocket matrix in references/tests.md requires disconnect/cancel ordering coverage.

[P3] Report a normal disconnect on shutdown, or fix the comment
ai_agents/agents/ten_packages/extension/rime_tts/rime_tts.py:200-204
The new comment says "the normal websocket close code is handled by the caller". Neither caller reports a disconnect:

  • RimeTTSynthesizer.close() (lines 460-480) cancels websocket_task and closes ws without calling on_connection_disconnected.
  • cancel() (lines 410-418) does the same.

After this change, a deliberate close or flush emits no disconnect at all. The connection status stays connected after the socket is gone. suppress_connection_callbacks_for_replacement() reports code=0, message="closed" for this kind of transition. The finally block could do the same when _session_closing is true, instead of skipping the callback. If silence is intended, update the comment so it does not point to a caller that doesn't exist.

[P2] rime_tts has no TTFB hook in the guarder
ai_agents/agents/ten_packages/extension/rime_tts/manifest.json:4
rime_tts appears in tts_guarder/tests/test_connection_status.py. It has no entry in tests/ttfb_reference.py and no module in tests/ttfb_hooks/, so its TTFB has no independent reference check. This gap predates the PR. The review baseline still requires it for every touched TTS extension. It can be handled in a follow-up, but it should be tracked.

The version bump to 0.4.15 matches in manifest.json and pyproject.toml. No new imports or dependencies were added.

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