-
-
Notifications
You must be signed in to change notification settings - Fork 386
fix(stream-gate): accept Responses WebSocket prewarm terminals #1437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,7 @@ import { | |
| peekDeferredStreamingFinalization, | ||
| } from "./stream-finalization"; | ||
| import { mapProviderTypeToFamily } from "./stream-gate/frame-classifier"; | ||
| import { getStreamGateResponsePolicy } from "./stream-gate/response-policy"; | ||
| import { createShadowGateObserver, resolveStreamGateMode } from "./stream-gate/stream-content-gate"; | ||
| import { | ||
| createStreamProtocolObserver, | ||
|
|
@@ -3567,6 +3568,7 @@ export class ProxyResponseHandler { | |
| family, | ||
| providerId: provider.id, | ||
| providerName: provider.name, | ||
| allowTerminalOnlyCommit: getStreamGateResponsePolicy(response)?.allowTerminalOnlyCommit, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: 定位 ResponseFixer.process 实现,确认其是否为 openai-responses 流创建新的 Response 对象。
set -euo pipefail
fd -i responsefixer src
rg -n 'class ResponseFixer' -A 10 src
rg -n 'static async process' -A 40 src/app/v1/_lib/proxy/response-fixer* 2>/dev/null
rg -n 'new Response\(' src/app/v1/_lib/proxy/response-fixer* 2>/dev/nullRepository: ding113/claude-code-hub Length of output: 7222 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- response-fixer implementation ---'
cat -n src/app/v1/_lib/proxy/response-fixer/index.ts | sed -n '320,480p'
printf '%s\n' '--- policy helpers and inheritance calls ---'
rg -n 'getStreamGateResponsePolicy|inheritStreamGateResponsePolicy|allowTerminalOnlyCommit' src/app/v1/_lib/proxy src/app/v1/_lib/proxy/response-handler.ts
printf '%s\n' '--- dispatch call path ---'
rg -n 'ResponseFixer\.process|handleStream\(' src/app/v1/_lib/proxy/response-handler.ts -A 8 -B 8Repository: ding113/claude-code-hub Length of output: 11081 🏁 Script executed: #!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
fixer = Path("src/app/v1/_lib/proxy/response-fixer/index.ts").read_text()
handler = Path("src/app/v1/_lib/proxy/response-handler.ts").read_text()
policy = Path("src/app/v1/_lib/proxy/stream-gate/response-policy.ts").read_text()
stream_start = fixer.index("private static processStream(")
stream_end = fixer.index("\n private static buildFixersApplied(", stream_start)
stream_body = fixer[stream_start:stream_end]
checks = {
"processStream creates a new Response": "return new Response(" in stream_body,
"processStream does not inherit stream policy": "inheritStreamGateResponsePolicy" not in stream_body,
"dispatch passes ResponseFixer result to handleStream": (
"fixedResponse = await ResponseFixer.process(session, response);" in handler
and "return await ProxyResponseHandler.handleStream(session, fixedResponse);" in handler
),
"policy lookup uses WeakMap": "new WeakMap<Response" in policy,
}
for name, passed in checks.items():
print(f"{'PASS' if passed else 'FAIL'}: {name}")
if not all(checks.values()):
raise SystemExit(1)
PYRepository: ding113/claude-code-hub Length of output: 347 继承 ResponseFixer 生成响应的流门控策略 启用 🤖 Prompt for AI Agents |
||
| }); | ||
| })(); | ||
|
|
||
|
|
@@ -4761,6 +4763,7 @@ export class ProxyResponseHandler { | |
| family, | ||
| providerId: provider.id, | ||
| providerName: provider.name, | ||
| allowTerminalOnlyCommit: getStreamGateResponsePolicy(response)?.allowTerminalOnlyCommit, | ||
| }); | ||
| })(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| export interface StreamGateResponsePolicy { | ||
| allowTerminalOnlyCommit: boolean; | ||
| } | ||
|
|
||
| const responsePolicies = new WeakMap<Response, StreamGateResponsePolicy>(); | ||
|
|
||
| export function setStreamGateResponsePolicy( | ||
| response: Response, | ||
| policy: StreamGateResponsePolicy | ||
| ): void { | ||
| responsePolicies.set(response, policy); | ||
| } | ||
|
|
||
| export function getStreamGateResponsePolicy( | ||
| response: Response | ||
| ): StreamGateResponsePolicy | undefined { | ||
| return responsePolicies.get(response); | ||
| } | ||
|
|
||
| export function inheritStreamGateResponsePolicy(source: Response, target: Response): void { | ||
| const policy = responsePolicies.get(source); | ||
| if (policy) responsePolicies.set(target, policy); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: ding113/claude-code-hub
Length of output: 663
🏁 Script executed:
Repository: ding113/claude-code-hub
Length of output: 50379
🏁 Script executed:
Repository: ding113/claude-code-hub
Length of output: 50379
🏁 Script executed:
Repository: ding113/claude-code-hub
Length of output: 50379
不要仅根据客户端可控的
generate字段放行终止帧requestBodyJson直接来自客户端最终请求体。当前过滤逻辑不会移除generate,因此普通客户端可发送generate: false,使空流被视为成功并绕过故障转移。请改用明确的内部预热标识判断。🤖 Prompt for AI Agents