Skip to content

fix(voice-call): flush unmatched webhook upgrade rejects before destroy - #141315

Merged
obviyus merged 3 commits into
openclaw:mainfrom
hugenshen:fix/voice-call-webhook-upgrade-reject-flush
Sep 9, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
hugenshen:fix/voice-call-webhook-upgrade-reject-flush

Conversation

@hugenshen

@hugenshen hugenshen commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Unmatched WebSocket upgrades to the voice-call webhook server close without an HTTP response. Clients see a reset or empty connection close instead of a readable rejection. Once the server writes a rejection, it must also own socket errors during that write because Node has transferred the upgraded socket out of HTTP error handling.

Why This Change Was Made

Use the existing SDK rejection helper to flush HTTP 404, with an error guard installed first and only for unmatched upgrades. Recognized realtime and media streams retain their existing handlers and error ownership.

Replace the peer-disconnect-and-sleep test with a deterministic fault at the real server socket. A non-handling error monitor observes the actual error while the rejection write is pending. Removing only the production guard makes the same regression fail with that uncaught error. Test fixtures now validate separate, supported audio modes.

User Impact

Clients receive a readable HTTP 404 for unknown voice stream paths. Socket errors during rejection do not escape as uncaught process errors. Existing realtime, media, and ordinary webhook behavior stays intact.

Evidence

Normal Gateway/plugin startup, tested separately for realtime and classic streaming. Both configurations pass openclaw voicecall setup --json; service logs report the voice-call runtime initialized. Tests use isolated loopback networks, a mock carrier for realtime, and inert synthetic carrier settings for streaming. No real carrier request, credential, or public exposure is involved.

Redacted output from both modes:

Baseline c7cb45dfd5db:
  voicecall setup: ok=true
  unmatched upgrade: response="", closed=true

Candidate runtime 7efebf957152:
  voicecall setup: ok=true
  unmatched upgrade:
    HTTP/1.1 404 Not Found
    Connection: close
  complete headers received before closure

Before and after controls:
  recognized realtime rejection: 401
  recognized media handshake: 101
  malformed media upgrade: 400
  ordinary webhook GET: 405
  unknown HTTP path: 404

The final revision changes only tests, so the verified candidate runtime retains its actual build identity. A fresh independent validator passed 24 TCP/HTTP checks across both Gateway-started modes, including random paths, fragmented requests, repeated requests, fresh WebSocket handshake verification, and both setup commands.

Deterministic error regression:

guard present: pending-write socket-error test passed
guard removed: 1 failed test, 1 uncaught exception
Error: synthetic rejection transport failure
code: ECONNRESET
exit: 1
guard restored: tests passed

This injects a fault through Node's real destroy(error) path. It does not claim that a peer sent an operating-system reset packet. The monitors observe without handling the error.

  • 91 focused tests passed with valid single-mode fixtures; all four final transport cases passed after the typed socket-chunk correction.
  • Formatting and focused lint passed. Fresh source review found no actionable findings.
  • The previous direct-server proof and invalid dual-mode fixture are retained as failure history; the Gateway-started runs above address that review finding.
  • The first CI run found a typed-lint error in test response collection; the final revision converts the actual string-or-buffer chunk without a cast.
  • Source-only guard order and ownership requirements have separate source review. Private paths, identities, request bodies, and credentials are omitted from these excerpts.

Retains @hugenshen's original contribution and commit ancestry. AI-assisted.

@clawsweeper

clawsweeper Bot commented Sep 7, 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 channel: voice-call Channel integration: voice-call size: XS labels Sep 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 8, 2026, 9:29 PM ET / September 9, 2026, 01:29 UTC (Revision 6).

ClawSweeper review

What this changes

The voice-call webhook server returns HTTP 404 before closing unknown WebSocket upgrades, handles rejection-time socket errors, and adds transport regression coverage.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still silently closes unmatched upgrades. The earlier socket-error and regression-proof concerns are resolved, and no blocking defect remains.

