Skip to content

fix(http): enforce streaming timeouts outside reqwest - #1858

Open
jshanson7 wants to merge 21 commits into
smg-project:mainfrom
jshanson7:codex/smg-streaming-timeout
Open

fix(http): enforce streaming timeouts outside reqwest#1858
jshanson7 wants to merge 21 commits into
smg-project:mainfrom
jshanson7:codex/smg-streaming-timeout

Conversation

@jshanson7

@jshanson7 jshanson7 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Problem

Streaming routes currently use a reqwest client configured with request_timeout_secs. Reqwest applies that timeout while reading the response body, so a long generation that hits the cap gets cut off as an incomplete chunked read instead of a controlled SMG timeout.

Fix

Use a separate worker HTTP client for streaming requests without reqwest's total body timeout, and enforce streaming deadlines in SMG instead:

  • request_timeout_secs remains the total wall-clock cap, from upstream send through body relay.
  • stream_idle_timeout_secs caps gaps between streamed chunks, defaulting to 300s.
  • Streaming error bodies and SSE error streams use the same deadlines.

Non-streaming requests still use the existing timeout-bearing client. The idle timeout is exposed as --stream-idle-timeout-secs for CLI users.

Test Plan

  • Added coverage for total vs idle streaming timeout classification.
  • Added slow chunked-response regressions for the streaming client and builder override behavior.
  • Ran focused SMG Rust checks locally; CI covers the full PR suite.

Summary by CodeRabbit

  • New Features

    • Added --stream-idle-timeout-secs (default 300) to configure the maximum idle gap between streamed chunks, including wiring into server and router behavior.
  • Bug Fixes

    • Improved streaming reliability with deadline-aware forwarding, timeout handling, and clearer SSE timeout error events.
    • Limited and deadline-bound streaming error-body reads to prevent unbounded buffering.
  • Documentation

    • Documented the new “Stream Idle Timeout” configuration option in reliability and configuration references.
  • Tests

    • Extended coverage for total-vs-idle timeout behavior, SSE event boundary detection, and preservation of the dedicated streaming client.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a configurable stream idle timeout, a shared StreamDeadline utility, separate streaming HTTP clients, and deadline-aware streaming paths across Anthropic, HTTP, and OpenAI routers.

Changes

Stream Idle Timeout Feature

Layer / File(s) Summary
Configuration and CLI wiring
model_gateway/src/config/types.rs, model_gateway/src/config/builder.rs, model_gateway/src/config/validation.rs, model_gateway/src/main.rs, docs/concepts/reliability/rate-limiting.md, docs/reference/configuration.md
Adds stream_idle_timeout_secs (default 300) to RouterConfig, a builder setter, validation rejecting 0, a CLI flag wired into config, and documentation updates.
Streaming client setup in AppContext
model_gateway/src/app_context.rs, model_gateway/src/service_discovery.rs, model_gateway/src/workflow/steps/local/drain_workers.rs
AppContext and AppContextBuilder gain a separate streaming_client built without a total body timeout; tests verify timeout vs streaming client behavior; test helpers are updated.
Shared StreamDeadline utility
model_gateway/src/routers/common/stream_timeout.rs, model_gateway/src/routers/common/mod.rs
New StreamDeadline type tracks total/idle deadlines, emits SSE timeout events, bounds futures/streams, and reads size-limited error bodies, with unit tests.
Anthropic router streaming deadline integration
model_gateway/src/routers/anthropic/context.rs, model_gateway/src/routers/anthropic/router.rs, model_gateway/src/routers/anthropic/non_streaming.rs, model_gateway/src/routers/anthropic/sse.rs, model_gateway/src/routers/anthropic/streaming.rs, model_gateway/src/routers/anthropic/worker.rs
RouterContext gains a streaming client and idle timeout; SSE consumption, passthrough, and MCP tool-loop paths enforce total/idle deadlines and handle streaming error bodies via StreamDeadline.
HTTP router and PD router streaming deadline integration
model_gateway/src/routers/http/router.rs, model_gateway/src/routers/http/pd_router.rs
Router/PDRouter add streaming_client, stream_timeout, stream_idle_timeout; multipart, typed-request, and dual-dispatch paths select clients by is_stream and enforce deadlines during send and relay.
OpenAI router streaming deadline integration
model_gateway/src/routers/openai/context.rs, model_gateway/src/routers/openai/router.rs, model_gateway/src/routers/openai/chat.rs, model_gateway/src/routers/openai/responses/streaming.rs
SharedComponents and OwnedStreamingContext gain streaming client and timeouts; chat and responses streaming paths enforce total-send and idle-chunk deadlines, including in MCP tool interception.
Multimodal and test cleanup
crates/multimodal/src/registry/llama4.rs, crates/multimodal/src/vision/processors/qwen_vl_base.rs, crates/multimodal/src/vision/transforms.rs, model_gateway/src/routers/grpc/multimodal/assemble.rs, model_gateway/src/routers/grpc/multimodal/transport.rs, model_gateway/src/worker/monitor.rs
Updates chunk iteration style in multimodal processing and trims a few test/import patterns.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

