Skip to content

fix(logs): classify web-search client aborts as 499, not upstream 502#158

Closed
Wibias wants to merge 2 commits into
lidge-jun:mainfrom
Wibias:fix/web-search-client-abort-classification
Closed

fix(logs): classify web-search client aborts as 499, not upstream 502#158
Wibias wants to merge 2 commits into
lidge-jun:mainfrom
Wibias:fix/web-search-client-abort-classification

Conversation

@Wibias

@Wibias Wibias commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Mid-stream OpenCodex web-search cancels surface as response.failed with client closed request during web-search.
  • That message was inferred as HTTP 502 / upstream_server_error with closeReason: terminal, which looked like a Kimi upstream failure.
  • Classify client-close messages as 499 / client_closed_request / closeReason: client_cancel, including a legacy remap when a 5xx log still carries that reason.
  • Preserve explicit client_cancelled JSON errors used by combo/compact paths.

This does not change Kimi itself or stop web-search sidecar behavior — it fixes log/error classification so cancels are not mistaken for provider outages.

Test plan

  • bun test tests/errors-adapter-failure.test.ts tests/request-log.test.ts tests/web-search.test.ts
  • bun test tests/server-combo-failover-e2e.test.ts -t ""connect cancellation""
  • Reproduce a cancelled web-search turn on a routed model (e.g. kimi/k3) and confirm /api/logs shows 499 + client_closed_request + client_cancel

Wibias added 2 commits July 19, 2026 10:31
Mid-stream web-search cancels were emitted as response.failed with
'client closed request during web-search', then inferred as 502 /
upstream_server_error. Map those messages to 499 client_closed_request
and client_cancel in /api/logs.
…mpact

Keep formatErrorResponse(499, client_cancelled, ...) stable while still
mapping web-search abort messages onto client_closed_request.
lidge-jun pushed a commit that referenced this pull request Jul 19, 2026
Mid-stream web-search cancels were emitted as response.failed with
'client closed request during web-search', then inferred as 502 /
upstream_server_error. Map those messages to 499 client_closed_request
and client_cancel in /api/logs.

(cherry picked from commit 57d8794)

Community PR #158 absorb; source head 67b660b.
lidge-jun pushed a commit that referenced this pull request Jul 19, 2026
…mpact

Keep formatErrorResponse(499, client_cancelled, ...) stable while still
mapping web-search abort messages onto client_closed_request.

(cherry picked from commit 67b660b)

Community PR #158 absorb; source head 67b660b.
lidge-jun added a commit that referenced this pull request Jul 19, 2026
Repairs for community PR #158 absorb (source head 67b660b), Sol review
findings:

- isClientClosedMessage no longer matches bare 'client closed' / 'client
  cancelled' substrings, which could reclassify a legitimate upstream 502
  ('upstream HTTP client closed idle connection') as a 499 client cancel.
  The matcher now covers only phrases this codebase produces: 'client closed
  request' (web-search loop), 'Client cancelled/canceled request'
  (responses.ts), and the explicit 'request cancel(l)ed by client' forms.
- Negative tests pin the narrowness: upstream closed-connection wordings stay
  502/upstream_server_error.
- Compact-path activation: bufferCompactResponse exported as the narrow seam
  and driven with a real mid-buffer AbortSignal — the 499 client_cancelled
  branch is now observed firing, not just the formatter.

Co-authored-by: Wibias <37517432+Wibias@users.noreply.github.com>
@lidge-jun

Copy link
Copy Markdown
Owner

Thanks — mid-stream web-search cancels masquerading as upstream 502s was a real logging bug, and it's landed on dev with your authorship preserved plus a maintainer repair:

  • acca0e9a / b44355f7 — your PR fix(logs): classify web-search client aborts as 499, not upstream 502 #158 commits, absorbed as-is (author: @Wibias, source head 67b660b).
  • 120a652f — maintainer repair (Co-authored-by: @Wibias) closing two review findings:
    1. the matcher accepted bare "client closed"/"client cancelled" substrings, which would reclassify a legitimate upstream 502 like "upstream HTTP client closed idle connection" as a 499 — it now matches only the abort phrases this codebase produces, with negative tests pinning the narrowness;
    2. the compact-path preservation test never drove the compact branch — bufferCompactResponse is now driven with a real mid-buffer AbortSignal and the 499 client_cancelled payload observed.

Full suite green (3,087 tests). Closing in favor of the dev-landed commits; ships with the next release.

@lidge-jun lidge-jun closed this Jul 19, 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