Skip to content

[Bug] Streamed adapter body timeouts lose their explicit 504 classification #8157

Closed

Description

@tackle-me

Client or integration

Codex App / streaming Responses. Reproduced offline at the adapter-error and terminal-classification boundary.

Area

Streaming / request-log failure classification

Summary

The ResponseBodyInactivityError catch in adapter-delivery.ts creates an adapter error with status: 504 and the fixed message Upstream response body stalled before completing. After the error is represented as a Responses terminal, status inference maps that message to 502 / upstream_server_error.

The explicit timeout status is lost because the later classifier recognizes words such as timeout, timed out and deadline, but not this emitted message. This conflicts with the existing classifier comment that a stall is genuinely 504.

This concerns failure classification and recorded status. An SSE response whose HTTP 200 headers are already committed cannot send a second HTTP status.

Reproduction

Save as repro-timeout.ts at the repository root and run bun repro-timeout.ts. No network or credentials are needed.

import { adapterFailureFromEvent } from './src/bridge/internal.ts';
import { httpStatusFromTerminalError } from './src/lib/errors.ts';
import { errorDetailFor } from './src/usage/error-detail.ts';
import { formatErrorResponse } from './src/bridge/errors.ts';
const message = 'Upstream response body stalled before completing';
for (const code of [undefined, 'upstream_stall_timeout']) {
  const result = adapterFailureFromEvent({
    type: 'error', status: 504, errorType: 'upstream_error', message,
    ...(code ? { code } : {}),
  });
  console.log({ suppliedCode: code ?? null, explicitStatus: result.httpStatus,
    resultingCode: result.error.code,
    terminalClassification: httpStatusFromTerminalError(result.error) });
}
console.log({ bufferedHttpStatus: formatErrorResponse(504, 'upstream_error', message).status });
for (const upstreamError of [
  'Upstream response body stalled for 1000ms', message,
]) console.log({ message: upstreamError,
  detail: errorDetailFor({ status: 504, upstreamError }).failureDetail ?? null });

Observed on unmodified 2.97.0: the catch-shaped event has explicit status 504 but terminal classification 502. Merely setting the existing timeout code does not establish that the numeric status is preserved. The original guard message yields a body_stall detail; the replacement message loses that detail.

Relevant code and expected behavior

  • src/server/responses/adapter-delivery.ts: initial, recovery and buffered body-timeout catches replace the guard's message. The streamed error has no dedicated timeout code.
  • src/lib/errors.ts: inferHttpStatusFromAdapterMessage() falls back to 502 for this text; httpStatusFromTerminalError() uses that inference.
  • src/server/request-log-terminal-status.ts: the response.failed error object is passed to httpStatusFromTerminalError() to derive the recorded terminal status.
  • src/usage/error-detail.ts: the bounded body_stall pattern recognizes the guard's original duration-bearing message, not the replacement literal.

The buffered, non-streaming catch still calls formatErrorResponse(504, ...), preserving its HTTP response status. The replacement message loses the body_stall detail there too; I have not verified that path's final usage-log status.

Please preserve the explicit timeout status through streamed-terminal handling and retain the bounded timeout detail. Reusing the existing upstream_stall_timeout identity is one option, but its persistence and status mapping need to be covered together. Keep genuine upstream 502 errors distinct. No timeout extension or replay after partial output is requested.

Version

OpenCodex 2.97.0; Bun 1.4.4.

The relevant files were compared with dev at ad6a80e5cd5cf347097dbd0572e2410f92e7604b and match.

Operating system

Windows 10 Pro, x64, build 19045.

Related work

Related to the body-inactivity guard in #4751. The older DeepSeek reports #1065, #1172 and #1176 concern a provider's former bounded-JSON transport and timeout policy. This reproduction concerns the current generic adapter error-classification chain and does not claim that an upstream request was healthy or that a provider emitted an error.

Checks

  • I searched existing issues and pull requests.
  • The reproduction contains no private request, credentials, account details or personal paths.

Activity

  1. github-actions commented on Nov 4, 2026

    @github-actions
    Contributor

    Automated translation bookkeeping — detected language: English.

  2. added
    bug
    streaming
    on Nov 4, 2026
  3. github-actions commented on Nov 4, 2026

    @github-actions
    Contributor

    Issue reopened

    The report now contains the information required by the automated check. Thanks for updating it.

  4. lidge-jun commented on Nov 6, 2026

    @lidge-jun
    Owner

    Fixed in #8200, merged into dev as 092b496.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugstreaming

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions