Skip to content

fix(coordinator): bound non-streaming provider response retention - #1297

Merged
Gajesh2007 merged 7 commits into
masterfrom
codex/issue337-public
Oct 5, 2026
Merged

Gajesh2007 merged 7 commits into
masterfrom
codex/issue337-public

Conversation

@jonathan308

@jonathan308 jonathan308 commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #337.

A provider can currently grow the coordinator's non-streaming []string accumulator for the entire inference timeout. This change rejects an attempt before retaining more than 64 MiB of decrypted chunk payload or 262,144 frames by default, with positive deployment overrides. Empty and malformed frames count too. Limits apply across chat completions, Responses, completions, and messages; streaming consumers retain the existing backpressure behavior.

Enforcement happens at decrypted handleChunk ingress before classification/queuing, so a fast completion cannot settle an over-limit attempt while the HTTP handler drains its queue. Primary/retry/speculative and queued attempts receive separate budgets before dispatch. The response assembler independently checks already-held first chunks and subsequent chunks. Overflow sends the existing tracked cancel, removes the pending attempt through the existing error lifecycle, forgets the chunk key, and returns 502 provider_error. Existing reservation finalization prevents duplicate refunds or late success settlement. A coordinator-only response_limit cause preserves the status through error normalization and cannot be supplied over provider JSON.

No provider wire change or Swift source change is needed: the provider already force-streams non-streaming requests and propagates coordinator cancellation to the inference task. The coordinator bound does not depend on provider cooperation.

Before

flowchart LR
  A[Non-streaming consumer request] --> B[dispatch / queued attempt]
  B --> C[Provider force-streams SSE]
  C --> D[handleChunk decrypts and queues]
  D --> E[HTTP response handler appends without aggregate cap]
  E --> F[Memory grows until terminal or timeout]
  C --> G[handleComplete can settle before HTTP drain]
  G --> H[Assemble response and HTTP 200]
Loading

After

flowchart LR
  A[Non-streaming consumer request] --> B[Install ResponseBudget before reservation / queue]
  B --> C[Provider force-streams SSE]
  C --> D[handleChunk decrypts then checks bytes and frames]
  D -->|Within both limits| E[Queue / hold first chunks]
  E --> F[Assembler checks first and later chunks]
  F --> G[Existing usage / tools / reasoning assembly and HTTP 200]
  D -->|Over either limit| H[Tracked cancel + handleInferenceError]
  H --> I[Remove pending / forget key / release slot]
  I --> J[Existing retry or refund ownership / HTTP 502]
  H --> K[Late chunks and completions cannot settle success]
Loading

Limits and compatibility

  • EIGENINFERENCE_NONSTREAM_RESPONSE_MAX_BYTES defaults to 67,108,864; EIGENINFERENCE_NONSTREAM_RESPONSE_MAX_CHUNKS defaults to 262,144. Invalid/non-positive values retain defaults. Exact ceilings are accepted; the next byte/frame is rejected.
  • These are payload/frame budgets, not token estimates. Current fallback output ceiling is 8,192 tokens; catalog ceilings vary. Defaults allow 32 frames and about 8 KiB of envelope-inclusive payload per fallback token. Larger deployment contracts may need an explicit higher limit.
  • At the frame ceiling, Go string-header length accounts for 4 MiB on 64-bit hosts, plus slice capacity growth. Parsing/encoding, one current WebSocket frame, and concurrent requests add memory: this is a per-attempt retention limit, not a whole-process RSS guarantee.
  • No database migration, model change, release bump, or rollout protocol dependency. Existing valid outputs below both ceilings are preserved. Revert this change to roll back (restores the reported risk).

Ported onto the reorganized coordinator (2026-10-04)

