Skip to content

fix(talk): preserve replacement speech when an old utterance is canceled - #130687

Merged
steipete merged 1 commit into
mainfrom
codex/apple-speech-cancellation-owner
Aug 27, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/apple-speech-cancellation-owner

Conversation

@steipete

@steipete steipete commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #130674

What Problem This Solves

Fixes an issue where users could lose replacement system speech in iOS or macOS Talk when the previous speech task was cancelled just before the replacement started. The same shared owner is used by iOS spoken chat pushes.

Why This Change Was Made

Cancellation schedules cleanup on the main actor. A newer utterance can take ownership before that cleanup runs, so an unconditional stop cancels the wrong operation. Revalidate the existing captured token immediately before stopping, matching the watchdog's ownership check. Explicit public stop remains unconditional; delegate callbacks retain their existing utterance-identity checks.

This is the shared-owner repair, not a caller-specific workaround. No extra state, API, dependency, config, persistence, or fallback is introduced. Production delta is +3/-0: the necessary ownership check and its two-line invariant comment. Tests are separate (+39/-1, including formatter normalization). Moving the check to individual callers would leave other users of the shared synthesizer exposed; introducing another cancellation abstraction would add unnecessary surface.

User Impact

A cancelled utterance can no longer stop speech that replaced it. Active speech cancellation and explicit stop retain their behavior. This fixes the separately reproduced race in #130674, not every silent-audio, provider, or CarPlay report.

Evidence

  • Real Apple AVSpeechSynthesizer, not a fake: against unchanged main source at 73b98c4b50160a1f57f6a0f9197ae6c6b53c22b4, ordinary control speech completed, but cancelling A and immediately awaiting B on the main actor cancelled B before its start callback, despite its caller not being cancelled. Reproduced twice. The retained regression also failed on the original source.
  • With the token check, replacement speech started and completed; the final opt-in retained regression passed (1 test, 0 failures, 3.269 seconds). Earlier focused coverage also passed active cancellation, explicit stop, and the existing watchdog tests (8 tests, 0 failures).
  • Run the retained real-engine regression alone on an audio-capable Mac: OPENCLAW_LIVE_TEST=1 swift test --package-path apps/shared/OpenClawKit --filter testLiveOldCancellationDoesNotStopReplacement. It still requires successful replacement completion, exactly one start callback, and cancellation of A. After opt-in, speech errors are failures, not skips.
  • Live-audio test is explicitly opt-in: later parallel/rapid lifecycle runs timed out, and the isolated iOS simulator host reported AudioQueue -66680 / unavailable default audio I/O. Do not make headless CI depend on working speech output, extend timeouts, or replace the assertions with a mock. Default CI compiles the regression but intentionally skips its live execution.
  • Physical iPhone was detected, but SwiftPM tool-hosted tests cannot run directly on device. A separate isolated application-host attempt was blocked by missing Foundation development provisioning; no physical-device test is claimed. The simulator host used the exact owner and test source, but failed on the audio-service error above. No visual UI changes; screenshots would not prove this audio ownership race.
  • Independent owner/history review and isolated Codex autoreview: no accepted/actionable finding. Read iOS Talk and spoken-chat-push callers, macOS Talk, sibling buffered-audio lifecycle, watchdog/delegate ownership, and Apple's cancellation-handler and AVSpeech stop contracts.
  • Provenance: the unconditional cancellation stop exists in f86772f26ce625314324abba0c7c715913593fc9, authored and committed by Peter Steinberger on December 30, 2025, and in stable v2026.7.1-2. The later delegate repair fix(ios): guard talk TTS callbacks to active utterance #33304 did not introduce it.

Changed-surface gate passed: env -u OPENCLAW_TESTBOX PATH="$PWD/.build/swift-tools:$PATH" node scripts/check-changed.mjs -- apps/shared/OpenClawKit/Sources/OpenClawKit/TalkSystemSpeechSynthesizer.swift apps/shared/OpenClawKit/Tests/OpenClawKitTests/TalkSystemSpeechSynthesizerTests.swift. This included Swift lint, repository guards, and 502 passing tests across seven macOS CI shards. Default focused Swift tests also passed with exactly one intentional live-only skip.

