Skip to content

fix(tts): preserve free-text [[tts:...]] reply body - #137288

Closed
gaoanze888 wants to merge 1 commit into
openclaw:mainfrom
gaoanze888:fix/tts-free-text-reply
Closed

gaoanze888 wants to merge 1 commit into
openclaw:mainfrom
gaoanze888:fix/tts-free-text-reply

Conversation

@gaoanze888

Copy link
Copy Markdown

What Problem This Solves

When tts.auto: "inbound", the system-prompt hint tells the model to Use [[tts:...]] and optional [[tts:text]]...[[/tts:text]] to control voice/expressiveness. gpt-5.6 (via an OpenAI-compatible proxy) reads that as "wrap the reply in the tag" and answers a voice note with, literally:

[[tts:Yes—I understand you clearly now.]]

extractTtsDirectiveFacts parsed the [[tts:...]] body as key=value tokens, found none, stripped the tag, and the reply had no visible text. before_agent_finalize never fired (no visible payload), and the channel received the fallback "No reply was generated for this message...". The transcript stored an empty assistant message with openclawDelivery.tts.tagged: true.

Reproduced by the reporter with openclaw agent exec --model litellm/gpt-5.6-terra in 5 of 6 runs on one host and 2 of 3 on another (version 2026.8.1-beta.3; directive-facts unchanged in 2026.8.2).

Fix

In extractTtsDirectiveFacts, when a [[tts:...]] directive body contains no key=value token (i.e. the model used the tag to carry the spoken reply itself instead of emitting directives), treat the body as the spoken reply text instead of discarding it. This mirrors how [[tts]]...[[/tts]] and [[tts:text]]...[[/tts:text]] already carry their inner body as the spoken text, so all three forms are now consistent. The reply is both shown and spoken, and the empty-reply fallback is no longer reached.

Key=value directives ([[tts:speed=1.5]], [[tts:provider=openai speed=1.2]]) keep their existing behavior — the body is only preserved when there are no parseable directives.

Closes #137281.

