Skip to content

fix(voice-call): shutdown no longer leaves media connections open - #116536

Merged
vincentkoc merged 8 commits into
mainfrom
fix/voice-server-stop-sockets
Jul 30, 2026
Merged

vincentkoc merged 8 commits into
mainfrom
fix/voice-server-stop-sockets

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Related: #116201

What Problem This Solves

Fixes an issue where stopping or reloading voice-call could report completion while classic media or realtime WebSocket connections were still open. Concurrent stop callers could also return before the first shutdown finished.

Why This Change Was Made

The classic and realtime handlers now own and terminate their active sockets, while webhook shutdown keeps both handlers closed through the HTTP drain barrier. Intentional shutdown takes completed-state precedence, stale stream tokens are cleared, disconnect timers are cancelled, and concurrent callers share one completion promise.

User Impact

Voice-call shutdown and reload now finish deterministically without leaving media connections or provider bridges behind. No provider, configuration, or environment-variable surface changes.

Evidence

  • Real loopback WebSocket lifecycle coverage for classic media and realtime bridges.
  • Focused post-rebase suite: 5 files, 72 tests passed.
  • Full voice-call Testbox suite: 53 files, 508 tests passed.
  • check:changed explicit voice-call path gate passed, including production/test typechecks and type-aware lint.
  • Structured autoreview: clean after resolving shutdown-barrier and timer-order findings.

@vincentkoc vincentkoc self-assigned this Jul 30, 2026
@openclaw-barnacle openclaw-barnacle Bot added channel: voice-call Channel integration: voice-call size: L maintainer Maintainer-authored PR labels Jul 30, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review July 30, 2026 19:24
@clawsweeper clawsweeper Bot added the rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. label Jul 30, 2026
@vincentkoc
vincentkoc force-pushed the fix/voice-server-stop-sockets branch from a6270f0 to 186df53 Compare July 30, 2026 19:54
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 30, 2026, 3:59 PM ET / 19:59 UTC.

ClawSweeper review

What this changes

The PR makes voice-call shutdown wait for and terminate active classic-media and realtime WebSocket connections, while concurrent stop calls share one completion promise.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep this PR open for normal maintainer review. Current main still stops the webhook server without closing the plugin-owned classic-media and realtime WebSocket handlers, while this patch adds coordinated ownership and completion barriers for those paths; no concrete correctness or security defect was found in the reviewed change.

Priority: P1
Reviewed head: 186df539fa596dc43ec18ba160cb2f0c0d9e6ed8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused on the correct lifecycle owners, includes realistic loopback WebSocket coverage, and has no supported correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The author is a repository member, so the external-contributor real-behavior-proof gate does not apply; the PR body nevertheless reports loopback WebSocket lifecycle coverage and focused voice-call validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a repository member, so the external-contributor real-behavior-proof gate does not apply; the PR body nevertheless reports loopback WebSocket lifecycle coverage and focused voice-call validation.
Evidence reviewed 5 items Current-main shutdown gap: Current main clears timers and closes only the HTTP server; it does not call a close method on the media-stream or realtime handlers, so upgraded WebSocket ownership is outside the existing stop path.
Classic media repair boundary: The patch adds a single in-flight close promise, rejects upgrades while closing, terminates tracked WebSocket clients, and waits for the webhook drain barrier.
Realtime repair boundary: The patch tracks active realtime sockets, rejects new upgrades during shutdown, and gives server-initiated socket closure completed-state semantics instead of recording a false error outcome.
Findings None None.
Security None None.

How this fits together

The voice-call plugin receives provider webhooks and upgrades media or realtime connections into provider-backed audio sessions. Runtime shutdown flows through the tunnel and webhook server, which must drain those owned connections before a reload or stop reports completion.

flowchart LR
  A[Provider webhook or reload] --> B[Voice-call runtime]
  B --> C[Webhook server]
  C --> D[Classic media handler]
  C --> E[Realtime voice handler]
  D --> F[Media and transcription sockets]
  E --> G[Realtime bridges and sockets]
  C --> H[Completed shutdown]