Suggested labels: tests

Suggested reviewers: CatherineSue, key4ng, claude

Poem

A rabbit hops through streams so wide,
With deadlines set on every side,
Idle chunks now dare not stall,
Timeouts catch them, one and all,
Two clients now, both swift and true —
Hop hop hooray, this build is new! 🐇⏱️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 76.77% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: moving streaming timeout enforcement out of reqwest and into application code.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added model-gateway Model gateway crate changes openai OpenAI router changes anthropic Anthropic router changes labels Jun 30, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a dedicated streaming_client alongside the standard HTTP client in AppContext and the various routers (Anthropic, HTTP, OpenAI) to handle streaming requests without a total request timeout, preventing premature timeouts during long-lived streams. Feedback suggests exposing a dedicated streaming_client builder method on AppContextBuilder to allow callers to configure and customize the streaming client independently of the standard client.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread model_gateway/src/app_context.rs
@jshanson7
jshanson7 force-pushed the codex/smg-streaming-timeout branch from e353ffc to 536a941 Compare June 30, 2026 14:55
@jshanson7 jshanson7 changed the title [smg] don't timeout active streaming responses fix(http): don't apply total timeout to streaming responses Jun 30, 2026
@jshanson7
jshanson7 force-pushed the codex/smg-streaming-timeout branch 2 times, most recently from 5717ea2 to 27353c3 Compare June 30, 2026 15:36
@jshanson7
jshanson7 force-pushed the codex/smg-streaming-timeout branch 3 times, most recently from b7ee09a to eb93e0d Compare June 30, 2026 17:58
@jshanson7 jshanson7 changed the title fix(http): don't apply total timeout to streaming responses fix(http): enforce streaming timeouts outside reqwest Jun 30, 2026
@jshanson7
jshanson7 force-pushed the codex/smg-streaming-timeout branch from eb93e0d to 9210c8a Compare June 30, 2026 19:20
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jun 30, 2026
@jshanson7
jshanson7 marked this pull request as ready for review July 3, 2026 00:49
@mergify

mergify Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Hi @jshanson7, this PR has merge conflicts that must be resolved before it can be merged. Please rebase your branch:

git fetch origin main
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