Exact-head hosted CI run 33039448772 passed on attempt 1 for d97573868434e98da265e5414c142220450067ca, including macOS Swift, iOS build/lifecycle tests, and the iPhone/Watch and iPad screenshot pipeline. Broader native silent-audio reports remain open; this change does not prove their cause.

Revalidate the speech operation token before delayed cancellation cleanup stops the shared Apple synthesizer. Preserve active cancellation and explicit stop, and retain an opt-in real-audio regression for the replacement race. Fixes #130674.
@steipete steipete self-assigned this Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 27, 2026
@steipete
steipete marked this pull request as ready for review August 27, 2026 04:27
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 12:33 AM ET / 04:33 UTC.

ClawSweeper review

What this changes

The PR revalidates the shared Apple speech request token before delayed cancellation stops the synthesizer and adds an opt-in real-engine regression test.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. Current main retains the unguarded delayed cancellation cleanup, while this focused shared-owner repair addresses the reproduced replacement-speech race; the member-authored, maintainer-labeled PR requires maintainer handling rather than automated closure.

Priority: P1
Reviewed head: d97573868434e98da265e5414c142220450067ca
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A narrowly scoped owner-boundary fix with documented real-engine regression evidence and no actionable patch defect found.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body supplies a real AVSpeechSynthesizer before/after run, an opt-in exact regression command, and an observed passing replacement result.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body supplies a real AVSpeechSynthesizer before/after run, an opt-in exact regression command, and an observed passing replacement result.
Evidence reviewed 6 items Current-main defect: The base revision’s cancellation handler hops to the main actor and unconditionally calls stop, so it can act after a replacement has taken ownership.
Owner-boundary repair: The PR guards the delayed stop with the captured request token, matching the watchdog’s ownership check while retaining explicit stop behavior.
Caller and sibling coverage: The same owner is called by iOS Talk, iOS incremental system-voice fallback, macOS Talk, and iOS spoken chat pushes; the unrelated chat UI and watch synthesizers retain their own lifecycle owners.
Findings None None.
Security None None.

Live Verification

Command: OPENCLAW_LIVE_TEST=1 swift test --package-path apps/shared/OpenClawKit --filter testLiveOldCancellationDoesNotStopReplacement

Result: FAIL (failed) — step 1 run OPENCLAW_LIVE_TEST=1 swift test --package-path apps/shared/OpenClawKit --filter testLiveOldCancellationDoesNotStopReplacement: previous terminal command was still running after 30 seconds: "OPENCLAW_LIVE_TEST=1 swift test --package-path apps/shared/OpenClawKit --filter testLiveOldCancellationDoesNotStopReplacement"

Fetching https://github.com/mgriebling/SwiftMath
Fetching https://github.com/swiftlang/swift-markdown
Fetching https://github.com/groue/GRDB.swift.git
Fetched https://github.com/swiftlang/swift-markdown from cache (0.64s)
Fetched https://github.com/mgriebling/SwiftMath from cache (0.65s)
Fetching https://github.com/steipete/ElevenLabsKit
Fetched https://github.com/steipete/ElevenLabsKit from cache (0.27s)
Fetched https://github.com/groue/GRDB.swift.git from cache (9.93s)
Computing version for https://github.com/swiftlang/swift-markdown
Computed https://github.com/swiftlang/swift-markdown at 0.8.0 (14.43s)
Fetching https://github.com/swiftlang/swift-cmark.git
Fetched https://github.com/swiftlang/swift-cmark.git from cache (0.83s)
Computing version for https://github.com/mgriebling/SwiftMath
Computed https://github.com/mgriebling/SwiftMath at 1.7.3 (2.02s)
Computing version for https://github.com/groue/GRDB.swift.git
Computed https://github.com/groue/GRDB.swift.git at 7.11.1 (0.31s)
Computing version for https://github.com/steipete/ElevenLabsKit
Computed https://github.com/steipete/ElevenLabsKit at 0.1.1 (0.18s)
Computing version for https://github.com/swiftlang/swift-cmark.git
Computed https://github.com/swiftlang/swift-cmark.git at 0.8.0 (0.22s)
Creating working copy for https://github.com/mgriebling/SwiftMath
Working copy of https://github.com/mgriebling/SwiftMath resolved at 1.7.3
Creating working copy for https://github.com/swiftlang/swift-cmark.git
Working copy of https://github.com/swiftlang/swift-cmark.git resolved at 0.8.0
Creating working copy for https://github.com/steipete/ElevenLabsKit
Working copy of https://github.com/steipete/ElevenLabsKit resolved at 0.1.1
Creating working copy for https://github.com/swiftlang/swift-markdown
Working copy of https://github.com/swiftlang/swift-markdown resolved at 0.8.0
Creating working copy for https://github.com/groue/GRDB.swift.git
Working copy of https://github.com/groue/GRDB.swift.git resolved at 7.11.1
Building for debugging...
[51/163] Emitting module Markdown

