Repository navigation
feat: preserve prompt_cache_options across Responses execution - #436
Merged
maralbahari merged 7 commits intoOct 19, 2026
Merged
maralbahari merged 7 commits into
maralbahari merged 7 commits into
Conversation
Signed-off-by: zitian.zhao <[email protected]>
7 tasks
skyloevil
marked this pull request as ready for review
October 11, 2026 16:02
skyloevil
requested review from
bbrowning,
franciscojavierarceo,
haoshan98,
jiahuei,
leseb,
maralbahari,
noobHappylife,
qandrew and
tjtanaa
as code owners
October 11, 2026 16:02
Adapt the request-parity test to the fixed-size slice API required by the updated MSRV Clippy configuration. Signed-off-by: zitian.zhao <[email protected]>
haoshan98
requested changes
Oct 15, 2026
Allow independent retention and options controls, defer strict options parsing to executor routes, and echo current request options consistently through response lifecycle and storage. Add regressions for all three review findings and synchronize with main while preserving telemetry stage ownership. Signed-off-by: zitian.zhao <[email protected]>
haoshan98
approved these changes
Oct 16, 2026
haoshan98
left a comment
Collaborator
There was a problem hiding this comment.
@skyloevil Kindly resolve the conflicts.
Signed-off-by: zitian.zhao <[email protected]>
This was referenced Oct 16, 2026
Contributor
Author
|
@haoshan98 The conflicts are resolved. Thanks! |
Zheng-Lu
added a commit
to Zheng-Lu/agentic-api
that referenced
this pull request
Oct 19, 2026
Resolve the conflicts with vllm-project#436 by keeping both sides. Its prompt-cache options validation runs first in rehydrate_request, then the unsupported-parameter check. Signed-off-by: Zheng Lu <[email protected]>
maralbahari
added a commit
that referenced
this pull request
Oct 20, 2026
…ponses execution (#456) ## Summary Part of #314. Typed Responses execution now rejects two request members it recognizes but can't honour. Before, it silently answered a different request than the client sent. **Before:** `RequestPayload` had no `background` or `prompt` field, so serde dropped both. A request that selected typed execution (storage, a continuation, built-in tools, and so on) ran as a foreground, prompt-less response, with no error. **After:** | Path | `background` | `prompt` | | --- | --- | --- | | Direct HTTP JSON/SSE | Forwarded unchanged; upstream validation | Forwarded unchanged; upstream validation | | Typed HTTP JSON/SSE, WebSocket, split-execution hydration | Absent, `null`, or `false` accepted; `true` → `400 unsupported_value`, `param: background` | Absent or `null` accepted; any other value → `400 unsupported_parameter`, `param: prompt` | The rejection happens before history lookup, tool discovery, storage, or inference. Background mode itself is #357. **Why the direct route is left alone.** It follows the policy #436 documents for `prompt_cache_options`, and the handler's existing rule that direct requests keep their raw body: on the direct route, the upstream decides. For vLLM (the contract at [`840c7c2f`](https://github.com/vllm-project/vllm/blob/840c7c2f4bc72c7c55edb2dea6d23f9a9c9734e0/vllm/entrypoints/openai/responses/protocol.py), the commit #436 cites), that means: - `background: true` is already rejected unless `store` is true. The direct route only carries `store: false` requests, so vLLM rejects every one of them. - `prompt` is accepted and echoed, but the serving path never reads it. The gap #314 targets, "required request semantics do not silently disappear when enabling storage or built-in tools", is the typed route. That is where this PR acts. How it's built: - **Detection-only fields.** `RequestPayload` gains `background: Option<bool>` and `prompt: Option<RejectedValue>`. Both are `skip_serializing`, so they never reach storage, the split-execution context, or the upstream request the executor builds. `RejectedValue` accepts any JSON value and keeps none of it, so the boundary stays typed, and the HTTP routing parse never fails on a value it must forward. - **Typed error.** The new types-layer `UnsupportedParameterError` provides `code()` and `param()`. It converts into `ExecutorError::UnsupportedParameter` through `#[from]`, mirroring `MaxToolCallsError` and `InvalidMaxToolCalls`. The existing `UnsupportedValue { param, message }` variant can't carry `unsupported_parameter`. - **One check.** `ensure_supported_parameters()` runs first in `rehydrate_request`. Every typed entry point reaches it: executor-routed HTTP, WebSocket `response.create`, `rehydrate_conversation` (llm-d and embedders), and sessions. The HTTP handler is unchanged. - **Docs.** `docs/api/index.md` gains the per-path matrix above. It also lists the unmodelled members typed execution still ignores (`top_logprobs`, `user`, `safety_identifier`, `stream_options`, and vLLM sampling extensions), which #434 tracks. Out of scope: - **`file_search`.** Its "accepted but not offered to the model" behaviour is documented in `ROADMAP.md` and `docs/design/codex-integration.md`, and `max_tool_calls_test` relies on a request-declared `file_search`. Whether to reject it until a handler exists is a separate decision. - **Preserving the ignored members** listed above (#434). ### Overlap with #436 I checked against #436 at `3e601ca`: - **Conflicts:** 4 files (`executor/error.rs`, `executor/rehydrate.rs`, `executor/telemetry.rs`, `types/request_response.rs`). Each is two adjacent additions: a new `ExecutorError` variant, a new first line in `rehydrate_request`, or a new child module and its re-export. Keep both. - **Compiles cleanly:** `ensure_supported_parameters` is implemented on the typed `RequestPayload`, which keeps #436's new default type parameter. - **Tests pass on the combined tree:** `request_response` unit tests, the core admission tests, `responses_test`, `responses_websocket_test`, `compaction_test`, `openapi_test`, and llm-d `http_contract`. - **Size limit:** the file-size ratchet passes, with `types/request_response.rs` at 474 lines after #436's text-config split. ## Test Plan New tests: - **`types/request_response/unsupported.rs`** (unit): - absent, `null`, and `false` are accepted; - `background: true` is rejected; - `background: "yes"` is a parse error; - three `prompt` shapes are rejected; - `background` is checked before `prompt`; - the HTTP routing payload parses every value it passes through; - neither member is ever serialized. - **`executor/error.rs`:** `unsupported_parameters_match_openai_error_envelopes` checks both exact envelopes. - **`agentic-server-core/tests/unsupported_parameters_test.rs`:** - JSON and SSE execution are rejected with zero upstream calls. - `rehydrate_conversation` rejects them. - Explicit defaults execute and are not forwarded upstream. - **`responses_test::test_unsupported_parameters_are_rejected_by_typed_execution_and_passed_through_directly`:** - Typed routes, in three cases (`store: true` with JSON, `store: true` with SSE, and `store: false` with a missing `previous_response_id`), return exact envelopes with zero upstream calls. The last case returns `400 unsupported_*`, not `404`, so the check runs before history lookup. - The direct route forwards each body byte-for-byte as JSON. - Typed execution accepts the explicit defaults and does not forward them. - **`responses_websocket_test::websocket_rejects_unsupported_parameters_and_keeps_the_connection`:** checks the exact error frames, then a valid `response.create` on the same socket completes. - **`agentic-llm-d` `http_contract::hydrate_rejects_unsupported_parameters_with_a_standard_envelope`.** Evidence: - **RED.** - The core admission tests failed before the check (requests were executed and admitted). - The HTTP test's direct-route assertions failed while an earlier draft of this branch also validated before routing (`400` instead of forwarding). - **Negative control.** Removing only the check in `rehydrate_request` fails all five rejection tests (core execution, core rehydration, HTTP, WebSocket, llm-d). The explicit-defaults test still passes. - **Recorded traffic.** The 261 cassettes contain 684 HTTP request bodies and 146 WebSocket `response.create` frames. None sends `background` or `prompt`, so recorded Codex, Claude Code, and SDK flows are unaffected. Gate: - `cargo fmt -- --check` - `cargo clippy --workspace --all-targets -- -D warnings` - Feature clippy (`--features embedded-code-interpreter`) for `agentic-server-core` and `agentic-server` - Rust file-size ratchet - `pre-commit run --all-files` - `mkdocs build --strict` - `cargo test --workspace --no-fail-fast`: 2521 passed, 1 failed. The failure is `tool::web_fetch::http::tests::the_deadline_bounds_a_slow_origin`, a wall-clock bound that also fails on unmodified `main` when the whole lib suite runs in parallel. It passes in isolation. --------- Signed-off-by: Zheng Lu <[email protected]> Co-authored-by: Maral <[email protected]>
maralbahari
pushed a commit
that referenced
this pull request
Oct 22, 2026
## Summary Closes #457 The gateway had only global concurrency bounds, so one caller could use up the upstream's capacity and shared web-search or code-interpreter quotas for everyone. This PR adds an opt-in, per-caller request rate limit. It is off by default: no middleware is installed and no headers change. **Configuration** (CLI > environment > `[server]` file setting, following `max_request_body_size_bytes`): | CLI | Environment | File (`[server]`) | | --- | --- | --- | | `--rate-limit-requests-per-minute` | `AGENTIC_RATE_LIMIT_REQUESTS_PER_MINUTE` | `rate_limit_requests_per_minute` | | `--rate-limit-burst` | `AGENTIC_RATE_LIMIT_BURST` | `rate_limit_burst` (default: the per-minute rate) | - A burst without a rate, a zero value, or a burst over one hour of requests fails at startup, and the error names the setting. - An explicit CLI value outranks a malformed inherited environment value. **Caller key** (first match): 1. OIDC issuer and subject; 2. a keyed hash of the bearer token; 3. a keyed hash of `x-api-key`; 4. one shared anonymous bucket. Raw credentials are never stored. A WebSocket is keyed by its upgrade request's own credentials, never by the server's `OPENAI_API_KEY` fallback. **Algorithm:** GCRA (equivalent to a token bucket). Each caller holds one theoretical arrival time in a `std::sync::Mutex<HashMap>`, using `tokio::time::Instant` so tests can pause time. No lock is held across an await. Memory is bounded at 100,000 callers: idle callers are pruned first, and new callers share an overflow bucket while every tracked caller is active, with a `warn` at most once a minute. No new dependencies. **HTTP:** - The middleware is a `route_layer` on the protected routes, layered before OIDC so that it runs after authentication and sees the principal. `/health`, `/ready` and Swagger are exempt. - A limited request never reaches the upstream. It gets `429` in OpenAI format (`rate_limit_error` / `rate_limit_exceeded`), or in Anthropic format with `request-id` on `/v1/messages` and `count_tokens`. - Headers: `retry-after`, `retry-after-ms`, `x-ratelimit-limit-requests`, `x-ratelimit-remaining-requests: 0`, and `x-ratelimit-reset-requests`. The last is the time until the full burst returns, formatted like `1.5s` or `2m3s`. **WebSocket:** - The upgrade is charged by the HTTP middleware, which also carries the caller's bucket into the connection. - Each client `response.create` is charged before any lane or byte capacity is reserved. A limited create gets an `error` frame with `status: 429`, and the connection stays open. - `response.steer`, `response.inject` and gateway-started continuations are not charged. The check sits where client messages arrive, not in `WsMultiplexer::schedule`, which also runs automatic continuations. **Structure:** - `rate_limit.rs` holds the limiter, middleware, `429` builder and retry formatting. - `server_settings.rs` resolves the `[server]` table. Its first commit is a pure move of the existing body-size resolution out of `main.rs`, which was at its 644-line exception (now 616). - `ServerConfig` gains `rate_limit`, so `AppState` and its 16 test literals are unchanged. - `auth.rs` is at its line baseline. Its only change is visibility (`AuthErrorFormat` and `for_path`, reused for the 429 format), and `bearer_token` in `auth/api_key.rs` is also now crate-visible. **Scope:** - Per process: with N replicas, a caller can send up to N times the rate. The API, container and Kubernetes docs say so. - Not in this PR: - distributed or token-based quotas (#107, #315); - per-IP keying, which needs trusted-proxy configuration; - `agentic` launcher flags. The launcher's child process inherits the environment variables, and the configuration file is shared. Conflicts: a trial merge with #436, #440 and #420 is clean. ## Test Plan **Unit tests:** - `rate_limit::tests` (paused time): - burst, then one request per interval, including exact `retry_after` and `reset`; - steady state; - independent callers; - pruning before overflow; - credentials kept only as a hash (no token text in `Debug`; bearer and `x-api-key` share a key; `Basic` is anonymous); - retry rounding and `x-ratelimit-reset-requests` formatting; - the burst bound. - `server_settings::tests`: - off by default; - file, then environment, then CLI, including a CLI value over a malformed environment value; - the burst defaulting to the rate; - five invalid inputs, each named in its error; - flag parsing; - the generated `[server]` table. - `config_file` tests: the new keys parse, `0` is rejected, and an unset burst is not written. **`tests/rate_limit_test.rs`** (one request per minute, so the outcomes are deterministic): - `a_caller_over_its_limit_gets_an_openai_429_with_retry_headers`: exact body and all five headers; the limited request never reaches the upstream; another bearer is unaffected. - `callers_without_credentials_share_one_bucket` - `health_endpoints_are_never_limited` - `messages_routes_answer_in_the_anthropic_format_and_key_by_api_key`: exact body; the `request-id` header matches the body. - `rate_limiting_is_off_by_default`: 10 requests and no rate-limit headers. - `websocket_creates_are_charged_and_a_limited_create_keeps_the_connection`: the upgrade and two creates use a burst of 3; the next create gets the exact `429` frame; then `response.steer` is answered on the same connection. - `http_and_websocket_share_a_bucket_and_the_upgrade_is_charged`: a limited upgrade gets HTTP `429` before switching protocols. - `a_websocket_without_credentials_is_not_charged_to_the_server_key` **`oidc_auth_test::rate_limits_key_oidc_callers_by_subject_not_token`:** two tokens for one subject share a bucket, and another subject has its own. **Negative controls** (each applied to the finished code): | Change | Result | | --- | --- | | Never install the HTTP layer | 6 of the 8 integration tests fail; health and off-by-default pass | | Drop the WebSocket charge | Both WebSocket charging tests fail | | Layer the limiter outside OIDC | The OIDC subject test fails | | Off-by-one in the GCRA comparison | 4 unit tests fail | | Disable pruning | The pruning test fails | **Binary smoke test** at 1 request per minute: - `--help` lists both flags. - `AGENTIC_RATE_LIMIT_BURST` without a rate fails at startup: `AGENTIC_RATE_LIMIT_BURST requires AGENTIC_RATE_LIMIT_REQUESTS_PER_MINUTE`. - The first `/v1/models` request reaches the upstream; the second gets `429` with all headers; `/health` still returns `200`. **Gate:** - `cargo fmt -- --check` - `cargo clippy --workspace --all-targets -- -D warnings` - Feature clippy (`--features embedded-code-interpreter`) for both crates - The Rust file-size ratchet - `pre-commit run --all-files` - `mkdocs build --strict` - `cargo test --workspace --no-fail-fast`: 2530 passed, 1 failed. The failure is `tool::web_fetch::http::tests::the_deadline_bounds_a_slow_origin`, which also fails on unmodified `main` when the whole lib suite runs in parallel. --------- Signed-off-by: Zheng Lu <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Responses requests lose
prompt_cache_optionswhen gateway features select typed execution. Add typedmode(implicit/explicit) andttl(30m) preservation across HTTP JSON/SSE, WebSocket, gateway tool rounds, multi-agent execution, and automatic/trigger/standalone compaction.responses.prompt_cache_options_supportedoperator assertion apply only to executor routes.prompt_cache_optionsand legacyprompt_cache_retentionindependently, including when both are supplied. Preserve omission without adding defaults or inheriting top-level options from a previous response.The mode/TTL contract is pinned to openai-python response_create_params.py. Full breakpoint lifecycle qualification, model-specific capability profiles, and upstream cache diagnostics remain follow-ups. Request metadata echoes do not establish cache hits or TTL enforcement.
Part of #330; updates the path matrix tracked by #314.
Test Plan
cargo test --locked --workspace --features agentic-server/openapi --no-fail-fast --quietcargo clippy --locked --all-targets --features agentic-server/openapi -- -D warningsuvx --from pre-commit==4.4.0 pre-commit run --all-files