@mergify mergify Bot added the needs-rebase PR has merge conflicts that need to be resolved label Jul 3, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@model_gateway/src/routers/anthropic/worker.rs`:
- Around line 240-257: Reuse the existing record_error_metrics helper in
handle_error_response instead of duplicating the duration and error metric calls
inline. Update the non-streaming error path in the anthropic worker to pass the
same model_id, start_time, and error_type into record_error_metrics, keeping the
metric labels and behavior unchanged while removing the repeated block.

In `@model_gateway/src/routers/http/router.rs`:
- Around line 663-692: The streaming total-timeout branch in the `send_result`
handling path is missing `Metrics::record_worker_error`, unlike the `reqwest`
error handling later in `router.rs`. Update the `is_stream` timeout arm around
`StreamDeadline::until_total(...)` to record a worker error before returning the
504 response, using the same `model_id`, `endpoint`, and status-derived error
classification as the existing `worker.record_outcome` and
`Metrics::record_router_error` calls.

In `@model_gateway/src/routers/openai/chat.rs`:
- Around line 188-204: In `chat.rs`, the `is_streaming` branch in
`StreamDeadline::new()`/`until_total(req.send())` currently returns a 504 from
`error::gateway_timeout`, which is treated as retryable by
`is_retryable_status()`. Update this timeout path so streaming total-timeout
responses are marked non-retryable or use a distinct non-retryable status, and
keep the change localized to the `resp` handling in `openai::chat` so repeated
attempts do not reconsume the full request timeout.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ae371554-17cf-4825-bed7-856f9eedf979

📥 Commits

Reviewing files that changed from the base of the PR and between 7ff6e03 and 9210c8a.

📒 Files selected for processing (23)
  • docs/concepts/reliability/rate-limiting.md
  • docs/reference/configuration.md
  • model_gateway/src/app_context.rs
  • model_gateway/src/config/builder.rs
  • model_gateway/src/config/types.rs
  • model_gateway/src/config/validation.rs
  • model_gateway/src/main.rs
  • model_gateway/src/routers/anthropic/context.rs
  • model_gateway/src/routers/anthropic/non_streaming.rs
  • model_gateway/src/routers/anthropic/router.rs
  • model_gateway/src/routers/anthropic/sse.rs
  • model_gateway/src/routers/anthropic/streaming.rs
  • model_gateway/src/routers/anthropic/worker.rs
  • model_gateway/src/routers/common/mod.rs
  • model_gateway/src/routers/common/stream_timeout.rs
  • model_gateway/src/routers/http/pd_router.rs
  • model_gateway/src/routers/http/router.rs
  • model_gateway/src/routers/openai/chat.rs
  • model_gateway/src/routers/openai/context.rs
  • model_gateway/src/routers/openai/responses/streaming.rs
  • model_gateway/src/routers/openai/router.rs
  • model_gateway/src/service_discovery.rs
  • model_gateway/src/workflow/steps/local/drain_workers.rs

Comment thread model_gateway/src/routers/anthropic/worker.rs
Comment thread model_gateway/src/routers/http/router.rs
Comment thread model_gateway/src/routers/openai/chat.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9210c8a560

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/http/pd_router.rs Outdated
Comment thread model_gateway/src/routers/http/router.rs Outdated
Comment thread model_gateway/src/routers/anthropic/streaming.rs Outdated
@lightseek-bot lightseek-bot added the priority:high High priority label Jul 8, 2026
@jshanson7
jshanson7 force-pushed the codex/smg-streaming-timeout branch from 9210c8a to 8739949 Compare July 9, 2026 00:55
@mergify mergify Bot removed the needs-rebase PR has merge conflicts that need to be resolved label Jul 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
model_gateway/src/app_context.rs (1)

430-502: 🚀 Performance & Scalability | 🔵 Trivial

Dual clients double the idle-connection ceiling per worker.

Each build_worker_http_client call sets pool_max_idle_per_host(500), so a single worker can now accumulate up to 1000 idle connections combined (500 for client + 500 for streaming_client) instead of 500. Likely fine given today's deployment sizes, but worth keeping in mind for connection/FD budgeting as worker counts grow.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@model_gateway/src/app_context.rs` around lines 430 - 502,
`build_worker_http_client` is creating two separate reqwest clients (`client`
and `streaming_client`) that each allow 500 idle connections per host,
effectively doubling the per-worker idle-connection cap. Reduce the combined
idle pool budget by lowering `pool_max_idle_per_host` for these clients or
otherwise centralize the limit so the total across both clients stays at the
intended ceiling. Use the `client` and `streaming_client` setup in this section
to keep the per-worker FD/connection budget bounded.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@model_gateway/src/main.rs`:
- Around line 426-429: Add a two-path plumbing test for stream_idle_timeout_secs
in main.rs to match the existing *_flows_into_both_configs coverage used by
engine_metrics, multimodal_tensor_transport, runtime_worker_threads, and
health_check_port. Create a test that builds CLI args with
--stream-idle-timeout-secs, calls cli_args_from and then to_router_config (and
the server-config path if the other tests do both), and asserts the value is
preserved so the flag is verified end-to-end through the config conversion flow.

In `@model_gateway/src/routers/anthropic/streaming.rs`:
- Around line 110-141: The stream relay logic in the anthropic streaming path is
duplicated between the main response handling and the SSE error handling.
Extract the repeated `stream_deadline.next(...)` / `tx.send(...)` / break-loop
behavior from the `tokio::spawn` block into a shared helper used by both call
sites, keeping the existing timeout and error translation behavior intact. Make
the helper reusable for both the success path and SSE error path so
`Body::from_stream` and the error-event sender rely on the same relay
implementation.

In `@model_gateway/src/routers/common/stream_timeout.rs`:
- Around line 45-50: The sse_error_event method is hand-building a JSON payload
by interpolating self.message(timeout) directly into a string, which is fragile
if the message ever contains characters that need escaping. Update
sse_error_event in StreamTimeoutKind to construct the SSE error payload with
serde_json::json! or a typed serializable struct and serialize it with
serde_json::to_string, then wrap that serialized JSON in the Bytes response.

---

Outside diff comments:
In `@model_gateway/src/app_context.rs`:
- Around line 430-502: `build_worker_http_client` is creating two separate
reqwest clients (`client` and `streaming_client`) that each allow 500 idle
connections per host, effectively doubling the per-worker idle-connection cap.
Reduce the combined idle pool budget by lowering `pool_max_idle_per_host` for
these clients or otherwise centralize the limit so the total across both clients
stays at the intended ceiling. Use the `client` and `streaming_client` setup in
this section to keep the per-worker FD/connection budget bounded.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a439a475-9de2-4acc-9f03-e6a3724e31fe

📥 Commits

Reviewing files that changed from the base of the PR and between 9210c8a and 8739949.

📒 Files selected for processing (23)
  • docs/concepts/reliability/rate-limiting.md
  • docs/reference/configuration.md
  • model_gateway/src/app_context.rs
  • model_gateway/src/config/builder.rs
  • model_gateway/src/config/types.rs
  • model_gateway/src/config/validation.rs
  • model_gateway/src/main.rs
  • model_gateway/src/routers/anthropic/context.rs
  • model_gateway/src/routers/anthropic/non_streaming.rs
  • model_gateway/src/routers/anthropic/router.rs
  • model_gateway/src/routers/anthropic/sse.rs
  • model_gateway/src/routers/anthropic/streaming.rs
  • model_gateway/src/routers/anthropic/worker.rs
  • model_gateway/src/routers/common/mod.rs
  • model_gateway/src/routers/common/stream_timeout.rs
  • model_gateway/src/routers/http/pd_router.rs
  • model_gateway/src/routers/http/router.rs
  • model_gateway/src/routers/openai/chat.rs
  • model_gateway/src/routers/openai/context.rs
  • model_gateway/src/routers/openai/responses/streaming.rs
  • model_gateway/src/routers/openai/router.rs
  • model_gateway/src/service_discovery.rs
  • model_gateway/src/workflow/steps/local/drain_workers.rs
💤 Files with no reviewable changes (1)
  • model_gateway/src/workflow/steps/local/drain_workers.rs

Comment thread model_gateway/src/main.rs
Comment thread model_gateway/src/routers/anthropic/streaming.rs Outdated
Comment thread model_gateway/src/routers/common/stream_timeout.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 873994913e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/http/router.rs Outdated
Comment thread model_gateway/src/routers/openai/chat.rs
Comment thread model_gateway/src/routers/http/pd_router.rs
Comment thread model_gateway/src/routers/openai/responses/streaming.rs Outdated
Comment thread model_gateway/src/routers/openai/responses/streaming.rs
@jshanson7
jshanson7 force-pushed the codex/smg-streaming-timeout branch from 8739949 to 1f64f27 Compare July 9, 2026 02:05
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>
@jshanson7
jshanson7 force-pushed the codex/smg-streaming-timeout branch from 6bcd1d4 to fdf505c Compare July 26, 2026 04:10

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fdf505c4b5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/http/router.rs Outdated
@mergify mergify Bot removed the needs-rebase PR has merge conflicts that need to be resolved label Jul 26, 2026
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 490d962d8a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/common/sse.rs Outdated
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eaafcf19d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/common/stream_timeout.rs Outdated
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5eedf093f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/anthropic/streaming.rs
Comment thread model_gateway/src/routers/anthropic/streaming.rs Outdated
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eff2867217

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/anthropic/sse.rs
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c20cf45004

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/http/router.rs
Comment thread model_gateway/src/routers/anthropic/sse.rs
Comment thread model_gateway/src/routers/anthropic/streaming.rs Outdated
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 298681bc2d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/http/router.rs
Comment thread model_gateway/src/routers/openai/chat.rs
Comment thread model_gateway/src/routers/anthropic/streaming.rs Outdated
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2ef76e470c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/openai/responses/streaming.rs
Comment thread model_gateway/src/routers/openai/responses/streaming.rs Outdated
Comment thread model_gateway/src/routers/http/pd_router.rs Outdated
Comment thread model_gateway/src/routers/http/pd_router.rs Outdated
Comment thread model_gateway/src/routers/http/router.rs Outdated
Comment thread model_gateway/src/routers/http/router.rs Outdated
Comment thread model_gateway/src/routers/anthropic/streaming.rs Outdated
Comment thread model_gateway/src/routers/http/pd_router.rs Outdated
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 95670114fd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/openai/chat.rs Outdated
Comment thread model_gateway/src/routers/http/pd_router.rs Outdated
Comment thread model_gateway/src/routers/anthropic/streaming.rs
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a465d16a47

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/http/router.rs
Comment thread model_gateway/src/routers/http/router.rs
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8cd2950a71

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/http/pd_router.rs Outdated
Comment thread model_gateway/src/routers/anthropic/streaming.rs
Comment thread model_gateway/src/routers/anthropic/streaming.rs Outdated
Comment thread model_gateway/src/routers/http/pd_router.rs Outdated
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1271a373b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/openai/responses/streaming.rs
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05f664a5af

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread model_gateway/src/routers/anthropic/streaming.rs
Signed-off-by: Jeff Hanson <jshanson7@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05ccf91a26

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let mut terminal_seen = false;

loop {
let chunk_result = match stream_deadline.next(&mut upstream_stream).await {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recheck the deadline while forwarding Responses events

When an MCP Responses worker yields a large chunk just before the total deadline, this is the last deadline check before the inner next_block() loop parses and forwards every buffered event. Because those sends use the unbounded channel without another elapsed-time check, the gateway can continue emitting ordinary events after request_timeout_secs; if the same chunk contains a terminal event, it can even record the stream as successful without ever observing the expired deadline. Check the shared deadline before forwarding each decoded event, reserving post-deadline sends for the timeout event.

Useful? React with 👍 / 👎.

Comment on lines +790 to +791
if is_terminal {
break 'stream_loop;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the trailing Responses done marker

When a normal Responses upstream sends response.completed followed by data: [DONE]—the ordering used by the repository's mock worker—this branch exits the outer relay immediately after forwarding response.completed, so the subsequent done marker is dropped. Clients that rely on [DONE] to finalize a Responses stream receive an unexpected EOF instead; continue consuming through [DONE] or synthesize the marker when treating response.completed as terminal.

Useful? React with 👍 / 👎.

let mut done_observer = sse::SseTerminalObserver::done();
let mut terminal_seen = false;
loop {
let chunk = match stream_deadline.next(&mut s).await {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound queued chat output by the total deadline

When the upstream chat worker is faster than a slow downstream client, this deadline only governs reads from the upstream stream; each chunk is then placed on an unbounded channel. The relay can therefore consume through [DONE], record success, and exit before the client receives the queued data, after which the HTTP body may keep draining that queue well past request_timeout_secs while memory grows with the backlog. Use a bounded channel and deadline-aware sends so downstream delivery remains part of the total stream cap.

Useful? React with 👍 / 👎.

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

Labels

anthropic Anthropic router changes documentation Improvements or additions to documentation model-gateway Model gateway crate changes multimodal Multimodal crate changes openai OpenAI router changes priority:high High priority python-bindings Python bindings changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants