Skip to content

fix(tts): hold a trailing lone bracket across stream chunks - #144161

Merged
obviyus merged 9 commits into
openclaw:mainfrom
Bartok9:bartok9/fix-tts-stream-lone-bracket
Sep 15, 2026
Merged

obviyus merged 9 commits into
openclaw:mainfrom
Bartok9:bartok9/fix-tts-stream-lone-bracket

Conversation

@Bartok9

@Bartok9 Bartok9 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

This repair includes registered tests for both delivery lifecycles and moves existing helpers to keep the coordinator within its size limit.

What Problem This Solves

createTtsDirectiveTextStreamCleaner only parks a partial tag after it has seen both characters of [[. When a stream chunk ends on a single [, that bracket is emitted (or dropped) and the opener is never recognized.

Fixes #144151. Split openers leak speech-only text; split closers swallow the visible suffix.

Fix

Retain split delimiters and drain literal carry once at completion. Normal dispatch and ACP each use their existing lifecycle adapter over the same source receipt. That receipt owns source completion and ordering.

ACP recovery reuses the prepared payload and send operation instead of rebuilding a string. It preserves reply metadata, avoids repeated prefixes, transforms, media and speech, and respects cancellation and queue custody. The stateful stream tests now run in their existing auto-reply project.

Growth record

Ayaan, 2026-09-15: "accept the growth, land #144161".

Production is +221 net lines against the merge base, accepted by the owner for the ACP terminal drain, the prepared-payload recovery that replaced the string fallback, and the helper move into the existing payload module that keeps the coordinator under the 700-line rule. This adds no state owner.

Evidence

Gateway/Discord captures and correction evidence: split tags and literal tails reach the recipient correctly; audio stays separate from visible speech-only text. Registered recovery tests verify exact bytes, one transform/media delivery, metadata, cancellation and released custody. Real packaged Discord faults verify retained queue custody on both builds.

The 384 owner/sibling tests passed on head and fresh merge. After correcting test routing, all 12 stream cases pass under auto-reply, 136 routing tests pass, and the hosted unit-fast selector passes 9,235 tests with two skips. Local preflight passed.

Record correction: tested merge eaf170ab included main 2e7aa1b7 through an intermediate merge; the earlier reported f1cdcd51 was only an ancestor. Later merge 904f4d9e has exact parents main 78520903 and candidate 7614c08e. Earlier captures retain their actual identities.

The ledger records removal of the newline between same-source fragments, leaving "Intro visible" with two spaces; independent sources keep their separator. Duplicate helper-only bracket rows were removed while registered normal/ACP regressions and contributor history remain.

Consumers

Normal channel dispatch, ACP direct/routed delivery, terminal-only surfaces and retained followups retain their owners. Source receipts serialize continuations; actual delivery controls recovery and transcript coverage. Deferred captions retain complete-text fallback.

Compatibility

No new configuration, schema or public API.

A chunk that ends on a single "[" never arms the [[ pending buffer, so
the next chunk either leaks hidden [[tts:text]] speech or swallows the
rest of the reply. Buffer that trailing "[" until the next push or flush.
@clawsweeper

clawsweeper Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 10, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 10, 2026
@clawsweeper

clawsweeper Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 10:25 PM ET / September 15, 2026, 02:25 UTC (Revision 8).

ClawSweeper review

What this changes

Preserves split speech directives and trailing literal brackets across normal and external-agent reply streams, with prepared-payload recovery and registered delivery tests.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main and v2026.9.4 still mishandle split brackets. The previous terminal-drain finding is resolved, the linked runtime evidence supports the repair, and no new blocking defect was found.

Priority: P2
Reviewed head: 691ce254d87023a51e0d26bb3051db867a5f5a74

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent repair with convincing runtime evidence, meaningful delivery regressions, and no remaining actionable finding.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): Inspected Gateway/Discord captures demonstrate corrected split delimiters and literal-tail delivery through the production cleaner and dispatch paths, with separate audio and preserved reply metadata. Later packaged-transport faults demonstrate retained queue custody; released-custody recovery and deferred captions have supplemental registered tests, not claimed live proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): Inspected Gateway/Discord captures demonstrate corrected split delimiters and literal-tail delivery through the production cleaner and dispatch paths, with separate audio and preserved reply metadata. Later packaged-transport faults demonstrate retained queue custody; released-custody recovery and deferred captions have supplemental registered tests, not claimed live proof.
Evidence reviewed 7 items Current main still contains the defect: The no-opener branch emits or discards a trailing single bracket without buffering it, so the next chunk cannot reconstruct the delimiter.
Latest release remains affected: The same no-opener branch and flush behavior remain in v2026.9.4; this is not an already-shipped repair.
Existing behavior contract: The documented streaming contract strips directives across adjacent blocks and keeps speech-only text out of visible replies.
Findings None None.
Security None None.

How this fits together

OpenClaw separates speech-only directives from visible assistant replies before sending streamed messages. Normal dispatch and external-agent dispatch use the shared cleaner and delivery receipts to coordinate text, audio, recovery, and transcript completion.

flowchart TD
  A[Assistant text chunks] --> B[Speech directive cleaner]
  B --> C[Visible reply fragments]
  B --> D[Buffered delimiter]
  D --> E[Stream completion]
  E --> C
  C --> F[Ordered delivery receipts]
  F --> G[Channel delivery or recovery]
  F --> H[Transcript completion]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +221, Tests +588. Total +809 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 7 457 236 +221
Tests 6 617 29 +588
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 1074 265 +809

Review metrics

Metric Value Why it matters
Production and regression coverage Production +221 net lines; tests +587; test routing +1 The PR explains the production growth through terminal draining, prepared-payload recovery, and moving helpers within the existing delivery owner.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #144151
Summary: This PR is the candidate repair for the linked split-delimiter issue; related delivery and free-text work does not replace it.

Members:

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

Technical review

Best possible solution:

Keep one shared directive parser and source receipt, with each existing delivery lifecycle draining and recovering only its undelivered prepared fragments.

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

Yes: current source deterministically mishandles chunks split between the two opening brackets of either delimiter. This review inspected source and supplied runtime captures; it did not execute target code.

Is this the best way to solve the issue?

Yes: buffering the delimiter and draining through existing delivery owners repairs the documented behavior without new configuration, public APIs, or competing recovery state.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 38c4aa42e4ce.

Labels

Label justifications:

  • P2: A specific stream boundary can leak speech-only text or truncate the visible answer, with limited and intermittent exposure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): Inspected Gateway/Discord captures demonstrate corrected split delimiters and literal-tail delivery through the production cleaner and dispatch paths, with separate audio and preserved reply metadata. Later packaged-transport faults demonstrate retained queue custody; released-custody recovery and deferred captions have supplemental registered tests, not claimed live proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. Inspected Gateway/Discord captures demonstrate corrected split delimiters and literal-tail delivery through the production cleaner and dispatch paths, with separate audio and preserved reply metadata. Later packaged-transport faults demonstrate retained queue custody; released-custody recovery and deferred captions have supplemental registered tests, not claimed live proof.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The shared cleaner changes visible Telegram reply text when speech delimiters split across streamed chunks.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

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.

History

Review history (7 earlier review cycles)
  • reviewed 2026-09-10T15:53:57.744Z sha 8b02f01 :: needs real behavior proof before merge. :: [P2] [P2] Drain buffered literal tails through streaming delivery
  • reviewed 2026-09-15T00:04:10.048Z sha 1c7ac29 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T00:41:06.875Z sha 7614c08 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T01:02:42.103Z sha 7c871c0 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T01:48:11.031Z sha 691ce25 :: blocked before merge. :: none
  • reviewed 2026-09-15T02:07:35.000Z sha 691ce25 :: needs changes before merge. :: none
  • reviewed 2026-09-15T02:18:53.876Z sha 691ce25 :: needs maintainer review before merge. :: none

obviyus added a commit that referenced this pull request Sep 14, 2026
…g prefixes (#148301)

Depends on #148318.

## What Problem This Solves
A streamed prefix could mark the complete reply sent. If its deferred tail then failed, the final reply was already gone.

## Why This Change Was Made
One source receipt owns completion, ordered sends, and final recovery; this state has one writer. Completed sources, including fenced code, are not replayed. Pending sends retain custody.

## User Impact
Missing tails recover once, in order. Completed finals are cleared. Safe text and media still send immediately. Final-only media still sends when text is ambiguous, without changing its unknown state.

## Evidence
`node scripts/run-vitest.mjs src/auto-reply/reply/dispatch-from-config.source-completion.test.ts`: before, `See `; after, `See [` once. Fifteen producer cases and 410 sibling tests passed, including ambiguous text with unsent media.

With a real Gateway and Discord adapter against a local mock server, main lost a buffered literal tail; this head retained it for one queue recovery after the final send was refused, without replaying the prefix or its image bytes.

Live Discord closing proof was composed with #144161's parser commit `8b02f015`; that dependency is excluded here.

## Compatibility
No configuration, protocol, storage, or SDK export changes. Parser and terminal drains remain separate work.

## Consumers
Normal dispatch, ACP delivery, and direct/final reply accounting share the receipt.

## Invalidation
Receipts live for one source and remain reachable through its final settlement.

## Tests
Existing split-text fixtures now provide actual delivery settlements. Their assertions are unchanged.

## Contention
A concurrent suffix stays behind a failed prefix; safe block admission does not await transport settlement.

Co-authored-by: Ayaan Zaidi <[email protected]>
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 15, 2026
@obviyus

obviyus commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

landpr-approve-admin-merge
pr: 144161
head: 691ce25
scope: owner-review

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 15, 2026
@obviyus
obviyus merged commit 12fa7d4 into openclaw:main Sep 15, 2026
240 of 243 checks passed
@obviyus

obviyus commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Bartok9!

Proof: Discord streaming checks preserve split speech tags and the literal See [ exactly once. Recovery tests preserve reply metadata without repeated prefixes, media or speech.

  • Bug: Split speech tags could expose hidden speech or lose visible reply text.
  • Fix: Streaming delivery settles the visible tail once and recovers only an undelivered prepared continuation.
Before After
Split tags could leak hidden speech or swallow the visible suffix. Speech stays hidden and the visible suffix arrives.
A failed literal tail could disappear or repeat a prefix during recovery. Only the missing tail is recovered, with its reply identity preserved.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 15, 2026
…g prefixes (openclaw#148301)

Depends on openclaw#148318.

## What Problem This Solves
A streamed prefix could mark the complete reply sent. If its deferred tail then failed, the final reply was already gone.

## Why This Change Was Made
One source receipt owns completion, ordered sends, and final recovery; this state has one writer. Completed sources, including fenced code, are not replayed. Pending sends retain custody.

## User Impact
Missing tails recover once, in order. Completed finals are cleared. Safe text and media still send immediately. Final-only media still sends when text is ambiguous, without changing its unknown state.

## Evidence
`node scripts/run-vitest.mjs src/auto-reply/reply/dispatch-from-config.source-completion.test.ts`: before, `See `; after, `See [` once. Fifteen producer cases and 410 sibling tests passed, including ambiguous text with unsent media.

With a real Gateway and Discord adapter against a local mock server, main lost a buffered literal tail; this head retained it for one queue recovery after the final send was refused, without replaying the prefix or its image bytes.

Live Discord closing proof was composed with openclaw#144161's parser commit `8b02f015`; that dependency is excluded here.

## Compatibility
No configuration, protocol, storage, or SDK export changes. Parser and terminal drains remain separate work.

## Consumers
Normal dispatch, ACP delivery, and direct/final reply accounting share the receipt.

## Invalidation
Receipts live for one source and remain reachable through its final settlement.

## Tests
Existing split-text fixtures now provide actual delivery settlements. Their assertions are unchanged.

## Contention
A concurrent suffix stays behind a failed prefix; safe block admission does not await transport settlement.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 15, 2026
…#144161)

This repair includes registered tests for both delivery lifecycles and moves existing helpers to keep the coordinator within its size limit.

## What Problem This Solves

`createTtsDirectiveTextStreamCleaner` only parks a partial tag after it has seen both characters of `[[`. When a stream chunk ends on a single `[`, that bracket is emitted (or dropped) and the opener is never recognized.

Fixes openclaw#144151. Split openers leak speech-only text; split closers swallow the visible suffix.

## Fix

Retain split delimiters and drain literal carry once at completion. Normal dispatch and ACP each use their existing lifecycle adapter over the same source receipt. That receipt owns source completion and ordering.

ACP recovery reuses the prepared payload and send operation instead of rebuilding a string. It preserves reply metadata, avoids repeated prefixes, transforms, media and speech, and respects cancellation and queue custody. The stateful stream tests now run in their existing auto-reply project.

## Growth record

Ayaan, 2026-09-15: "accept the growth, land openclaw#144161".

Production is **+221 net lines against the merge base**, accepted by the owner for the ACP terminal drain, the prepared-payload recovery that replaced the string fallback, and the helper move into the existing payload module that keeps the coordinator under the 700-line rule. This adds no state owner.

## Evidence

[Gateway/Discord captures and correction evidence](https://gist.github.com/obviyus/f14fbf2109f3bb30d68e2af5e54b2d61): split tags and literal tails reach the recipient correctly; audio stays separate from visible speech-only text. Registered recovery tests verify exact bytes, one transform/media delivery, metadata, cancellation and released custody. Real packaged Discord faults verify retained queue custody on both builds.

The 384 owner/sibling tests passed on head and fresh merge. After correcting test routing, all 12 stream cases pass under auto-reply, 136 routing tests pass, and the hosted unit-fast selector passes 9,235 tests with two skips. Local preflight passed.

Record correction: tested merge `eaf170ab` included main `d4d14aca` through an intermediate merge; the earlier reported `bdb6b9f7` was only an ancestor. Later merge `904f4d9e` has exact parents main `31ed4888` and candidate `7614c08e`. Earlier captures retain their actual identities.

The ledger records removal of the newline between same-source fragments, leaving `"Intro  visible"` with two spaces; independent sources keep their separator. Duplicate helper-only bracket rows were removed while registered normal/ACP regressions and contributor history remain.

## Consumers

Normal channel dispatch, ACP direct/routed delivery, terminal-only surfaces and retained followups retain their owners. Source receipts serialize continuations; actual delivery controls recovery and transcript coverage. Deferred captions retain complete-text fallback.

## Compatibility

No new configuration, schema or public API.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TTS stream cleaner mishandles a chunk split between the two opening brackets, leaking hidden speech text or swallowing the rest of the reply

2 participants