Repository navigation
feat: preserve service_tier across Responses execution - #389
Conversation
Signed-off-by: zitian zhao <[email protected]>
Signed-off-by: zitian zhao <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Repeated lenient terminal events can double-charge tier memory and incorrectly exhaust response budgets.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Preserves requested and actual service_tier values throughout Responses execution, persistence, streaming, tool rounds, and compaction.
Changes:
- Adds typed request, upstream, event, and response tier fields.
- Propagates final-round tiers through storage and streaming.
- Adds regression tests, documentation, and memory-budget accounting.
| File | Description |
|---|---|
.rust-file-sizes.json |
Updates reduced file-size baselines. |
docs/api/index.md |
Documents tier forwarding and inheritance semantics. |
crates/agentic-server/tests/responses_websocket_test.rs |
Tests WebSocket tier behavior. |
crates/agentic-server/tests/responses_test.rs |
Tests HTTP, SSE, storage, and continuation behavior. |
crates/agentic-server-core/tests/web_search_tool_test.rs |
Tests tier forwarding across tool rounds. |
crates/agentic-server-core/tests/support/mod.rs |
Updates request fixtures. |
crates/agentic-server-core/tests/execution_trace_test.rs |
Updates trace test fixtures. |
crates/agentic-server-core/tests/event_normalizer_test.rs |
Adapts event payload matching. |
crates/agentic-server-core/tests/dispatch_loop_cassette_test.rs |
Updates cassette request fixtures. |
crates/agentic-server-core/src/types/request_response/schema.rs |
Extracts OpenAPI schemas and adds the tier field. |
crates/agentic-server-core/src/types/request_response.rs |
Adds request, upstream, and response tier types. |
crates/agentic-server-core/src/storage/types/response.rs |
Updates stored-response fixtures. |
crates/agentic-server-core/src/executor/upstream.rs |
Updates upstream test fixtures. |
crates/agentic-server-core/src/executor/response_budget.rs |
Accounts for retained tier memory. |
crates/agentic-server-core/src/executor/rehydrate.rs |
Updates rehydration fixtures. |
crates/agentic-server-core/src/executor/persist.rs |
Boxes recursive persistence execution. |
crates/agentic-server-core/src/executor/modes/response.rs |
Updates response-mode fixtures. |
crates/agentic-server-core/src/executor/modes/conversation.rs |
Updates conversation fixtures. |
crates/agentic-server-core/src/executor/engine/streaming.rs |
Initializes tier on synthetic failures. |
crates/agentic-server-core/src/executor/engine/execute.rs |
Boxes recursive executor execution. |
crates/agentic-server-core/src/executor/engine.rs |
Returns compaction-trigger inference tiers. |
crates/agentic-server-core/src/executor/compaction.rs |
Forwards tiers into compaction inference. |
crates/agentic-server-core/src/executor/accumulator/tests.rs |
Tests final-round tier selection. |
crates/agentic-server-core/src/executor/accumulator/terminal.rs |
Extracts terminal assembly and retains tiers. |
crates/agentic-server-core/src/executor/accumulator/mod.rs |
Tracks tiers during JSON and SSE ingestion. |
crates/agentic-server-core/src/executor/accumulator/json.rs |
Validates strict JSON tier values. |
crates/agentic-server-core/src/executor/accumulator/budget_tests.rs |
Tests tier budget boundaries. |
crates/agentic-server-core/src/events/validate.rs |
Validates streamed tier types. |
crates/agentic-server-core/src/events/types.rs |
Adds tiers to response events. |
crates/agentic-server-core/src/events/normalize.rs |
Extracts tiers from upstream events. |
crates/agentic-server-core/benches/executor_throughput.rs |
Updates benchmark fixtures. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if let Some(service_tier) = &service_tier | ||
| && let Some(budget) = &self.budget | ||
| { | ||
| budget.consume(RETAINED_CONTAINER_OVERHEAD_BYTES + service_tier.len())?; |
There was a problem hiding this comment.
Tier accounting now uses RetainedAccount::reconcile, so repeated terminal snapshots and smaller replacement values do not charge the same retained memory again. The regression also covers null tiers and rejects growth beyond the response budget without replacing the retained value.
| conversation_id: ctx.conversation_id.clone(), | ||
| instructions, | ||
| instructions: ctx.enriched_request.instructions.clone(), | ||
| service_tier, |
There was a problem hiding this comment.
Both blocking and streaming compaction-trigger tests now request priority, verify it reaches summary inference, and assert that the final response returns the upstream default tier. All 788 core tests pass (5 existing tests ignored), along with Clippy and all pre-commit hooks.
Signed-off-by: zitian zhao <[email protected]>
Signed-off-by: zitian zhao <[email protected]>
haoshan98
left a comment
There was a problem hiding this comment.
Thanks for the contribution. I leave the comments inline.
| /// Request body accepted by `POST /v1/responses/compact`. | ||
| #[derive(Debug, Clone, Deserialize)] | ||
| #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] | ||
| pub struct CompactRequest { |
There was a problem hiding this comment.
CompactRequest has no service_tier, so /v1/responses/compact drops it both ways
RequestPayload gained service_tier, but CompactRequest only types model, input, instructions and previous_response_id. Any other field lands in the #[serde(flatten)] compatibility map, which nothing reads. compact_response then builds its inference request with request_payload(..), which hard-codes service_tier: None, and throws away the returned tier (let (output, usage, _) = ...). CompactedResponse has no field for it either.
The PR does forward the tier on the other two compaction paths: automatic compaction and compaction_trigger. Only the standalone endpoint misses it.
OpenAI's POST /v1/responses/compact does accept service_tier in the body. Its reference says: "When the service_tier parameter is set, the response body will include the service_tier value based on the processing mode actually used to serve the request." (It also accepts prompt_cache_key, which the gateway drops the same way; that gap predates this PR -- can solve this in a following PR)
Suggested Fix: add #[serde(default)] service_tier: Option<String> to CompactRequest, set payload.service_tier in compact_response, and return the tier from compact_items_with_trigger on CompactedResponse (skip_serializing_if = "Option::is_none"). Add a /compact test for both directions. Or, if this is out of scope, say in docs/api/index.md that /compact does not forward the tier yet and track it under #330.
There was a problem hiding this comment.
CompactRequest now types service_tier, standalone compaction forwards it to summary inference, and CompactedResponse returns the upstream tier when present. The endpoint regression requests priority and receives default; another test covers omitted/null request values and a missing upstream tier, including when priority was requested.
This belongs in the current PR because standalone compaction should follow the same tier contract as automatic compaction and compaction_trigger. I checked those paths as well. The existing prompt_cache_key gap is separate and remains outside this PR.
| previous_response_id: pipeline.request.original_request.previous_response_id.clone(), | ||
| conversation_id: pipeline.request.conversation_id.clone(), | ||
| instructions: pipeline.request.original_request.instructions.clone(), | ||
| service_tier: None, |
There was a problem hiding this comment.
Multi-agent responses never return service_tier
The merge of main brought in MultiAgentRun (#373). The request side works: agents clone the root enriched_request, so every agent round sends the requested tier upstream. The response side does not. MultiAgentRun builds its final payload with service_tier: None. complete_round adds each round's usage, and when a root round ends abnormally (upstream terminal or incomplete) it also copies that round's status and error. It never copies the tier; the round's payload, tier included, is dropped when complete_round returns. JSON responses, the terminal SSE event and the stored snapshot all come out without service_tier. OpenAI does return it for the same flows: the recorded reference streams in tests/cassettes/multi_agent/ show "auto" on response.created and "default" on the terminal event. The PR summary's "return and store the tier reported by the final inference round" does not hold on this path. The PR did thread the tier through multi-agent compaction (multi_agent/compaction.rs), which makes the gap look like an oversight rather than a choice.
There was a problem hiding this comment.
Each completed root inference round now replaces the response-level tier, including clearing an earlier value when the latest round omits it. Child rounds do not overwrite it: the root controls the response-level outcome, and using whichever child finishes last would make the returned tier depend on scheduling.
The regression covers JSON and terminal SSE responses, different root/child tiers, a missing final root tier, and completed, failed, and incomplete root outcomes. Stored snapshots are checked for completed/incomplete responses; failed responses retain the existing policy of not being stored.
Signed-off-by: zitian zhao <[email protected]>
Signed-off-by: zitian zhao <[email protected]>
## Summary Standalone `/v1/responses/compact` currently accepts `prompt_cache_key` as an unmodeled compatibility field and drops it before summary inference. Type the field and forward it through the existing compaction path. The key remains request-scoped: omitted or null values are not inherited from `previous_response_id`. Invalid types return 400 before inference. Update the API docs to include the standalone endpoint. Part of #330. Follows #347 and #389. ## Test Plan - `cargo test --offline -p agentic-server --test compaction_test --quiet` — 11 passed, including explicit/empty, omitted/null, invalid, and stored-history cache-key cases. - `cargo test --offline -p agentic-server --test openapi_test --quiet` - `cargo clippy --offline --all-targets -- -D warnings` - All pre-commit hooks. Signed-off-by: zitian zhao <[email protected]>


Summary
Preserve the requested
service_tierthrough Responses execution, including HTTP, WebSocket, tool rounds, and both standalone and internal compaction calls.Return and store the tier reported by the final inference round, which may differ from the requested tier. Omitted or null request values are not inherited by continuations, and a missing final response tier is not filled from an earlier round.
Include the retained tier in response memory limits without charging repeated terminal snapshots twice. Document these semantics and keep the existing file-size limits.
Multi-agent responses use the last root inference round's tier; child tiers do not override it.
Part of #330.
Test Plan
cargo clippy --offline --all-targets -- -D warningspassed.