Assertions:

  • FAIL expect_output: 0 failures

How this fits together

iOS and macOS Talk flows, plus iOS spoken chat pushes, send system-speech requests to one shared Apple synthesizer. Cancellation, watchdogs, and speech delegate callbacks converge there, where completion or cancellation returns control to the calling flow.

flowchart LR
  A[Talk and spoken chat requests] --> B[Shared Apple speech owner]
  B --> C[Cancellation cleanup]
  C --> D{Original request still owns speech?}
  D -->|Yes| E[Stop active utterance]
  D -->|No| F[Replacement utterance continues]
  E --> G[Caller receives cancellation]
Loading

Decision needed

Question Recommendation
After exact-head native CI completes, should this protected shared-owner cancellation repair be merged? Merge after native CI: Merge when the exact-head macOS and iOS checks confirm the narrow owner-boundary repair.

Why: The PR is authored by a repository member and carries the protected maintainer label, so automated cleanup must not make the final merge decision.

Before merge

  • Resolve merge risk (P1) - Exact-head native build and test checks are still incomplete, so compilation and standard Swift-suite results for this head remain to be confirmed.
  • Resolve merge risk (P1) - The bug fix adds three production lines; the guard and its invariant comment are the minimal shared-owner expression, with no net-neutral equivalent apparent in the inspected owner.
Agent review details

Security

None.

PR surface

Other +41. Total +41 across 2 files.

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

Review metrics

Metric Value Why it matters
Production versus test delta production +3/-0; tests +39/-1 The only production growth is the ownership guard and its invariant comment; the added test covers the real shared-synthesizer race.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Merge the shared token check after exact-head native CI is green; it keeps cancellation ownership at the synthesizer rather than adding caller-specific workarounds.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Merge the shared token check after exact-head native CI is green; it keeps cancellation ownership at the synthesizer rather than adding caller-specific workarounds.

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

Yes. The linked report documents a real-engine current-main reproduction: cancel a started utterance and immediately await a replacement on the main actor; base source retains the matching unconditional stop.

Is this the best way to solve the issue?

Yes. The token guard belongs in the shared synthesizer that owns cancellation, watchdog, delegate, and replacement state, avoiding divergent caller-level fixes.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 71d4a8c3e305.

Labels

Label changes:

  • add P1: A canceled older request can silently suppress replacement system speech in active iOS and macOS Talk flows.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies a real AVSpeechSynthesizer before/after run, an opt-in exact regression command, and an observed passing replacement result.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body supplies a real AVSpeechSynthesizer before/after run, an opt-in exact regression command, and an observed passing replacement result.

Label justifications:

  • P1: A canceled older request can silently suppress replacement system speech in active iOS and macOS Talk flows.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body supplies a real AVSpeechSynthesizer before/after run, an opt-in exact regression command, and an observed passing replacement result.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies a real AVSpeechSynthesizer before/after run, an opt-in exact regression command, and an observed passing replacement result.

Evidence

What I checked:

Likely related people:

  • steipete: Peter Steinberger introduced the current shared speech-owner lineage and authored this focused repair. (role: introduced shared owner and recent area contributor; confidence: high; commits: 682ddcb28cbe, d97573868434; files: apps/shared/OpenClawKit/Sources/OpenClawKit/TalkSystemSpeechSynthesizer.swift)
  • mbelinky: This author’s merged callback-identity repair covers the same synthesizer lifecycle boundary but a distinct stale-delegate path. (role: related lifecycle repair author; confidence: medium; commits: 22e33ddda9d1; files: apps/shared/OpenClawKit/Sources/OpenClawKit/TalkSystemSpeechSynthesizer.swift)

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Ready to land the shared-owner repair at d97573868434e98da265e5414c142220450067ca.