Loading

Before merge

  • Complete next step (P2) - The PR is authored by a repository member and carries the protected maintainer label, so the remaining action is an explicit maintainer merge decision rather than automated repair or cleanup.
Agent review details

Security

None.

PR surface

Source +124, Tests +352. Total +476 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 4 156 32 +124
Tests 5 354 2 +352
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 510 34 +476

Review metrics

Metric Value Why it matters
Shutdown ownership 4 coordinated lifecycle owners The runtime, webhook server, classic media handler, and realtime handler now share one completion boundary, which is the central invariant needed to prevent a completed reload from leaving provider connections alive.

Technical review

Best possible solution:

Land the coordinated handler-owned shutdown path after the remaining required checks complete and a voice-call owner confirms the lifecycle ordering remains the desired reload contract.

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

Yes, from source and the added loopback lifecycle tests: current main closes the HTTP server without closing the media or realtime handler-owned upgraded sockets, and the patch exercises concurrent shutdown completion and socket termination.

Is this the best way to solve the issue?

Yes. Handler-owned socket closure coordinated through the webhook drain barrier is narrower and more maintainable than trying to infer or terminate those provider connections from the runtime layer.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7ba4df67ad4b.

Labels

Label changes:

  • add P1: The patch addresses a voice-call shutdown/reload regression that can leave active media or provider bridge connections alive after the operator is told shutdown completed.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The author is a repository member, so the external-contributor real-behavior-proof gate does not apply; the PR body nevertheless reports loopback WebSocket lifecycle coverage and focused voice-call validation.

Label justifications:

  • P1: The patch addresses a voice-call shutdown/reload regression that can leave active media or provider bridge connections alive after the operator is told shutdown completed.
  • 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 author is a repository member, so the external-contributor real-behavior-proof gate does not apply; the PR body nevertheless reports loopback WebSocket lifecycle coverage and focused voice-call validation.

Evidence

What I checked:

  • Current-main shutdown gap: Current main clears timers and closes only the HTTP server; it does not call a close method on the media-stream or realtime handlers, so upgraded WebSocket ownership is outside the existing stop path. (extensions/voice-call/src/webhook.ts:15, 7ba4df67ad4b)
  • Classic media repair boundary: The patch adds a single in-flight close promise, rejects upgrades while closing, terminates tracked WebSocket clients, and waits for the webhook drain barrier. (extensions/voice-call/src/media-stream.ts:228, 186df539fa59)
  • Realtime repair boundary: The patch tracks active realtime sockets, rejects new upgrades during shutdown, and gives server-initiated socket closure completed-state semantics instead of recording a false error outcome. (extensions/voice-call/src/webhook/realtime-handler.ts:394, 186df539fa59)
  • Shutdown ordering and concurrency coverage: The PR adds loopback WebSocket lifecycle tests for classic and realtime paths plus tests that concurrent runtime and webhook stop callers share the same completion promise. (extensions/voice-call/src/webhook.shutdown.lifecycle.test.ts:9, 186df539fa59)
  • Related issue scope: The linked issue separately tracks broader realtime resource bounds; this PR addresses its terminal-close and post-close-input portion rather than the full provider-buffer and consult-queue program.

Likely related people:

  • vincentkoc: Opened the related realtime-resource report and authored the focused shutdown-lifecycle series in this PR, including the classic-media, realtime, webhook, and runtime changes. (role: voice-call lifecycle contributor; confidence: medium; commits: 29d738519706, 5ad6d79a6264, fef179cfedbd; files: extensions/voice-call/src/media-stream.ts, extensions/voice-call/src/webhook/realtime-handler.ts, extensions/voice-call/src/webhook.ts)

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.

@vincentkoc
vincentkoc merged commit 78fd4f9 into main Jul 30, 2026
102 checks passed
@vincentkoc
vincentkoc deleted the fix/voice-server-stop-sockets branch July 30, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: voice-call Channel integration: voice-call maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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