Skip to content

fix: retain speech providers until stream cleanup finishes - #143369

Merged
steipete merged 2 commits into
mainfrom
codex/streaming-speech-resources
Sep 9, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/streaming-speech-resources

Conversation

@steipete

@steipete steipete commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Related: #140674. Builds on telephony #143065 and buffered speech #143313.

What Problem This Solves

Resolves a problem where speech streams outlive the provider registrations they use, or leave resources behind when metadata fails, cancellation is delayed, or an unopened stream has already ended.

Why This Change Was Made

Transfer the existing owned speech acquisition to the returned stream. Retain it through metadata, reads, source cancellation, provider release, and tracked producer work. Start cancellation before waiting for reads it must unblock, preserve the last queued chunk, and finalize outside the work being drained.

Providers with an explicit release callback keep their existing contract: callers await release after EOF or read failure. Providers without one clean up automatically, including empty or failed unopened streams and a consumed final queued chunk. Failed metadata projection cleans up before fallback; errors after bytes have escaped do not start another provider.

All three synthesis paths now require an owned prepared registry. The unused raw setup function and its type-only coupling are removed; public synchronous provider lookup contracts remain unchanged.

User Impact

Streaming speech retains its provider resources until actual cleanup finishes. It preserves explicit release, cancellation, provider selection and raw-host ownership, without adding a release obligation for providers that previously had none. Completed audio remains usable after disposal.

Evidence

Native regressions cover retirement, cancellation, blocked producer work, metadata/getter failures, cleanup-error precedence, unopened termination, and final-chunk delivery. Final combined testing passes 48 distinct cases across streaming, telephony, buffered speech and Talk. The preceding ownership candidate also passed 141 sibling/E2E cases, including Discord voice and provider binary-stream controls.

Affected checks, fresh full-candidate Codex review through P2, and the final ordinary build passed. The final build took 298.41 seconds and emitted a non-fatal UI startup gzip warning of 29 bytes over its threshold; no UI source, baseline or guard was changed.

Both actual compiled public APIs passed on one sealed build: 21 streaming requests and nine buffered calls across cold, managed and raw ownership. They exercised real WAV/PCM roundtrips and SQLite reads through metadata, cleanup and delayed work, followed by close/reopen. All six process groups terminated; all 11,390 artifact hashes remained unchanged, with no application source fallback. These use synthetic local providers, not an external speech vendor, carrier or operator Gateway.

An additional 32 Web-reader cases covered pending reads, timed/gated cleanup and cleanup failures, preserving final chunks and errors. Timings are local observations, not a comparative speedup claim.

@clawsweeper

clawsweeper Bot commented Sep 9, 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 docs Improvements or additions to documentation size: XL maintainer Maintainer-authored PR labels Sep 9, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 9, 2026
@clawsweeper

clawsweeper Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 4:33 PM ET / 20:33 UTC (Revision 2).

ClawSweeper review

What this changes

Retains speech plugin resources through stream reads, cancellation, and cleanup, with lifecycle documentation and regression coverage.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused repair: current main and the latest release lack streaming resource ownership, and the related merged fixes explicitly exclude streams. No actionable introduced defect was found.

Priority: P2
Reviewed head: 82c780cf6b17f3303c59aea95c976809b9ac1ed5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent owner-level repair with meaningful regression coverage and reported compiled-runtime validation; no blocking defect was found.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied maintainer classification exempts this PR from the external-contributor proof gate. Its body reports compiled speech API runs through stream cleanup and SQLite disposal across three ownership modes; this review inspected the matching production path and tests without replaying those runs.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied maintainer classification exempts this PR from the external-contributor proof gate. Its body reports compiled speech API runs through stream cleanup and SQLite disposal across three ownership modes; this review inspected the matching production path and tests without replaying those runs.
Evidence reviewed 8 items Current main still needs the repair: The fetched main implementation uses resolveTtsRequestSetup and returns the provider's audioStream and release callback directly, without acquiring a resource owner for the returned stream.
Latest release has the same gap: The v2026.9.3 streaming implementation also directly returns provider streams without the proposed resource ownership.
Cleanup ordering and existing contracts: The new owner starts transport cancellation before joining pending reads, releases registrations after cleanup, and finalizes no-release providers outside the pull being joined. Providers with explicit release retain their existing caller obligation. Discord playback already awaits the returned release callback in its cleanup path.
Findings None None.
Security None None.

