Skip to content

Add active upstream WebSocket ping and request compatibility filtering - #4

Merged
PenguinDOOM merged 3 commits into
future/first-writefrom
agent/active-websocket-ping
Jul 31, 2026
Merged

Add active upstream WebSocket ping and request compatibility filtering#4
PenguinDOOM merged 3 commits into
future/first-writefrom
agent/active-websocket-ping

Conversation

@PenguinDOOM

@PenguinDOOM PenguinDOOM commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • add periodic client-initiated WebSocket Ping frames for upstream connections
  • keep existing error handling on Ping send failure
  • add debug logging for sent Ping and received Pong
  • strip VS Code's unsupported prompt_cache_options field before forwarding requests to the Codex backend
  • cover active Ping behavior and compatibility filtering with unit tests

Motivation

Some proxies, NAT devices, and firewalls close idle WebSocket connections. Periodic Ping frames help keep long-lived upstream connections alive without changing the existing reconnect behavior.

VS Code may also include prompt_cache_options in Responses requests, but the Codex backend does not accept that field. Threadline now removes it through the existing unsupported-field normalization shared by initial requests and follow-up tool-output requests.

Notes

  • Ping interval: 30 seconds
  • No Pong timeout is introduced in this PR (Codex-compatible behavior)
  • Existing handling of server Ping/Pong remains unchanged
  • prompt_cache_options is removed only from the upstream payload; all other request fields remain unchanged

Validation

  • cargo test
  • Long-running VS Code/Codex session verification

@codacy-production

codacy-production Bot commented Jul 30, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 6 complexity · -1 duplication

Metric Results
Complexity 6
Duplication -1

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@PenguinDOOM PenguinDOOM changed the title Add active upstream WebSocket ping Add active upstream WebSocket ping and request compatibility filtering Jul 31, 2026
- Format the ping timer initialization consistently
@PenguinDOOM PenguinDOOM self-assigned this Jul 31, 2026
@PenguinDOOM PenguinDOOM added the enhancement New feature or request label Jul 31, 2026
@PenguinDOOM
PenguinDOOM marked this pull request as ready for review July 31, 2026 07:29
Copilot AI review requested due to automatic review settings July 31, 2026 07:29

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

The PR successfully implements the core requirements for WebSocket heartbeats and Codex compatibility filtering, and the changes are overall up to standards. However, while the implementation includes logic to handle Ping failures, there is no automated verification for these error paths or the processing of Pong frames.

A significant robustness gap was identified: the current implementation lacks a heartbeat timeout. Without checking for activity or Pong responses, the pump may remain active on a 'half-open' connection where the upstream is unresponsive but the TCP socket has not yet closed. It is recommended to implement a timeout and switch the timer behavior to prevent cumulative drift.

About this PR

  • The unit tests focus primarily on the happy path. Error paths related to WebSocket transmission failures and the logic for processing received Pong frames remain untested.

Test suggestions

  • Verify 'prompt_cache_options' is filtered out of initial response.create payloads.
  • Verify 'prompt_cache_options' is filtered out of follow-up tool output payloads.
  • Verify the WebSocket pump sends a Ping frame after the configured interval.
  • Verify the WebSocket pump terminates the connection if sending a Ping fails.
  • Verify that receiving a Pong frame is correctly processed (logged).
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify the WebSocket pump terminates the connection if sending a Ping fails.
2. Verify that receiving a Pong frame is correctly processed (logged).

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

Comment thread src/ws_pump.rs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves upstream connection stability and request compatibility in Threadline’s bridge between VS Code BYOK /v1/responses traffic and the Codex backend WebSocket protocol by (1) actively keeping retained upstream WebSockets alive with periodic client-initiated Ping frames and (2) normalizing outgoing response.create payloads by stripping a VS Code field that Codex does not accept.

Changes:

  • Add a 30s periodic upstream WebSocket Ping in the pump loop, plus debug logging for sent Ping and received Pong frames.
  • Extend upstream request normalization to remove prompt_cache_options from outgoing response.create payloads (initial and follow-up tool-output requests).
  • Add unit tests covering active Ping behavior and prompt_cache_options filtering.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/ws_pump.rs Adds periodic upstream Ping keepalive behavior (with logging) and a unit test verifying a Ping is sent after the configured interval.
src/responses/upstream/original.rs Filters out prompt_cache_options via existing unsupported-field normalization and adds assertions covering both initial and follow-up payload construction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@PenguinDOOM
PenguinDOOM merged commit 04682b0 into future/first-write Jul 31, 2026
2 checks passed
@PenguinDOOM
PenguinDOOM deleted the agent/active-websocket-ping branch July 31, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants