Repository navigation
feat: trace and time gateway tools on the Messages path - #453
Conversation
Gateway-executed built-in tools in the Messages loops now record the same `agentic.tool.execute` span and `tool` stage sample as the Responses executor. Each call that runs is typed by the registry entry that serves it, so an operator alias such as `WebSearch` is recorded as `web_search`. A call that reports a failure, errors, has no handler, or times out is a failed stage (`error.type=tool`). A client disconnect mid-call records `cancelled`. Calls refused at admission (spent `max_uses`, undispatchable arguments) record nothing. Both loops pass `ExecutionContext::metrics` into `execute_gateway_calls`. `web_fetch` joins the documented and test-enforced `agentic.tool.type` values, because Messages `web_fetch` calls now emit it. Closes vllm-project#449 Signed-off-by: Zheng Lu <[email protected]>
69fab19 to
5acc487
Compare
| &mut context(), | ||
| &no_op_registry().await, | ||
| &tool_seam::GatewayToolMap::default(), | ||
| &crate::executor::telemetry::metrics::ExecutorMetrics::from_global(), |
There was a problem hiding this comment.
nit: use on top file import for crate::executor::telemetry::metrics:
There was a problem hiding this comment.
Done in f3d9c85. The test module now imports ExecutorMetrics at the top.
| .await | ||
| .unwrap(); | ||
| let client = tokio::spawn(response.body.collect::<Vec<_>>()); | ||
| arrived.notified().await; |
There was a problem hiding this comment.
Could we put a timeout around arrived.notified().await, ideally also detecting early completion of client? If tool classification or dispatch regresses and the search endpoint is never reached, this notification never fires—even if the consumer has already finished or panicked. The test then hangs instead of reporting the regression. The existing metrics harness uses a five-second deadline for similar synchronization.
There was a problem hiding this comment.
Yes, we can. The wait is now a select! over three outcomes:
- the search arriving;
- the client task finishing first, which panics with the frames it received;
- a five-second deadline, matching the metrics harness.
I checked it against the regression you described by temporarily short-circuiting dispatch for web_search, so the search endpoint is never reached. The new test failed within seconds with "the stream ended before the search started: Ok([... "event: error" ...])". With the old bare notified().await, the same regression hung until I killed it after 60 seconds.
| Hangs(Arc<tokio::sync::Notify>), | ||
| } | ||
|
|
||
| pub async fn search_server(search: Search) -> (String, tokio::task::JoinHandle<()>) { |
There was a problem hiding this comment.
This generalizes the existing search_server() in execution_metrics_test.rs:385; Search::Answers serves the same route and payload. Could we switch the existing Responses test to this shared helper and remove the old function? That would leave one implementation of the search backend fixture.
There was a problem hiding this comment.
Done in f3d9c85. Search/search_server now live in tests/support, and both older copies are gone:
- the Responses test in
execution_metrics_test.rsnow usessearch_server(Search::Answers); execution_trace/stages.rshad a third copy, which I removed as well.
The shared result keeps the trace copy's title, "private search result", because the stage-tree test uses it as a privacy fixture.
| } | ||
|
|
||
| /// The model's final text turn. | ||
| pub fn final_round(stream: bool) -> MockResponse { |
There was a problem hiding this comment.
final_round() duplicates messages_json_response("end_turn") and messages_sse_response("end_turn") in execution_trace_test.rs. Could we move those builders into shared support, retaining their configurable stop reason, and reuse them here? That would avoid maintaining another copy of the same Messages envelope and SSE lifecycle.
There was a problem hiding this comment.
Done in f3d9c85. messages_json_response(stop_reason) and messages_sse_response(stop_reason) moved from execution_trace_test.rs into tests/support, together with the SSE framing and the message_start event they share. The trace tests call them unchanged. final_round(stream) is now a two-branch switch over them, and tool_round reuses the same framing and start event, so the fixture module no longer has its own copy of the envelope or the SSE lifecycle.
Review follow-ups: - One search backend: `Search`/`search_server` move to tests/support. They replace the copies in execution_metrics_test.rs and execution_trace/stages.rs (the result keeps its privacy-fixture title). - One set of Messages turn builders: `messages_json_response` and `messages_sse_response` (configurable stop reason) and their SSE framing move to tests/support. They replace the trace test's copies, and `final_round` now reuses them. - The cancellation test waits for the search with a five-second deadline and fails if the stream ends first. A dispatch regression used to hang it instead. - Import ExecutorMetrics at the top of the messages_stream tests. Signed-off-by: Zheng Lu <[email protected]>
…tool-scheduling Main's Messages tracing change (vllm-project#453) added a metrics argument to the Messages gateway dispatch where this branch added the scheduling policy; both arguments are kept. The traced dispatch now resolves the binding, acquires the shared permits, and then applies the execution timeout, so the tool stage and the agentic.tool.execute span include permit waits, as they already do for the Responses scheduler. Signed-off-by: Chuyue Wang <[email protected]>
## Summary Messages tool rounds currently dispatch every admitted call directly, bypassing `tools.max_concurrent_gateway_calls`, the handler's same-tool exclusion, and the execution context's shared materialization window. For example, a four-call round starts all four handlers even when the configured execution limit is two. Apply the same permit-acquisition path to Responses and both Messages loops. Resolve aliases to their typed binding, acquire same-tool exclusion before round capacity, and start the execution timeout after all permits are acquired. Preserve admission decisions, failure outputs, and model-order results; completion refills available slots, and cancellation drops active and waiting calls without spawning work. On the Messages path, the `tool` stage and `agentic.tool.execute` span from #453 therefore include permit waits, as they already do for Responses. Advances the bounded scheduling work in #313 and Enterprise Readiness #316. Document the scope: active executions are bounded; aggregate Messages content, retained output, and pending-call limits remain follow-up work under #313. ## Test Plan - On unmodified `main` (2bbb3cc), the four full-loop scheduling tests fail: execution-window overflow, per-round windows, overlapping aliases of an exclusive handler, and bypassed shared materialization capacity. - Eight new tests pass. Complete JSON/SSE loops cover 4- and 40-call fan-out, refill while the first call remains blocked, ordered results in the next inference request, independent round windows, alias exclusion, shared capacity, and cancellation. Paused-clock tests cover every permit-wait stage, execution timeout, permit recovery, failure status, and unexecuted calls under saturation. - Six mutants of the scheduling path are each caught: no permits, a timeout that includes permit waits, a missing handler that waits for a slot, a window per call, one window shared across requests, and a round slot taken before same-tool exclusion (caught by the existing Responses scheduler test). - `cargo test --workspace --locked` at c80f2af: 2690 passed, 0 failed, including the Messages/Responses cassette replay, trace, metrics, and transport tests. Eighteen existing tests remain ignored (14 PostgreSQL qualification tests, two manual scaling measurements, one multi-agent recording comparison, and one documentation example). - `cargo clippy --workspace --all-targets --locked -- -D warnings`, `cargo fmt --all -- --check`, and `pre-commit run --all-files` (including the Rust file-size check): passed. No new recordings or live inference were used: this changes internal scheduling, while existing recorded scenarios exercise wire compatibility. Synthetic test responses control concurrency deterministically and are not presented as captured cassettes. --------- Signed-off-by: Chuyue Wang <[email protected]>
Summary
Closes #449, the follow-up to departure 4 in #375. Gateway-executed built-in tools in the Messages loops now record the same telemetry as the Responses executor:
agentic.tool.executespan underagentic.execute, between the two inference rounds, withagentic.tool.typeas its only attribute.toolsample inagentic.stage.duration.registry.tool_type(&call.name)), never from the model-supplied name. An operator alias such as Claude Code'sWebSearchis therefore recorded asweb_search.error.type=tool. A client disconnect while a call runs recordscancelled, because the stage timer's drop handles it.max_usesbudget, or undispatchable arguments) records neither a span nor a sample.messages_tools::runnow delegates the dispatch todispatch, which carries#[tracing::instrument]. Both loops pass&exec_ctx.metricsintoexecute_gateway_calls.web_fetchvalue.stages::tool_typealready mappedWebFetchtoweb_fetch, but nothing emitted that value until now. It is added to the documented values and to both test allowlists,execution_metrics/harness.rsandexecution_traces/attributes.rs. The newweb_fetchtest failed on the metrics allowlist before this addition.docs/deploying/observability.mddrops "not timed yet" and says which stages cover the Messages executor.Overlap with #437
#437 rewrites the same
run. Both PRs append a trailing parameter toexecute_gateway_callsand its callers, so a trial merge conflicts mechanically in 4 files:messages_tools.rsmessages_loop.rsmessages_stream.rsmessages_stream/blocks.rsThe resolution keeps both parameters. #437's binding lookup, permit wait and
binding.executemove intodispatch, so the span and timer also cover the permit wait. Responses'run_onealready behaves that way. Whichever PR lands second rebases; I'm happy to do it.Test Plan
New tests:
execution_trace/messages_tools.rs:messages_{loop,stream}_gateway_tool_is_a_typed_stage_between_rounds.web_searchundermax_uses: 1, with two calls.agentic.tool.executespan with typeweb_search, parented toagentic.executeand placed between round 0 and round 1.execution_metrics_test.rs, each in both stream modes unless noted:messages_gateway_tool_times_only_the_admitted_call: onetoolsample of typeweb_search, no failure.messages_gateway_tool_failure_is_a_failed_tool_stage: the search backend returns 500, givingerror.type=tool, and the execution still completes.messages_aliased_gateway_tool_is_typed_by_the_executor_that_serves_it:WebSearchis recorded asweb_search.messages_web_fetch_is_a_web_fetch_tool_stage(JSON mode only).messages_stream_dropped_while_a_gateway_tool_runs_cancels_its_stage(stream mode only): the search hangs, then the client is aborted, givingerror.type=cancelled.Results:
RED on
634899a. The trace tests fail becauseagentic.tool.executenever closes, although both rounds ran. The metrics tests see 0toolsamples.GREEN with this change.
Negative controls. Each regression below was applied to the fix and was caught:
Gate:
cargo fmt -- --checkcargo clippy --workspace --all-targets -- -D warnings--features embedded-code-interpreter) foragentic-server-coreandagentic-serverpre-commit run --all-filesmkdocs build --strictcargo test --workspace --no-fail-fast: 2348 passed, 1 failed. The failure istool::web_fetch::http::tests::the_deadline_bounds_a_slow_origin. It also fails on unmodified634899aon my machine when the whole lib suite runs in parallel: 1.24 s against its 1 s bound, while its origin sleeps 2 s. It passes 5 out of 5 runs in isolation. It's a load-sensitive wall-clock bound in code this PR doesn't touch.