How this fits together

OpenClaw's speech runtime selects a configured provider and returns audio to callers such as Discord voice playback. The stream owner keeps provider resources available until playback and cleanup finish.

flowchart TD
  A[Text and speech settings] --> B[Acquire speech providers]
  B --> C[Select provider and synthesize]
  C --> D[Owned audio stream]
  D --> E[Playback consumer]
  E --> F[EOF, error, cancellation or release]
  F --> G[Finish transport and producer work]
  G --> H[Release provider resources]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +261, Tests +545, Docs +9. Total +815 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 384 123 +261
Tests 2 546 1 +545
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 939 124 +815

Review metrics

Metric Value Why it matters
Production versus test growth Production net +261 lines; tests net +545 lines Production growth implements the escaping stream's lifecycle owner; tests cover disposal ordering and compatibility across existing ownership modes.

Root-cause cluster

Relationship: canonical
Canonical: #143369
Summary: This is the focused streaming-lifetime candidate extracted from the broader resource-ownership effort.

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 acquisition owner through stream termination and actual cleanup while preserving provider selection, explicit release, and raw-host lifetimes.

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

Yes, from source: current main hands streams out without retaining managed provider registrations, and the native fixture exercises releasing the inspection before consuming the stream. This review did not execute that regression.

Is this the best way to solve the issue?

Yes. Extending the existing acquisition mechanism through stream cleanup repairs the owning boundary and avoids a competing provider-selection path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 227e2f4fe1c2.

Labels

Label justifications:

  • P2: Repairs a bounded speech resource-lifecycle gap without evidence of an urgent widespread outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied maintainer classification exempts this PR from the external-contributor proof gate. Its body reports compiled speech API runs through stream cleanup and SQLite disposal across three ownership modes; this review inspected the matching production path and tests without replaying those runs.

Evidence

What I checked:

  • Current main still needs the repair: The fetched main implementation uses resolveTtsRequestSetup and returns the provider's audioStream and release callback directly, without acquiring a resource owner for the returned stream. (src/tts/tts-streaming.ts:22, 227e2f4fe1c2)
  • Latest release has the same gap: The v2026.9.3 streaming implementation also directly returns provider streams without the proposed resource ownership. (src/tts/tts-streaming.ts:22, 1391f7cd2d40)
  • Cleanup ordering and existing contracts: The new owner starts transport cancellation before joining pending reads, releases registrations after cleanup, and finalizes no-release providers outside the pull being joined. Providers with explicit release retain their existing caller obligation. Discord playback already awaits the returned release callback in its cleanup path. (src/tts/tts-streaming-resources.ts:114, 82c780cf6b17)
  • Meaningful lifecycle regression coverage: The new tests exercise real SQLite connections through EOF, read errors, unopened streams, managed and raw registrations, blocked producer tails, metadata failures, and final queued chunks. Tests were inspected, not executed during this read-only review. (src/tts/tts-streaming.resources.test.ts:204, 82c780cf6b17)
  • Captured runtime evidence and review continuity: The complete supplied PR body reports compiled public API validation with 21 streaming requests and nine buffered calls across cold, managed, and raw ownership, including WAV/PCM roundtrips and SQLite close/reopen checks. This is reported synthetic-provider validation, not an independently replayed vendor run. Captured context sourceRevision is 0d62d774778c60bd3edc3c1787311eace6f8286dfbba3a6e9e055cf8b47fd36a. The prior completed review examined this same head and retained no findings. (82c780cf6b17)
  • Related work does not supersede streaming: GitHub confirms fix: retain buffered speech providers through synthesis cleanup #143313 merged; its supplied body explicitly excludes returned streams. The merged telephony predecessor likewise treats streaming as a separate boundary. The live body of refactor(plugins): release scoped resources after actual work #140674 identifies this streaming PR as a focused replacement and says the aggregate draft will not merge. (9b99c6113fe0)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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 (1 earlier review cycle)
  • reviewed 2026-09-09T20:22:47.160Z sha 82c780c :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review September 9, 2026 20:25
@steipete
steipete merged commit d77cb0a into main Sep 9, 2026
247 checks passed
@steipete
steipete deleted the codex/streaming-speech-resources branch September 9, 2026 20:48
@steipete

steipete commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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.

1 participant