Evidence

  • src/tts/directive-facts.ts: the [[tts:...]] directive branch now returns the trimmed body (and sets facts.text) when no key=value tokens are present, instead of always returning "".
  • src/tts/directive-facts.test.ts (new): 9 cases covering the reported scenario and regressions:
    • [[tts:Yes—I understand you clearly now.]] → cleanedText preserves the reply, facts.text set.
    • Multi-word free-text body, free-text inside surrounding prose, whitespace-only body (no synthesized text), single/provider key=value directives (unchanged — body stripped), visible text preserved around a stripped directive, [[tts:text]]...[[/tts:text]] block (unchanged), and plain text without TTS markup (unchanged).
  • Local verification on origin/main (64f4cdac8):
    • npx vitest run src/tts/directive-facts.test.ts src/tts/directives.test.ts src/tts/directive-number.test.ts — 37 passed (15 new + 22 existing).
    • npx vitest run src/tts/ — 206 passed (18 files), no regression.
    • npx tsc --noEmit -p tsconfig.core.json — only the pre-existing chat-turn-router.ts(188,7) false positive (symlinked @types resolution; reproduces on pristine origin/main, not visible to CI's real install).
    • oxlint -c .oxlintrc.json on both files — clean.
    • oxfmt --check on both files — clean.

Notes

  • This is the parser-level fix (option 1 from the issue). It makes the failure mode impossible regardless of how the model phrases the tag, because the reply body is never discarded when there are no directives. The alternative prompt-hint change (option 2) is intentionally left out of this PR to keep the change minimal and avoid altering the prompt contract for other providers.
  • A mixed body ([[tts:provider=openai hello]]) still strips the free-text fragment; that case is not produced by the reported failure and is left as-is to avoid changing directive-parsing semantics.

gpt-5.6 reads the inbound TTS hint as "wrap the reply in the tag" and
emits the spoken reply as the [[tts:...]] directive body.
extractTtsDirectiveFacts parsed that body as key=value tokens, found none,
and stripped the tag, leaving the reply with no visible text — the channel
then delivered the "No reply was generated" fallback.

When the [[tts:...]] body contains no key=value directive, treat it as the
spoken reply text (mirroring [[tts]]...[[/tts]] and [[tts:text]]...[[/tts:text]]
which already carry their body as the spoken text), so the reply is shown
and spoken instead of discarded.
@clawsweeper

clawsweeper Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 3, 2026, 8:10 AM ET / 12:10 UTC.

ClawSweeper review

What this changes

This PR changes TTS directive parsing so a [[tts:...]] tag without key=value options preserves its body as reply text, with unit coverage.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

The parser repair correctly preserves free-text directives for its direct path, but captioned deferred-final delivery still removes that same text, so the reported visible-reply failure remains on an important channel route.

Priority: P1
Reviewed head: 8bd681640e3e1229c8721a3c39a39821158a1d50

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The targeted parser change is plausible but incomplete for a material delivery route, and no post-fix real-behavior proof is supplied.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The supplied evidence is parser/unit-test and static-tool output plus pre-fix reporter runs; it does not show an after-fix inbound-audio turn producing both a visible reply and the intended voice/caption, and the captioned route remains untested. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The supplied evidence is parser/unit-test and static-tool output plus pre-fix reporter runs; it does not show an after-fix inbound-audio turn producing both a visible reply and the intended voice/caption, and the captioned route remains untested. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Introduced parser behavior: The PR head adds the free-text fallback that returns the trimmed directive body and records it as TTS text when no directive values were parsed.
Current-main defect: Current main still parses free-text tts: bodies as no directives and returns an empty replacement; the parser file is unchanged from the reported pre-fix base.
Deferred-caption gap: Captioned final delivery invokes the streaming directive cleaner, which classifies every tts: tag as a directive and emits none of its body; the deferred route consequently overwrites visible text with that empty cleaned result.
Findings 1 actionable finding [P1] Preserve free-text tags in deferred TTS captions
Security None None.

How this fits together

TTS directives are extracted from assistant replies before delivery metadata and speech are prepared. Channels that defer a final voice message also stream-clean the original reply to derive its visible caption.

flowchart LR
  A[Assistant reply] --> B[TTS directive parser]
  B --> C[Delivery facts]
  C --> D[Speech payload]
  A --> E[Deferred caption cleaner]
  E --> F[Final channel caption]
  D --> G[Voice delivery]
  F --> G
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The supplied evidence is parser/unit-test and static-tool output plus pre-fix reporter runs; it does not show an after-fix inbound-audio turn producing both a visible reply and the intended voice/caption, and the captioned route remains untested. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Preserve free-text tags in deferred TTS captions (P1) - Captioned-final channels bypass the repaired value when they derive the final visible caption: the deferred cleaner still treats every [[tts:...]] as a directive and removes its body, then the route uses that empty result. Telegram advertises this delivery mode, so the claimed shown-and-spoken result remains false for a voice-note route. Update the shared streaming/caption classification and cover a free-text tag at the captioned delivery boundary.
  • Resolve merge risk (P1) - Merging leaves captioned deferred-final channels able to discard the free-text body and send an empty visible caption despite the parser fix.
  • Complete next step (P2) - Repair deferred/streaming caption handling for free-text [[tts:...]], add captioned delivery regression coverage, and provide redacted post-fix behavior proof.

Findings

  • [P1] Preserve free-text tags in deferred TTS captions — src/tts/directive-facts.ts:117-121
Agent review details

Security

None.

PR surface

Source +12, Tests +78. Total +90 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 12 0 +12
Tests 1 78 0 +78
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 90 0 +90

Review metrics

Metric Value Why it matters
Production versus test delta production +12, tests +78 The parser behavior is small, but its positive production change must be completed in the shared deferred delivery owner rather than leaving captioned channels inconsistent.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #137281
Summary: This PR is a candidate fix for the reported free-text TTS reply loss, but it does not yet cover the deferred caption branch.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Repair the deferred caption path (recommended)
    Preserve free-text directive bodies in the shared streaming/caption cleanup flow and add a captioned-final delivery regression test before merge.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Repair the shared deferred-caption directive classification and add regression coverage for a free-text [[tts:...]] voice reply retaining visible text.

Technical review

Best possible solution:

Use one shared classification for free-text [[tts:...]] across final parsing and deferred streaming/caption cleanup, then prove a captioned channel preserves the reply text.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: a free-text [[tts:reply]] reaches the deferred cleaner on captioned-final channels, where the cleaner emits no body and the route uses that empty text; no local runtime execution was performed in this read-only review.

Is this the best way to solve the issue?

No: the direct parser change is appropriate, but it is not the best complete repair because deferred caption cleanup independently discards the same form.

Full review comments:

  • [P1] Preserve free-text tags in deferred TTS captions — src/tts/directive-facts.ts:117-121
    Captioned-final channels bypass the repaired value when they derive the final visible caption: the deferred cleaner still treats every [[tts:...]] as a directive and removes its body, then the route uses that empty result. Telegram advertises this delivery mode, so the claimed shown-and-spoken result remains false for a voice-note route. Update the shared streaming/caption classification and cover a free-text tag at the captioned delivery boundary.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4c4144d5ae68.

Labels

Label changes:

  • add P1: The PR addresses a shipped TTS reply path that can deliver a visible fallback instead of the assistant's actual response.
  • add merge-risk: 🚨 message-delivery: Captioned deferred-final delivery still strips free-text directive bodies, so merging would leave an empty visible delivery on that route.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The supplied evidence is parser/unit-test and static-tool output plus pre-fix reporter runs; it does not show an after-fix inbound-audio turn producing both a visible reply and the intended voice/caption, and the captioned route remains untested. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • add proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The parser change affects Telegram's captioned-final voice delivery, so Test Server evidence should demonstrate the visible caption/body after the repair.

Label justifications:

  • P1: The PR addresses a shipped TTS reply path that can deliver a visible fallback instead of the assistant's actual response.
  • merge-risk: 🚨 message-delivery: Captioned deferred-final delivery still strips free-text directive bodies, so merging would leave an empty visible delivery on that route.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The supplied evidence is parser/unit-test and static-tool output plus pre-fix reporter runs; it does not show an after-fix inbound-audio turn producing both a visible reply and the intended voice/caption, and the captioned route remains untested. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The parser change affects Telegram's captioned-final voice delivery, so Test Server evidence should demonstrate the visible caption/body after the repair.

Evidence

Acceptance criteria:

  • [P1] Run the focused TTS parser, captioned-final, and deferred delivery tests.
  • [P1] Capture a redacted inbound-audio/free-text-tag turn showing the retained visible reply and voice/caption, preferably with Telegram Test Server proof.

What I checked:

  • Introduced parser behavior: The PR head adds the free-text fallback that returns the trimmed directive body and records it as TTS text when no directive values were parsed. (src/tts/directive-facts.ts:111, 8bd681640e3e)
  • Current-main defect: Current main still parses free-text tts: bodies as no directives and returns an empty replacement; the parser file is unchanged from the reported pre-fix base. (src/tts/directive-facts.ts:112, 4c4144d5ae68)
  • Deferred-caption gap: Captioned final delivery invokes the streaming directive cleaner, which classifies every tts: tag as a directive and emits none of its body; the deferred route consequently overwrites visible text with that empty cleaned result. (src/tts/directives.ts:113, 8bd681640e3e)
  • Telegram reaches the deferred caption path: Telegram declares captioned final text support, making its voice-note path dependent on the deferred cleaner. (extensions/telegram/src/setup-plugin.ts:39, 8bd681640e3e)
  • Original feature provenance and shipped behavior: The parser was introduced by the structured-reply-speech feature; raw-parent inspection confirms this file was added there, and v2026.8.2 contains that commit, so the defect is shipped. (src/tts/directive-facts.ts:85, 7a3f40c4ac4c)
  • Existing coverage gap: Captioned-final tests cover intentionally hidden [[tts:text]] content, but not a free-text [[tts:...]] tag reaching the deferred caption boundary. (src/tts/captioned-final.test.ts:16, 8bd681640e3e)

Likely related people:

  • Peter Steinberger: Raw commit 7a3f40c adds src/tts/directive-facts.ts:85 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7a3f40c4ac4c; files: src/tts/directive-facts.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Repair free-text handling in deferred streaming/caption cleanup and add a captioned-channel boundary test.
  • Provide redacted after-fix proof that an inbound-audio free-text tag produces visible text and voice/caption.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@gaoanze888

This comment was marked as spam.

@gaoanze888

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tts: a free-text [[tts:...]] reply is stripped to nothing and delivered as "No reply was generated"

1 participant