Commit a245761
authored
## Summary
Fix #180 (implementation of #167): give users an actionable diagnostic
when a third-party relay (older sub2api / claude2api / anyrouter builds)
mishandles OpenAI Responses API SSE events and cuts the stream short
with no HTTP status.
## What changed
- `packages/shared/src/diagnostics.ts` — new `relayStreamingBug`
hypothesis in `diagnoseGenerateFailure()`. Triggers when:
- `wire === 'openai-responses'`
- `baseUrl` host is **not** `*.openai.com`
- No HTTP status is attached (transport-level failure, not a 4xx/5xx)
- Message matches a truncated-stream shape: `stream ended`, `premature
close`, `terminated`, `ECONNRESET`, `aborted`
- `packages/i18n/src/locales/en.json` + `zh-CN.json` —
`diagnostics.cause.relayStreamingBug` +
`diagnostics.fix.relayStreamingBug`.
- `packages/shared/src/diagnostics.test.ts` — 6 new tests covering
positive + negative cases:
- openai-responses + custom baseUrl + "terminated" → triggers
- openai-responses + `api.openai.com` + "terminated" → does NOT trigger
(official endpoint isn't the culprit)
- openai-responses + custom baseUrl + 500 status → does NOT trigger
(routes to `serverError`)
- anthropic wire + "terminated" → does NOT trigger (wrong wire)
- "premature close" + "ECONNRESET" message shapes both matched
Detection signal used: **(b)** from the task spec — pattern-matching on
baseUrl + wire + message, since the existing error path
(`packages/providers/src/codex/client.ts`, `retry.ts`) does not yet
attach a "stream closed without response.completed" context field.
## Stacked on #165
This PR builds on the `diagnoseGenerateFailure()` function introduced in
#165 (branch `worktree-agent-a75d65c7`). **Merge #165 first**, then this
PR. Rebasing onto main after #165 lands will be a no-op.
## Four-principle check
- Compatibility: green — pure addition, no signature changes
- Upgradeability: green — hypothesis code-path is additive, falls
through to existing `serverError` / `unknown` when signals don't match
- No bloat: green — ~25 LOC + 2 i18n strings per locale
- Elegance: green — same shape as existing hypotheses, reuses the
DiagnosticHypothesis surface
## Test plan
- [x] `pnpm --filter @open-codesign/shared test` — 174 passed (8 files)
- [x] `pnpm typecheck` — 10 packages green
- [x] `pnpm lint` — biome clean (360 files)
- [ ] Manual: reproduce with a gateway that truncates `response.*` SSE
events, confirm the diagnostic panel renders the new cause + fix strings
Refs #167, closes #180.
Signed-off-by: hqhq1025 <1506751656@qq.com>
1 parent 022e1b6 commit a245761
4 files changed
Lines changed: 111 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
785 | 785 | | |
786 | 786 | | |
787 | 787 | | |
| 788 | + | |
788 | 789 | | |
789 | 790 | | |
790 | 791 | | |
| |||
798 | 799 | | |
799 | 800 | | |
800 | 801 | | |
801 | | - | |
| 802 | + | |
| 803 | + | |
802 | 804 | | |
803 | 805 | | |
804 | 806 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
781 | 781 | | |
782 | 782 | | |
783 | 783 | | |
| 784 | + | |
784 | 785 | | |
785 | 786 | | |
786 | 787 | | |
| |||
794 | 795 | | |
795 | 796 | | |
796 | 797 | | |
797 | | - | |
| 798 | + | |
| 799 | + | |
798 | 800 | | |
799 | 801 | | |
800 | 802 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
194 | 259 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
| 177 | + | |
| 178 | + | |
177 | 179 | | |
178 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
179 | 202 | | |
180 | 203 | | |
181 | 204 | | |
182 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
183 | 223 | | |
184 | 224 | | |
185 | 225 | | |
| |||
0 commit comments