The exact-head CI run 33039448772 passed on attempt 1, including macOS Swift, iOS build/lifecycle tests, and the iPhone/Watch and iPad screenshot pipeline. Local changed-surface validation passed Swift lint, repository guards, and 502 tests across seven shards:

env -u OPENCLAW_TESTBOX PATH="$PWD/.build/swift-tools:$PATH" node scripts/check-changed.mjs -- apps/shared/OpenClawKit/Sources/OpenClawKit/TalkSystemSpeechSynthesizer.swift apps/shared/OpenClawKit/Tests/OpenClawKitTests/TalkSystemSpeechSynthesizerTests.swift
swift test --parallel --package-path apps/shared/OpenClawKit --filter TalkSystemSpeechSynthesizerTests
OPENCLAW_LIVE_TEST=1 swift test --package-path apps/shared/OpenClawKit --filter testLiveOldCancellationDoesNotStopReplacement

Default Swift result: five passing watchdog tests and one intentional live-audio skip. Separately enabled final live regression: one pass, zero failures, replacement started once and completed; the first task was cancelled. The pre-fix retained regression failed on replacement, and earlier real-engine coverage also verified current cancellation and explicit stop.

Reviewed the latest ClawSweeper feedback: no actionable findings or additional Rank-up moves. Its displayed live-verification failure is a 30-second harness cutoff while dependencies/build were still running, not a test failure; the completed local invocation above is the actual test result. The +3 production lines are the minimal existing-token ownership check plus its invariant comment; public stop remains unconditional, and no state or fallback is added. Tests are +39/-1. Independent review and isolated Codex autoreview found no accepted/actionable issue.

Known limits remain explicit: physical-iPhone test provisioning was unavailable; the isolated local simulator audio proof failed with unavailable audio I/O. The final real-engine regression passed on macOS, and normal CI intentionally does not require live speech output. This fixes #130674 only; broader silent-audio/CarPlay reports remain open.

@steipete
steipete merged commit 617ad7d into main Aug 27, 2026
138 checks passed
@steipete
steipete deleted the codex/apple-speech-cancellation-owner branch August 27, 2026 04:57
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 27, 2026
…-retirement-v13

* origin/main: (243 commits)
  fix: preserve Gateway error reasons in text logs (#130645)
  refactor(video): deduplicate generation contracts (#130635)
  fix(agents): preserve direct-message sender identity (#124548)
  fix(agents): preserve silent reply after settled tools (#130675)
  fix(talk): preserve replacement speech when an old utterance is canceled (#130687)
  fix(browser): preserve literal names and formatter-owned snapshot refs (#130599)
  fix(auth): reset only the profile replaced by a successful login (#124014)
  fix: bind session creation to admitted Gateway (#130686)
  refactor(qa-lab): reuse model reference splitter (#130317)
  docs(gateway): clarify independent HTTP endpoint switches (#130690)
  fix(ui): Control UI smooth scrolling ignores the reduced-motion preference (#130428)
  refactor(lmstudio): remove unreachable catalog merge (#130689)
  fix(crabbox): restore cloud machine CPU and RAM (#130684)
  fix(secrets): compare proxy bearer tokens directly (#127054)
  fix(matrix): show recovery key availability in text status (#128051)
  fix(ios): restore approval settings navigation and remove duplicate shell state (#130651)
  refactor(agents): use fixed tool-loop defaults directly (#130681)
  refactor(qa-lab): share process tree metric reader (#130419)
  refactor(models): simplify prepared owner access (#130683)
  fix(parallels): main install and update smoke cannot complete (#130658)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…led (openclaw#130687)

Revalidate the speech operation token before delayed cancellation cleanup stops the shared Apple synthesizer. Preserve active cancellation and explicit stop, and retain an opt-in real-audio regression for the replacement race. Fixes openclaw#130674.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS 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.

Apple system speech cancellation can stop a replacement utterance

1 participant