Skip to content

Consolidate coordinator SSE lifecycle and completion policies - #898

Closed
Gajesh2007 wants to merge 3 commits into
masterfrom
refactor/coordinator-operations
Closed

Gajesh2007 wants to merge 3 commits into
masterfrom
refactor/coordinator-operations

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

The coordinator maintained three copies of the provider SSE relay loop and two copies of translated-endpoint setup, error settlement and completion handling. This change gives channel arbitration one implementation and makes endpoint completion differences explicit, so changes to coalescing or late-error delivery have one owner.

Stacked on feat/gpt-oss-20b-prefix-cache (#894); no release/default changes are introduced here.

  • Production streaming code shrinks by 127 lines; regression tests and documentation account for the overall diff growth.
  • relayProviderStream owns bounded queued-chunk draining, flush-before-terminal ordering, idle timeout and cancellation selection for Chat, Responses, Completions and Messages.
  • handleEndpointStreamingResponse owns shared translated-endpoint setup, initial provider errors, route outcomes, refunds and final flushing. Emitters retain their exact wire formats; chat retains its held finish/usage/metadata logic.
  • streamCompletionPolicy explicitly preserves existing differences: Messages/Completions require completion usage even without a reservation and observe cancellation during the completion wait; Responses retains its settled-reservation fallback and independent usage grace period.
  • The consumer architecture page documents those ownership boundaries and policies.

Before:

flowchart TD
  A[Committed provider request] --> B{Consumer endpoint}
  B --> C[Chat handler: own select/drain/flush loop]
  B --> D[Responses handler: own setup/error/select loop]
  B --> E[Generic handler: own setup/error/select loop]
  C --> F[Chat held usage/finish and metadata]
  D --> G[Responses completion grace and emitter]
  E --> H[Explicit completion required and Messages/Completions emitters]
  C --> I[Queued chunks before error; refund/route outcome]
  D --> I
  E --> I
  F --> J[Existing endpoint success terminal]
  G --> J
  H --> J
  I --> K[Existing endpoint in-band error or client departure]
Loading

After:

flowchart TD
  A[Committed provider request] --> B{Consumer endpoint}
  B --> C[Chat handler: chat wire state]
  B --> D[handleEndpointStreamingResponse: shared setup/error settlement]
  C --> E[relayProviderStream: one select/drain/flush loop]
  D --> E
  E -->|Closed| F[Chat held usage/finish and metadata]
  E -->|Closed| G[finishEndpointStream: explicit completion policy]
  G --> H[Responses or Messages/Completions emitter]
  F --> J[Same endpoint success terminal]
  H --> J
  E -->|Error / idle timeout / client gone| I[Caller settles and records outcome]
  I --> K[Same endpoint in-band error or client departure]
Loading

Validation:

  • Existing SSE golden, burst, coalescing, usage and Responses tests pass.
  • New regression matrix covers missing completion across all translated formats with no/outstanding/settled reservations, exactly-once refunds, dispatch-time chunks before an initial error, and the endpoint-specific cancellation grace.
  • GOTOOLCHAIN=go1.25.0 go test ./coordinator/... passes (API package 194.418s; registry/routing simulation/store/billing and all other coordinator packages pass).
  • Final targeted API race suite passes (47.427s), covering endpoint, SSE/burst/coalescing, settlement, generic and request-outcome tests.
  • git diff --check and docs lint pass (278 documents).

The observable API shapes, status codes, flush bounds, timer-reset placement, settlement calls, telemetry, provider cancellation ownership and GPT-OSS defaults remain unchanged. This is a focused coordinator refactor, not a rewrite of the scheduler or ledger.

@vercel

vercel Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Ready Ready Preview Sep 11, 2026 11:45pm UTC
d-inference-console-ui-dev Ready Ready Preview Sep 11, 2026 11:45pm UTC
d-inference-landing Ready Ready Preview Sep 11, 2026 11:45pm UTC

Request Review

@Gajesh2007

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-11T23:50:42.439366Z 9cb3a69 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 775c41e32d

ℹ️ 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 coordinator/api/endpoint_stream.go Resolved
@Gajesh2007

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 77f0ea83b5

ℹ️ 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".

@Gajesh2007

Copy link
Copy Markdown
Member Author

Final validation for 77f0ea83b5be6e1d7c89ad21308d5a5a6300f4cf:

Individual validation details and limitations are in each PR description, including the dedicated-M5 provider/live GPT-OSS checks and the unchanged baseline TypeScript diagnostics in #899. No merge or deployment was performed.

@Gajesh2007

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 275190bb01

ℹ️ 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".

@Gajesh2007

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 9cb3a691f6

ℹ️ 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".

@Gajesh2007

Copy link
Copy Markdown
Member Author

Superseded by #1054, which carries this change and its regression coverage into the coordinator subsystem layout. The replacement passed the relevant local race tests, build/lint checks, and independent source review.

Please review #1054; closing this older implementation to keep one active version of the change. The branch and review history are retained. No change has been merged to master by this closure.

This branch had an error being deployed

1 failed and 3 active deployments
Preview – d-inference-console-ui-dev — 9cb3a691 Deployed Sep 11, 2026 by vercel[bot]
Preview – d-inference — 9cb3a691 Deployed Sep 11, 2026 by vercel[bot]
Preview – d-inference-landing — 9cb3a691 Deployed Sep 11, 2026 by vercel[bot]
benchmarks — 9cb3a691 Deployed Sep 11, 2026 by Gajesh2007 via E2E Benchmarks #981
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.

1 participant