Merged current master c5552d3af7 (after #1324, #1338 and #1340). Signed commits on top of the previous head: merge 89ee0b56, refactor pass f83ea9a8, merge 5f983a2d; the resolved source tree is 8a5d09cc. The text above names functions as they were; this table gives their homes now. Limits, defaults, status codes and the two environment variables are unchanged.

Before Now
Ingress check in handleChunk, error normalization in handleInferenceErrorOwned (coordinator/api/provider.go) Owner.HandleChunk and Owner.handleInferenceErrorOwned in coordinator/api/inference/provider_inference.go
Assembler budget in coordinator/api/consumer_response.go relay.Controller.NonStream in coordinator/internal/inference/relay/consumer_response.go
Budget on dispatched attempts in dispatchProviderWith dispatch.Plan.Dispatch in coordinator/internal/inference/dispatch/plan.go, with a new Input.Stream
Budget on the queue placeholder in dispatchPrimary Primary.Run in coordinator/api/inference/primary_run.go
(*Server).newNonStreamingResponseBudget and the two default constants responselimit.Limits.NewBudget in the small package coordinator/internal/inference/responselimit. The owner, the dispatcher and the relay all need the same rule, and the last two cannot import the owner
Message constant in package api failure.NonStreamingResponseLimitError, beside the sanitizer that uses it
One test file in package api, one in registry The same tests by owner: coordinator/tests/api/inference (7), coordinator/tests/api/inference/failure (1), coordinator/tests/api (1), coordinator/tests/registry (2)

registry.ResponseBudget, PendingRequest.NonStreamingResponseBudget and protocol.CoordinatorCauseResponseLimit are where they were.

Documentation added for the new layout, which the widened docs rules require: the limit joins the list of coordinator/internal/inference components in docs/architecture/components/coordinator.md; the error-vocabulary row of docs/architecture/security/encryption.md says the response_limit terminal cannot come from a provider frame; docs/consumer/billing.md has a troubleshooting row (the reservation is refunded in full).

Refactor pass. A dedicated refactor subagent reviewed the ported change against the structure and clean-code rules in AGENTS.md. Changes followed, in a separate commit (f83ea9a8), none to a production statement: a doc comment on ResponseBudget.Accept (a nil budget accepts everything, limits are inclusive, an empty chunk uses a slot); a twelfth test, TestNonStreamingResponseLimitBudgetFollowsRequestStream, which sends a non-streaming and a streaming request through the real router and reads the budget on the dispatched attempt; and two symbol names in the documentation row. It judged the responselimit package the right shape and left it. Noted for a follow-up: nothing asserts the budget on the queue placeholder, and an overflow before first content is retried like any other provider failure.

Validation on the merged head (Go 1.25.0, PostgreSQL 16):

  • gofmt clean, go build ./coordinator/..., go vet ./coordinator/..., layout guard TestCoordinatorTestsAreIsolated.
  • The 12 tests and their 14 subtests pass, also under -race.
  • Fails without the fix, each through go test -overlay: master's ingress and assembler give status 200 want 502 on the oversized, aggregate, empty and malformed cases and leave the attempt pending; without the budget in the dispatch plan, budget not installed correctly before reservation; without the sanitizer branches, status 500 want 502; without the stream flag reaching the plan, stream=true: dispatched attempt budgeted=true.
  • Complete coordinator suite at the pushed head, python3 scripts/run-coordinator-tests.py --jobs 1 ./coordinator/...: 8,154 passed, 0 failed, 5 skipped. The same five tests skip on master.
  • make docs-check (330 files) and make docs-impact-check BASE=origin/master.
  • Not run on this head: the race-and-coverage configuration of the full suite, golangci-lint, the Linux cross-build, the Rust and native suites listed below for the earlier head. CI covers the coordinator ones.

Validation

Current branch is based on upstream master 55441677e49059a164211d0c08b62ddcec63c3ce. Refresh preserved both changelog entries; no additional production behavior changes.

On the refreshed patch: focused Go race regressions across api/registry/protocol PASS; docs-impact and docs-check PASS (326 docs); diff whitespace check PASS.

Historical validation on the identical fix before refresh (commit 0c44a07a49891bda8f4335686f95242f2a334860, base 6af40ccb97891ba8ed9e2b05adc798190eb13551): full Go race suites including disposable PostgreSQL16, Go vet/build/Linux cross-build, CI-pinned golangci-lint2.1.6, Rust163 tests/fmt/check/clippy, provider regression script,17 explicit native tests,22 SDK selections plus paged-kernel/composition checks, and cached-codec audio HTTP test passed. General provider logs contain89 opt-in skips; these are not full model qualification. Native testing held the documented exclusive lane. Local CMake4.3.2 differs from CI pin3.31.12.

Negative control: the new tests fail against original accumulator/ingress source with HTTP200 on oversized first/aggregate/empty/malformed cases and oversized attempts left pending. Tests use small synthetic payloads and local fixtures. Independent local review found no blocking findings.

Not yet qualified locally: full model/E2E and production prompt parity; AAC-video fixture case; Docker Linux load proof; Node22 console lint/build. test-prod-env-refresh.sh had a macOS awk failure reproduced on unchanged base. Hosted CI for this refreshed head is pending. Readiness follows the requested review workflow; benchmark approval and preview permissions are disclosed separately.

Integration refresh

Merged current master b1c14ed896e8f3fdb9a31a96fbd1a3cce977c86d via signed commit b2b4eb99d9e9870357b5364bdbed2c38c23e36d5. Master now includes the Homebrew cleanup fix from #1287. Retained its implementation/tests exactly and removed the redundant #1290 additions and test-specific docs. The diff against master is again only the18 intended #337 files; coordinator additions/deletions are identical to the original fix.

On this refreshed head: focused coordinator race tests, the upstream offline Homebrew regression, docs-impact/docs-check and whitespace checks passed. Reverting the cleanup trap in an isolated negative control reproduces the original unbound-variable failure.

Previous head 8efc8b4d17fe6ac3dfee0b379308cd0d7928e9e8 passed main CI, E2E integration and CodeQL. Fresh CI is required for the new head. The PR remains ready for review per request, not merged. Benchmark approval and preview-permission failures were outstanding on the previous head; no permission/settings changes were made.

@jonathan308
jonathan308 requested a review from Gajesh2007 October 1, 2026 03:06
@vercel

vercel Bot commented Oct 1, 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 Oct 4, 2026 10:50pm UTC
d-inference-console-ui-dev Building Building Preview Oct 4, 2026 10:50pm UTC
d-inference-landing Ready Ready Preview Oct 4, 2026 10:50pm UTC
eigen-homepages-darkbloom Ready Ready Preview Oct 4, 2026 10:50pm UTC

Request Review

davidtai and others added 2 commits September 30, 2026 20:13
The EXIT trap ran after install_brew returned, when the local variable
was gone, so set -u failed the step after a successful install.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run setup-macos-homebrew.sh with a local fake installer and its own
checksum, selected by test-only overrides that need
SETUP_MACOS_HOMEBREW_TEST=1. The test fails with "installer: unbound
variable" when the exit-trap fix is removed, and checks that a wrong
checksum stops the installer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

Deployment failed for project eigen-homepages-darkbloom with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: eigen-homepages-darkbloom.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-console-ui-dev with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-console-ui-dev.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-landing with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-landing.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head 5f983a2d22a9 against base c5552d3af7ae.

Review not completed for this head. Previous findings are superseded, not confirmed resolved.
Ten-PR pilot complete; maintainer evaluation required

Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging.

Coverage: 0/0 source units; cross-file integration pending. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned.

Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 0 reused batch(es), 0 provider cache-hit tokens.

Saved findings and earlier report · Historical findings are not confirmed resolved.

jonathan308 and others added 3 commits October 4, 2026 13:27
…zed coordinator

Upstream reorganized the coordinator (#1324): response assembly is owned by
coordinator/internal/inference/relay, dispatch by
coordinator/internal/inference/dispatch, provider ingress and the queue
placeholder by coordinator/api/inference, and every Go test lives under
coordinator/tests.

- Account each decrypted chunk in Owner.HandleChunk before it is classified
  or queued, and normalize the coordinator-only response_limit terminal in
  handleInferenceErrorOwned, as before.
- Budget the assembler in relay.Controller.NonStream (held first chunks and
  channel chunks), every dispatched attempt in dispatch.Plan.Dispatch, and
  the queue placeholder in Primary.Run.
- The limits-to-budget rule, which the owner, the dispatcher and the relay
  all need, is the small package
  coordinator/internal/inference/responselimit. registry.ResponseBudget and
  both environment variables are unchanged.
- Move the eleven tests, with the same names and assertions, to the owners
  they exercise: tests/api/inference, tests/api/inference/failure,
  tests/api and tests/registry.
- Documentation: keep both sides, cite the new paths, and note the limit in
  the coordinator component map, the error-vocabulary row and consumer
  billing troubleshooting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m flag

Outcome of the required refactor pass on the ported change. No production
statement changes.

- Document ResponseBudget.Accept: a nil budget accepts everything
  (streaming attempts carry none), limits are inclusive, and an empty
  chunk still uses a slot.
- Add TestNonStreamingResponseLimitBudgetFollowsRequestStream. It sends a
  non-streaming and a streaming request through the real router and reads
  the budget on the dispatched attempt, covering the one copy of the
  stream flag the port left without a test.
- encryption.md: the row this change edits cited two sanitizer symbols by
  their pre-reorganization names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Gajesh2007 Gajesh2007 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed head 5f983a2, including per-attempt queue/retry/speculation wiring, synchronous ingress enforcement, cancellation, settlement/refund ownership, and non-forgeable error normalization. No blocking correctness or security findings. Focused NonStreamingResponseLimit/ResponseBudget tests passed locally under -race (Go 1.25.4). Current applicable CI and integration checks pass; the E2E benchmark environment remains awaiting approval, not validated by this review.

@Gajesh2007
Gajesh2007 merged commit 3f20f33 into master Oct 5, 2026
32 of 33 checks passed

This branch was successfully deployed

4 active deployments
Preview – d-inference — 5f983a2d Deployed Oct 4, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 5f983a2d Deployed Oct 4, 2026 by vercel[bot]
Preview – d-inference-landing — 5f983a2d Deployed Oct 4, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — 5f983a2d Deployed Oct 4, 2026 by vercel[bot]
benchmarks — 5f983a2d Deployed Oct 4, 2026 by jonathan308 via E2E Benchmarks #2209
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.

OOM-H2: provider can OOM the coordinator (TEE) via unbounded non-streaming chunk accumulation

3 participants