proxy: cancel upstream on streaming disconnect #36

Merged
wmc merged 1 commit from codex/streaming-disconnect-cancellation into main 2026-06-23 08:48:36 +00:00
Owner

Summary:

  • Cancel the proxy response task when the downstream socket closes, covering disconnects before upstream streaming headers arrive and while the upstream body stream is idle.
  • Send buffered and streaming responses through cancellation-aware async helpers without exposing upstream/provider error details downstream.
  • Add Network.framework socket regression tests for both cancellation windows.
  • Update TODO.md with this completed slice and a tracked follow-up for isolated test listener ports.

Verification:

  • RED: DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer xcodebuild test -project CodexModelSwitcher.xcodeproj -scheme CodexModelSwitcher -configuration Debug -destination platform=macOS -derivedDataPath /tmp/CodexModelSwitcher-DerivedData-disconnect-preheaders-red CODE_SIGNING_ALLOWED=NO -only-testing:CodexModelSwitcherTests/CompatibilityProxyServerTests/testStreamingProxyCancelsUpstreamRequestBeforeResponseHeadersWhenDownstreamDisconnects failed before the production fix with unfulfilled expectations: "upstream request is cancelled".
  • DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer xcodebuild test -project CodexModelSwitcher.xcodeproj -scheme CodexModelSwitcher -configuration Debug -destination platform=macOS -derivedDataPath /tmp/CodexModelSwitcher-DerivedData-disconnect-socket-green CODE_SIGNING_ALLOWED=NO -only-testing:CodexModelSwitcherTests/CompatibilityProxyServerTests/testStreamingProxyCancelsUpstreamRequestBeforeResponseHeadersWhenDownstreamDisconnects -only-testing:CodexModelSwitcherTests/CompatibilityProxyServerTests/testStreamingProxyCancelsIdleUpstreamStreamWhenDownstreamDisconnects
  • DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer xcodebuild test -project CodexModelSwitcher.xcodeproj -scheme CodexModelSwitcher -configuration Debug -destination platform=macOS -derivedDataPath /tmp/CodexModelSwitcher-DerivedData-disconnect-proxy-final2 CODE_SIGNING_ALLOWED=NO -only-testing:CodexModelSwitcherTests/CompatibilityProxyServerTests
  • git diff --check -- CodexModelSwitcher/CompatibilityProxyServer.swift CodexModelSwitcherTests/CompatibilityProxyServerTests.swift TODO.md
  • DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer scripts/verify.sh
  • Subagent review: no blocking issues; residual fixed-port socket-test risk tracked in TODO.md.
Summary: - Cancel the proxy response task when the downstream socket closes, covering disconnects before upstream streaming headers arrive and while the upstream body stream is idle. - Send buffered and streaming responses through cancellation-aware async helpers without exposing upstream/provider error details downstream. - Add Network.framework socket regression tests for both cancellation windows. - Update TODO.md with this completed slice and a tracked follow-up for isolated test listener ports. Verification: - RED: `DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer xcodebuild test -project CodexModelSwitcher.xcodeproj -scheme CodexModelSwitcher -configuration Debug -destination platform=macOS -derivedDataPath /tmp/CodexModelSwitcher-DerivedData-disconnect-preheaders-red CODE_SIGNING_ALLOWED=NO -only-testing:CodexModelSwitcherTests/CompatibilityProxyServerTests/testStreamingProxyCancelsUpstreamRequestBeforeResponseHeadersWhenDownstreamDisconnects` failed before the production fix with `unfulfilled expectations: "upstream request is cancelled"`. - `DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer xcodebuild test -project CodexModelSwitcher.xcodeproj -scheme CodexModelSwitcher -configuration Debug -destination platform=macOS -derivedDataPath /tmp/CodexModelSwitcher-DerivedData-disconnect-socket-green CODE_SIGNING_ALLOWED=NO -only-testing:CodexModelSwitcherTests/CompatibilityProxyServerTests/testStreamingProxyCancelsUpstreamRequestBeforeResponseHeadersWhenDownstreamDisconnects -only-testing:CodexModelSwitcherTests/CompatibilityProxyServerTests/testStreamingProxyCancelsIdleUpstreamStreamWhenDownstreamDisconnects` - `DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer xcodebuild test -project CodexModelSwitcher.xcodeproj -scheme CodexModelSwitcher -configuration Debug -destination platform=macOS -derivedDataPath /tmp/CodexModelSwitcher-DerivedData-disconnect-proxy-final2 CODE_SIGNING_ALLOWED=NO -only-testing:CodexModelSwitcherTests/CompatibilityProxyServerTests` - `git diff --check -- CodexModelSwitcher/CompatibilityProxyServer.swift CodexModelSwitcherTests/CompatibilityProxyServerTests.swift TODO.md` - `DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer scripts/verify.sh` - Subagent review: no blocking issues; residual fixed-port socket-test risk tracked in TODO.md.
wmc merged commit 00e8ee30b4 into main 2026-06-23 08:48:36 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
wmc/CodexModelSwitcher!36
No description provided.