Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Closing this experiment rather than leaving a merge candidate that the operator-visible evidence does not support. The transport contract worked: all 12 prewarmed samples reused one socket, continued with
That is about 83% slower than SSE and 27% slower than the cold cached WebSocket path. The extra provider round trip costs more than the warm response state saves when OpenClaw starts it inside the active operator turn. Supported alternative: retain the direct API-key SSE default and the explicit cached-WebSocket continuation repair from #122483, without this prewarm request. Evidence that would change the decision: a real session-start window that completes warmup before prompt submission, or a server-side warmup path whose completion cost is near zero, followed by a fresh alternating A/B showing prewarmed first-text latency no longer materially worse than SSE. |
|
Follow-up research and live testing reinforce the original close decision while clarifying where WebSockets do help. OpenAI's official WebSocket guide documents Additional authenticated results on Fully hidden 1-second lead
20 sequential tool callsFour alternating workflows per lane, 21 generated Responses calls each:
Prewarm also used 30,954 input tokens versus 29,820 for plain WebSocket (+3.8%). Updated verdict:
Official references:
|
Related: #122497
Related: #122483
Caution
Negative experiment — do not merge. The authenticated latency gate failed. This draft preserves the implementation and evidence, but the direct API-key SSE default should remain unchanged and the prewarm behavior should not ship.
What Problem This Solves
Direct OpenAI Responses users who explicitly select a session-cached WebSocket transport pay the cold connection cost on the first generated turn. The experiment tests whether Codex-style handshake preconnect plus a
response.createframe withgenerate=falsecan hide that cold cost and make the cached WebSocket path competitive with the direct SSE default.Why This Change Was Made
The branch reuses the existing session-owned WebSocket cache, starts a v2 WebSocket before payload construction completes, sends a non-generating request with the stable system prompt and tools, waits for
response.completed, and lets the real request continue from that response ID. It adds no config, environment, protocol, dependency, or storage surface, and keeps direct API-key traffic on SSE by default.The implementation is intentionally isolated from normal prompt-retry admission, model-call diagnostics, idle-timeout accounting, assistant output, transcript persistence, degradation cooldown, and SSE fallback. Speculative failure closes only the candidate socket; the real request keeps the existing pre-dispatch fallback behavior.
Production LOC: +198/-11 (net +187) | Tests: +177/-2 (net +175) | Docs: +18/-8 (net +10)
User Impact
No behavior should ship from this branch. The prewarm wire contract worked, but operator-visible latency regressed materially. Keep direct API-key Responses on SSE by default and keep explicit cached WebSocket continuation from #122483 without adding this prewarm round trip.
A future attempt would need either a real idle session-start window before the operator submits a prompt or a server-side warmup whose completion cost is close to zero. Merely moving this request earlier inside the active turn is not sufficient.
Evidence
Authenticated live OpenAI A/B on this exact branch,
gpt-5.6-luna, 12 alternating samples per lane, 12,162-character stable system prefix:generate=falseprewarmThe prewarm request was accepted and continuation succeeded on every sample, so this is not a correctness or fallback failure. It is a latency failure: median first text was about 83% slower than SSE and 27% slower than a cold cached WebSocket request.
Focused regression proof:
node scripts/run-vitest.mjs packages/ai/src/transports/openai-responses-websocket.test.ts packages/ai/src/transports/openai-responses-websocket-client.test.ts src/agents/embedded-agent-runner/provider-prompt-state.test.ts src/agents/embedded-agent-runner/run/attempt.model-diagnostic-events.test.ts src/agents/embedded-agent-runner/run/llm-idle-timeout.test.tsgit diff --check: clean.oxfmtandoxlint: clean.gpt-5.6-sol, high): TruffleHog clean; no accepted/actionable findings; patch correctness 0.98. The review agreed the measured regression argues against retaining the experiment.Dependency and sibling-contract inspection:
codex-rs/core/src/client.rs: session-owned WebSocket cache, handshake-only preconnect, v2 beta header,generate=false, completion drain, and response-ID continuation.codex-rs/codex-api/src/endpoint/responses_websocket.rs: exclusive socket request lifecycle and discard-on-terminal-error behavior.ResponsesWS: constructor-time connect, connecting-state send queue, auth headers, and async iterator lifecycle.AI-assisted: yes. The implementation, upstream contract review, focused proof, authenticated live A/B, and final decision were reviewed by the maintainer.