Skip to content

fix(gateway): handle Codex WebSocket interruption and continuation - #837

Closed
zhaoxinbeizhucele wants to merge 1 commit into
tbphp:mainfrom
zhaoxinbeizhucele:review/codex-interrupt-local-20261009
Closed

zhaoxinbeizhucele wants to merge 1 commit into
tbphp:mainfrom
zhaoxinbeizhucele:review/codex-interrupt-local-20261009

Conversation

@zhaoxinbeizhucele

Copy link
Copy Markdown

关联 Issue / Related Issue

No linked issue.

变更内容 / Change Content

  • Bug 修复 / Bug fix
  • 新功能 / New feature
  • 其他改动 / Other changes

Codex clients send response.interrupt during an active Responses WebSocket generation. GPT-Load currently queues it as a create request and rejects it with invalid_protocol_request before it reaches the upstream.

This fix is limited to the Codex subscription path:

  • Handle interruption outside the create queue, validate its fields and connection/response/lane ownership, and check current authorization.
  • Forward it through the existing session wrappers, including the RPM wrapper, using CLIProxyAPI's official InterruptExecutionSession API.
  • Treat response.interrupt.failed as a nonterminal control result, allowing the original response to continue.
  • Treat response.incomplete with reason interrupted as a normal interrupted terminal, preserve the original event and usage, and permit continuation. Other incomplete reasons keep their existing handling.

The control does not create a second generation request, synthesize completion or usage, switch credentials, or replay input. Duplicate and already-finished controls are ignored. Regression tests cover target validation, forwarding during generation, upstream rejection, interrupted termination, usage and next-turn reuse.

Both Go modules upgrade the official github.com/router-for-me/CLIProxyAPI/v8 dependency from v8.0.8 to v8.0.22 for its existing interruption API. There is no personal-fork replacement or vendored core. No README, native/API-key interruption, diagnostic logging, database migration, UI or configuration changes are included.

Known limitations / draft status

This PR is a draft for review, not a claim that the candidate is ready to release:

  1. Official CPA v8.0.22 can still report terminal_empty_incomplete and invalidate the connection when interruption occurs before any output. The gateway accepts the interrupted terminal, but its mock-session test does not prove that CPA delivers this boundary successfully. The real CPA transport test covers accepted interruption after output and unsupported interruption. No separate dependency PR or fork is required by this candidate.
  2. With v8.0.22, the embedded suite's TestAntigravityExecutionOnlyBridgeConvertsDeclaredStreamingProtocols fails in four protocol subtests with empty stream output. The original v8.0.8 baseline passes; the pre-ablation v8.0.22 candidate also fails. This dependency-upgrade regression remains unresolved and needs assessment before merge.

Validation

Rechecked on the submitted commit:

go test ./internal/gateway -run '^TestWebsocketInterrupt' -count=1
go test ./internal/dialect -run '^TestOpenAIResponsesClassifiesStreamEvents$' -count=1
# in third_party/cpaembedded
go test ./embedded -run '^TestCodexWSInterruptDuringTurnAndReuse$' -count=1

Earlier validation of this same candidate passed gateway tests except the Windows-sensitive TestBufferedWriteDeadlineStopsRealTCPSlowReader, dialect/CPA execution/native session/Codex provider tests, dependency-version alignment, root and embedded go mod tidy -diff and go vet ./..., and root build. The full embedded suite has the failure described above.

Full make check, Linux acceptance and race checks have not been completed on this Windows workstation. Earlier broad checks encountered Unix path/permission assumptions and unavailable Docker/Bash tooling. The candidate has not been deployed or manually accepted; live testing of the earlier emergency implementation is not presented as acceptance of this refactor.

Manual acceptance: in a client using a Codex subscription group, interrupt after output starts, then send another message in the same session. Expect no gateway invalid_protocol_request, retained actual usage and a successful next turn. If the upstream rejects interruption, expect its control failure event followed by normal completion of the original response. Invalid or foreign response IDs/lane targets must be rejected. Before-first-output interruption remains a known dependency limitation.

自查清单 / Checklist

  • 我已运行 make check,或在说明中写明无法运行的原因和未验证范围。 / I ran make check, or documented why it could not run and what remains unverified.
  • 本 PR 范围聚焦,未包含无关改动。 / This PR is focused and contains no unrelated changes.
  • 我已更新必要的公开文档或发布说明。 / I updated any required public documentation or release notes.
    README changes are deliberately excluded from this focused bug-fix candidate; compatibility and limitations are documented here.
  • 我已确认提交、日志和测试数据不包含敏感信息。 / I confirmed that commits, logs, and fixtures contain no sensitive data.
  • 如适用,我已说明兼容性或数据迁移影响。 / Where applicable, I documented compatibility or data-migration impact.

@tbphp

tbphp commented Oct 9, 2026

Copy link
Copy Markdown
Owner

感谢详细的排查,已在 #838 修复并合并,这个 PR 就先关闭了。
同时也修复了升级 cpa 时 Antigravity 推理 tokens 重复计入的问题。

在首个输出前中断会断开连接的问题,已提交上游修复,会另行跟进。

@tbphp tbphp closed this Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants