Repository navigation
fix(talk): isolate cancellation ownership contract - #127186
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs changes before merge. Reviewed August 23, 2026, 6:36 AM ET / 10:36 UTC. ClawSweeper reviewWhat this changesThis PR makes realtime Talk output cancellation turn-bound across the Gateway, browser, Android, and iOS clients, and frames relay audio output. Merge readinessKeep open: the previous blank-turn-ID finding remains on the exact head. A defined whitespace turn ID is normalized into the legacy omitted form, so it can cancel the active replacement output instead of being rejected. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherRealtime Talk relays provider audio and cancellation events through the Gateway to browser and mobile clients. The cancellation path must associate a client request with the exact active output turn before it stops provider output. flowchart LR
Provider[Realtime provider] --> Relay[Gateway Talk relay]
Relay --> Event[Turn-tagged audio event]
Event --> Clients[Web and mobile clients]
Clients --> Cancel[Cancellation request]
Cancel --> Validate[Turn ownership validation]
Validate --> Relay
Relay --> Output[Provider output stopped]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +260, Tests +836, Docs +2, Other +482. Total +1580 across 26 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Reject a defined blank or whitespace-only turn ID at the Gateway boundary while preserving omitted-ID legacy callers, then add protocol and handler regressions; the platform-specific client changes and generated types have no credible single-owner net-neutral substitute. Do we have a high-confidence way to reproduce the issue? Yes, from source: call Is this the best way to solve the issue? No. The turn-owned design is the right owner boundary, but it must distinguish an omitted legacy ID from a defined blank ID before it can protect replacement output. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 5e1a28bb5664. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (14 earlier review cycles; latest 8 shown)
|
a523228 to
736aa18
Compare
|
@clawsweeper re-review Exact head moved to |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
d79d803 to
59a2916
Compare
|
Maintainer decision: I accept the bounded proof gap for this landing and skip the optional composed-client / physical-client rank-up proof. I own the disconnect-durability policy and the additive SDK compatibility policy in this layer. The focused regressions and exact-head CI are deterministic evidence, not live client proof; no live browser, Android-device, or physical iOS audio claim is being made. |
|
@clawsweeper re-review Please review exact restacked head |
|
🦞👀 Re-review progress:
|
Co-authored-by: Zhilong Zheng <[email protected]>
|
@clawsweeper re-review Please review exact head |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Co-authored-by: Zhilong Zheng <[email protected]>
|
@clawsweeper re-review Please review exact head |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Merged via squash.
|
* fix(talk): isolate cancellation ownership contract Co-authored-by: Zhilong Zheng <[email protected]> * fix(talk): frame realtime relay output audio Co-authored-by: Zhilong Zheng <[email protected]> * fix(talk): confirm turn-bound provider cancellation Co-authored-by: Zhilong Zheng <[email protected]> * fix(talk): bind legacy iOS output cancellation Co-authored-by: Zhilong Zheng <[email protected]> * fix(talk): close cancellation ownership gaps Drain dynamically arriving forced-consult results before terminal completion and validate legacy iOS cancellation responses against the active lifecycle. Co-authored-by: Zhilong Zheng <[email protected]> * fix(talk): require Android output identity for cancellation Co-authored-by: Zhilong Zheng <[email protected]> * fix(talk): bind Android cancellation to action turn Co-authored-by: Zhilong Zheng <[email protected]> * test(talk): align relay checks with current main Co-authored-by: Zhilong Zheng <[email protected]> * fix(talk): fence stale iOS output clear Co-authored-by: Zhilong Zheng <[email protected]> --------- Co-authored-by: Zhilong Zheng <[email protected]>
…ayout owner Integrates this branch with openclaw#127186, which landed turn-bound cancellation ownership while this branch was open. The two changes meet in the same three places, and each place needs both contracts rather than either one. The clear boundary. Upstream completed the cancellation waiter directly from handleRealtimeTalkEvent, straight after stopRealtimePlayback(). This branch made the playout owner the only thing allowed to reach the device, so completing there would tell cancelOutput the boundary had been reached while the AudioTrack was still queued for retirement. Turn validation stays on the receiving thread, where upstream put it; the retirement is queued to the owner, and the owner completes the waiter after it has actually retired the sink. RealtimePlaybackCommand.Clear therefore carries the turn id rather than a bare Unit completion -- the waiter must be answered with the identity the clear arrived with, because cancelOutput checks it against the turn it asked to cancel, and a newer turn overwriting the field mid-flight would otherwise answer with the wrong one. The capture gate. Upstream fences capture while a cancellation is in flight; this branch opens capture during playback whenever the platform is cancelling the echo. Those answer different questions -- which turn owns the uplink, versus whose voice the microphone hears -- so the merged gate requires both, and the fence wins even when full duplex is live. Both paths that release the waiter without a retirement release it with a null identity rather than the caller's turn: owner exit, and a Clear that could not be queued. In neither case was a turn physically retired, so nothing may claim one -- answering with the matching turn would tell cancelOutput the boundary was reached and lift the capture fence over a live sink. Null fails the turn check closed and the caller closes the relay, which is the honest outcome. The un-queued path has no unit test: reaching it needs the 32-slot control headroom filled by hand, which would exercise the harness rather than the product. Harness events now carry talkEvent.turnId, which upstream requires on audio. Three tests cover the merged contract, each verified to fail against the wrong resolution: removing upstream's fence fails 2 (including upstream's own realtimeAudioFramesStreamUntilPlaybackOrCancellationStarts), and replacing the full-duplex rule with upstream's half-duplex one fails 4.
What Problem This Solves
Delayed or stale realtime Talk cancellation RPCs could cancel a replacement turn, while Web and Android clients accepted unvalidated results and could release delayed work at the wrong ownership boundary. Large provider audio callbacks also needed a canonical browser-event framing boundary.
Later exact-head review exposed connected owner failures:
response.createdrequired a pre-existing Talk turn, so pre-audio and supported ID-less xAI responses failed visibly;clearevents ignored turn ownership and could stop replacement output.Why This Change Was Made
This establishes one turn-owned cancellation and drain contract across the Gateway, protocol, Web relay, Android relay, and legacy iOS adapter.
The first unowned
response.createdclaims the canonical Talk turn and binds exact-response or turn-bound ownership. Exact-response cancellation requires its matching response ID; the first provider terminal confirms turn-bound cancellation. Tool-result drain does not impersonate provider confirmation, while the one-second close fallback remains.Forced-consult dynamic native calls are rescanned after each successful wave until the current owner has no pending work. The legacy iOS client decodes the typed cancellation result, validates
ok, status, and optional exact turn identity, and fences failure recovery by lifecycle generation. Android requires a nonblank active output turn and snapshots the normalized turn and relay identity synchronously at the stop or push-to-talk action boundary before later asynchronous work. The legacy iOS relay accepts a non-emptyclearidentity only when it matches the active output turn; missing identity retains legacy behavior.The Gateway also splits normalized PCM output into ordered 20 ms frames of at most 960 bytes while preserving turn, item, response, and byte-order identity, including a trailing partial frame.
User Impact
Realtime Talk cancellation remains additive and legacy-compatible as
{ ok: true, status?, turnId? }. Matching and legacy cancellation applies normally,staleandidleare harmless races, and malformed or rejected responses fail closed. Provider output may start before browser microphone audio, ID-less cancellation can recover on the same relay, forced-consult terminal completion waits for all current async result waves, stale iOS cancellation failure cannot close a replacement lifecycle, Android never sends an unbound output cancellation, and a delayed clear for turn A cannot stop replacement output for turn B.Exact Artifact
69ae91878397f21c7ff79d9aecb6d7b449a6828887665fab10162bb87430d3c1106d3c6c3fa6110b36eb0384520403ad20a04b63cada1a16db6adb5553b33b5c2f7a2807ed080044138fb89facaf80a2e83e27be9621f47afdd3fd1a08c9b47c10a5233ed0452accf0332c8b9f440c56a29241318e9769e1ed578d6363c555146e5b8f09c25090a16f80256250f2a0d9d093e21254061030Codex Contract
Direct sibling source inspection at
openai/codexa196bbb64b1605a458c2531c47b6confirms thatturn.interruptcarries both thread and turn IDs. An emptyturnIdis reserved for startup interruption and is acknowledged after submission; a non-emptyturnIdis validated against the active turn and completes afterTurnAborted(codex-rs/app-server-protocol/src/protocol/v2/turn.rs:208-216,codex-rs/app-server/src/request_processors/turn_processor.rs:1351-1413). OpenClaw cancellation remains bound to the current Talk output turn; this PR does not claim that Codex startup interrupts require a turn identity.Evidence
response.created, cancellation, queued replacement audio,onResponseDone({ status: "cancelled" }), thenresponse.done.Unknown realtime relay session; restored code passed the targeted regression in both Gateway projects and the focused relay file passed172/172.native-3escaped; the repaired targeted regression passed in both Gateway projects.ok:false, unknown status, turn mismatch, request failure, legacy, applied, stale, idle, and failure after stop.clearignored turn identity. The new table regression sends stale clear A after replacement B and then matching clear B; the source now ignores only non-empty mismatched IDs and preserves legacy unscoped clear. Local Xcode 26.6 repeatedly timed out inCreateBuildDescriptionbefore compiling, so hosted exact-head iOS/required CI is the explicit execution-proof substitute; no local simulator pass is claimed.stopTtsreread replacement state and left the prior clear waiter active. The repaired path preserves local stop, binds the later RPC to the turn owned when the action began, passed the targeted mutation proof, the completeTalkModeManagerTestsuite passed56/56, and app ktlint passed.git diff --check, scoped iOS SwiftLint, protocol schema/registry, Web relay, and type checks are clean. Fresh terminal autoreview is clean.Scope And LOC
Raw reconciliation against the exact stack base:
+517/-162+1289/-98+29/-0+4/-2+4/-1This layer changes no native source inventory, locale JSON, or Apple
.xcstrings. Any repository-wide native-i18n baseline movement is inherited and is not claimed as an exact-head regeneration.Stack And Credit
This PR intentionally remains draft.