Priority: P2
Reviewed head: 98170a670a4b6099fdf1cd5f904233624b380c7a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair with strong transport proof and resolved earlier findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied Gateway-started TCP traces exercise the changed webhook owner in both supported audio modes and show complete 404 headers before closure with recognized-route controls preserved. The real-server pending-write fault and guard-removal failure establish error handling; the final head changes only tests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Supplied Gateway-started TCP traces exercise the changed webhook owner in both supported audio modes and show complete 404 headers before closure with recognized-route controls preserved. The real-server pending-write fault and guard-removal failure establish error handling; the final head changes only tests.
Evidence reviewed 8 items Current main still needs the repair: The fetched main revision retains bare socket.destroy() in the unmatched upgrade branch; recognized realtime and media routes are separate.
Release behavior: The v2026.9.3 webhook router also closes unmatched upgrades without an HTTP response.
Rejection ownership and shared helper: The introduced branch installs its error listener before calling the existing helper. The helper ends the socket with the HTTP response and destroys it in the completion callback; recognized handlers retain their own ownership.
Findings None None.
Security None None.

How this fits together

The voice-call plugin runs inside the Gateway and receives carrier webhooks and audio-stream connections. Its upgrade router sends recognized streams to their handlers and rejects unknown paths.

flowchart TD
  A[Incoming WebSocket upgrade] --> B[Voice-call webhook server]
  B --> C{Recognized stream path?}
  C -->|Realtime| D[Realtime handler]
  C -->|Media| E[Media handler]
  C -->|Unknown| F[Install socket error guard]
  F --> G[Flush HTTP 404 and close]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +3, Tests +200. Total +203 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 1 200 0 +200
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 204 1 +203

Review metrics

None.

Technical review

Best possible solution:

Keep rejection handling at the unmatched-route owner, using the supported shared transport helper while preserving recognized stream handlers.

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

Yes: with a voice stream handler enabled, an upgrade to an unknown path reaches bare socket.destroy() on current main. Source inspection establishes the path; the supplied baseline TCP transcript corroborates the empty response.

Is this the best way to solve the issue?

Yes: the patch reuses the existing flush helper and supplies error ownership only where HTTP has relinquished the unmatched socket; the declared minimum host exports that helper.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 03497256f95a.

Labels

Label justifications:

  • P2: This is a bounded transport-rejection repair for unknown voice stream paths, with recognized call flows preserved.
  • 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 (terminal): Supplied Gateway-started TCP traces exercise the changed webhook owner in both supported audio modes and show complete 404 headers before closure with recognized-route controls preserved. The real-server pending-write fault and guard-removal failure establish error handling; the final head changes only tests.
  • proof: sufficient: Contributor real behavior proof is sufficient. Supplied Gateway-started TCP traces exercise the changed webhook owner in both supported audio modes and show complete 404 headers before closure with recognized-route controls preserved. The real-server pending-write fault and guard-removal failure establish error handling; the final head changes only tests.

Evidence

What I checked:

  • Current main still needs the repair: The fetched main revision retains bare socket.destroy() in the unmatched upgrade branch; recognized realtime and media routes are separate. (extensions/voice-call/src/webhook.ts:555, 03497256f95a)
  • Release behavior: The v2026.9.3 webhook router also closes unmatched upgrades without an HTTP response. (extensions/voice-call/src/webhook.ts, 1391f7cd2d40)
  • Rejection ownership and shared helper: The introduced branch installs its error listener before calling the existing helper. The helper ends the socket with the HTTP response and destroys it in the completion callback; recognized handlers retain their own ownership. (extensions/voice-call/src/webhook.ts:557, 98170a670a4b)
  • After-fix runtime evidence: The complete supplied PR body, captured under sourceRevision 95e62dcfa9bf194c3309ed8367b38d2c8d2620eb3665e0a7f9ed6279defcc524, reports normal Gateway/plugin startup in separate realtime and streaming configurations. Baseline connections returned no response; candidate runtime 7efebf9 returned complete HTTP 404 headers before closure. Controls retained realtime 401, media 101, malformed-media 400, webhook 405, and ordinary unknown-path 404 results. The recorded guard-removal experiment produced an uncaught synthetic ECONNRESET, while restoring the guard passed. These are supplied observations, not reviewer-executed tests. (7efebf957152)
  • Re-review continuity: Only webhook.upgrade.test.ts changed since the previous reviewed runtime revision. The current test waits for a pending write on the real server socket, observes errorMonitor without handling the error, and invokes destroy(error). This addresses the earlier timing-only and unobserved-error findings. (extensions/voice-call/src/webhook.upgrade.test.ts:103, 98170a670a4b)
  • Supported SDK compatibility checked: The plugin currently declares OpenClaw >=2026.9.3. That release exports plugin-sdk/websocket-runtime, and its shared rejection implementation matches the inspected helper. The nearby historical 2026.9.2 compatibility workaround therefore does not establish a supported-host regression from this import. (package.json:819, 1391f7cd2d40)

Likely related people:

  • Peter Steinberger: Raw commit 40b6339 adds src/shared/websocket-upgrade-reject.ts:30 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 40b633964178; files: src/shared/websocket-upgrade-reject.ts)
  • obviyus: 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 (5 earlier review cycles)
  • reviewed 2026-09-07T15:40:29.028Z sha dfcadf06c9de9a9738c0edf46741b8e2cecf8a49 :: blocked before merge. :: [P1] Handle socket errors before writing the unmatched-upgrade rejection
  • reviewed 2026-09-07T17:10:47.865Z sha 6e15cdf90b5ea9d3a693baf1a7e5be609ebf5083 :: needs changes before merge. :: [P2] Reach the pending rejection before resetting the peer
  • reviewed 2026-09-07T17:22:49.857Z sha 6e15cdf90b5ea9d3a693baf1a7e5be609ebf5083 :: needs changes before merge. :: [P2] Reach the pending rejection before resetting the peer
  • reviewed 2026-09-07T17:54:08.954Z sha 1b3bc6a :: blocked before merge. :: [P2] Make the rejection test exercise an actual socket error
  • reviewed 2026-09-09T01:06:45.570Z sha 7efebf9 :: needs maintainer review before merge. :: none

@hugenshen
hugenshen force-pushed the fix/voice-call-webhook-upgrade-reject-flush branch from dfcadf0 to 6e15cdf Compare September 7, 2026 17:04
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Sep 7, 2026
@hugenshen

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@hugenshen
hugenshen force-pushed the fix/voice-call-webhook-upgrade-reject-flush branch from 6e15cdf to 1b3bc6a Compare September 7, 2026 17:49
@hugenshen

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@obviyus obviyus self-assigned this Sep 9, 2026
Use the existing WebSocket rejection helper for unmatched voice upgrades and own socket errors while its response is pending. Preserve realtime and media handler ownership.

Replace the timing-based peer-disconnect test with a real-server transport fault that observes the server error without handling it. Verify HTTP 404 bytes, guard-removal failure, and recognized realtime/media routing.
@clawsweeper clawsweeper Bot added 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 9, 2026
Use valid provider configuration for each audio mode and preserve separate realtime and media handler ownership. Collect socket text through its string-or-buffer contract without a cast.

Verified normal Gateway plugin startup and TCP rejection for both modes, with the existing observed-error and guard-removal evidence retained.
@obviyus
obviyus merged commit 0b4864b into openclaw:main Sep 9, 2026
105 of 106 checks passed
@obviyus

obviyus commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks @hugenshen! Landed in 0b4864b with your contributor credit preserved.

Proof: Normal Gateway/plugin startup passed in separate realtime and streaming configurations. The PR body retains redacted before/after transport output and the deterministic socket-error regression. Exact-head CI passed, with fresh independent behavior and source reviews.

  • Bug: Unknown voice stream paths closed without an HTTP response.
  • Fix: The existing helper flushes HTTP 404, with socket-error ownership limited to the rejected upgrade.
Before After
Unmatched upgrades closed with no HTTP bytes. Both audio modes return a complete HTTP 404 before closing.
The peer-disconnect test did not prove the guard ran. A real-server pending-write fault is observed, and removing the guard causes the expected uncaught error.

Recognized realtime/media and malformed-upgrade controls retain their behavior. Validation used isolated loopback traffic and no real carrier calls or credentials. All earlier failed proof and CI attempts remain recorded separately.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 9, 2026
…w#141315)

Return HTTP 404 before closing unmatched voice WebSocket upgrades and handle socket errors while that rejection is pending. Preserve existing realtime and media handler ownership.

Replace timing-based disconnect coverage with an observed server-side transport fault and a guard-removal regression. Validate real TCP rejection, recognized upgrades, and webhook siblings.

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

channel: voice-call Channel integration: voice-call P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

2 participants