openclaw - ✅(Solved) Fix Embedded websocket stream falls back to HTTP after 500 during WS setup [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#56826Fetched 2026-04-08 01:47:23
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
cross-referenced ×2subscribed ×2

On a current OpenClaw stable install, embedded session websocket streaming repeatedly fails with HTTP 500 during connection setup, but the client falls back to HTTP and continues functioning.

Core gateway behavior, channel delivery, and watcher processes remain operational.

Error Message

Repeated log warnings of the form:

Root Cause

On a current OpenClaw stable install, embedded session websocket streaming repeatedly fails with HTTP 500 during connection setup, but the client falls back to HTTP and continues functioning.

Core gateway behavior, channel delivery, and watcher processes remain operational.

Fix Action

Fixed

PR fix notes

PR #55535: fix: keep openai-codex on HTTP responses transport

Description (problem / solution / changelog)

Summary

  • keep openai-codex on its existing HTTP responses path instead of routing it into the generic OpenAI websocket transport selector
  • update the websocket transport selector test to explicitly reject the openai-codex / openai-codex-responses pair

Change Type

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Docs
  • Test-only

Scope

This PR is intentionally narrow.

It only changes websocket transport eligibility for openai-codex on the embedded runner path.

It does not change:

  • the openai-codex provider normalization logic
  • HTTP request payload behavior for Codex
  • any image/media-understanding routing
  • any memory provider routing

Linked Issue/PR

  • Related #55523
  • Related #56826
  • Related #56881
  • Follow-up to merged PR #53702
  • This PR fixes a bug or regression

Root Cause / Regression History

openai-codex models normalize to the ChatGPT backend HTTP path (https://chatgpt.com/backend-api) and use openai-codex-responses.

After #53702, the embedded runner's websocket eligibility selector also treated the openai-codex / openai-codex-responses pair as websocket-eligible. However, the websocket connection manager still targets the generic OpenAI Responses websocket endpoint rather than a Codex-specific transport target.

In isolated upstream-main smoke testing, that caused openai-codex requests to attempt websocket first, fail with HTTP 500, and then fall back to HTTP.

This patch keeps openai-codex on the existing HTTP path until there is a verified provider-specific websocket target and end-to-end support for it.

Behavior Changes

Before:

  • openai-codex / openai-codex-responses entered the generic OpenAI websocket selector
  • websocket could fail and fall back to HTTP in isolated smoke tests

After:

  • only native openai / openai-responses is websocket-eligible
  • openai-codex stays on HTTP responses transport

Regression Test Plan

Updated:

  • src/agents/pi-embedded-runner/run/attempt.spawn-workspace.websocket.test.ts

Coverage:

  • accepts the native openai / openai-responses websocket pair
  • rejects openai-codex / openai-codex-responses
  • rejects mismatched provider/API websocket pairs

Repro + Verification

Observed on merged upstream/main during isolated smoke validation of #53702:

  • openai-codex/gpt-5.4 requests succeeded, but only after websocket failed and the runner fell back to HTTP
  • gateway log showed websocket connect failure with HTTP 500 before fallback

With this patch:

  • the websocket selector no longer routes openai-codex into the generic OpenAI websocket path
  • focused websocket selector test passes locally

Tests

Passed locally:

  • corepack pnpm test -- src/agents/pi-embedded-runner/run/attempt.spawn-workspace.websocket.test.ts --reporter=verbose
  • pre-commit pnpm check passed during commit

Risks and Mitigations

Risk:

  • if openai-codex later gets a valid provider-specific websocket endpoint, this patch will keep it on HTTP until that support is added explicitly

Mitigation:

  • this preserves the existing working HTTP transport and avoids the currently observed websocket->HTTP fallback path
  • the selector remains a small, centralized surface to expand later once Codex websocket support is verified end-to-end

AI assistance

AI-assisted: drafted and implemented with Codex, then locally reviewed and tested by me.

Changed files

  • src/agents/pi-embedded-runner/run/attempt.spawn-workspace.websocket.test.ts (modified, +6/-9)
  • src/agents/pi-embedded-runner/run/attempt.thread-helpers.ts (modified, +4/-4)

Code Example

[ws-stream] WebSocket connect failed for session=<redacted>; falling back to HTTP. error=Error: Unexpected server response: 500
RAW_BUFFERClick to expand / collapse

Summary

On a current OpenClaw stable install, embedded session websocket streaming repeatedly fails with HTTP 500 during connection setup, but the client falls back to HTTP and continues functioning.

Core gateway behavior, channel delivery, and watcher processes remain operational.

Observed behavior

Repeated log warnings of the form:

[ws-stream] WebSocket connect failed for session=<redacted>; falling back to HTTP. error=Error: Unexpected server response: 500

After fallback:

  • normal assistant behavior continues
  • message delivery still succeeds
  • Gmail watcher still starts and runs
  • gateway status remains healthy

Impact

  • No obvious outage of core assistant functionality
  • Likely degraded embedded-session streaming behavior
  • Repeated warning noise in logs
  • Suggests websocket transport path is broken while HTTP fallback still works

Environment

  • OpenClaw stable 2026.3.28
  • macOS 15.5
  • Node 22.22.1
  • local loopback gateway
  • LaunchAgent-managed gateway service

What was ruled out

  • not a general gateway outage
  • not an auth failure
  • not an iMessage failure
  • not a Gmail watcher failure
  • not limited to a single stale session after restart

Why that matters

Before restart, all websocket failures were tied to one embedded session id. After a clean gateway restart, websocket failures reappeared with a new session id as well.

That suggests this is not only stale in-memory state from one bad session.

Expected behavior

Embedded session websocket streaming should connect successfully without returning HTTP 500.

Actual behavior

Websocket setup returns HTTP 500, then the client falls back to HTTP and continues.

Possible areas to inspect

  • embedded ws-stream route / upgrade handler regression
  • mismatch between embedded session stream client and gateway websocket endpoint
  • websocket auth / handshake path returning 500 while HTTP fallback path still works
  • session replay / embedded session state handling after restart or update

extent analysis

Fix Plan

The fix involves updating the websocket endpoint to handle authentication and handshake correctly.

  • Update the websocket endpoint to use the correct authentication mechanism:
// Update the websocket endpoint to use the correct authentication mechanism
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });

wss.on('connection', (ws, req) => {
  // Authenticate the client
  const authToken = req.headers['auth-token'];
  if (!authToken) {
    ws.close(1008, 'Authentication failed');
    return;
  }
  // Handle the websocket connection
  ws.on('message', (message) => {
    console.log(`Received message: ${message}`);
  });
});
  • Ensure the client is sending the correct authentication token:
// Ensure the client is sending the correct authentication token
const ws = new WebSocket('ws://localhost:8080', {
  headers: {
    'Auth-Token': 'your-auth-token',
  },
});
  • Verify the websocket connection is established successfully:
// Verify the websocket connection is established successfully
ws.on('open', () => {
  console.log('Websocket connection established');
});

Verification

To verify the fix, check the logs for any errors related to websocket connections. Also, test the websocket connection using a tool like wscat:

wscat -c ws://localhost:8080

If the connection is established successfully, you should see a message indicating that the connection is open.

Extra Tips

  • Ensure that the websocket endpoint is configured to handle errors correctly.
  • Use a library like ws to handle websocket connections, as it provides a simple and efficient way to establish and manage connections.
  • Consider implementing additional logging and monitoring to detect any issues with the websocket connection.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Embedded session websocket streaming should connect successfully without returning HTTP 500.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Embedded websocket stream falls back to HTTP after 500 during WS setup [1 pull requests, 1 participants]