Skip to content

feat: trace and time gateway tools on the Messages path - #453

Merged
maralbahari merged 2 commits into
vllm-project:mainfrom
Zheng-Lu:feat/449-messages-tool-telemetry
Oct 20, 2026
Merged

maralbahari merged 2 commits into
vllm-project:mainfrom
Zheng-Lu:feat/449-messages-tool-telemetry

Conversation

@Zheng-Lu

Copy link
Copy Markdown
Contributor

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:

  • Span. Each call that runs opens an agentic.tool.execute span under agentic.execute, between the two inference rounds, with agentic.tool.type as its only attribute.
  • Stage sample. Each call that runs records one tool sample in agentic.stage.duration.
  • Type source. The type comes from the registry entry that serves the call (registry.tool_type(&call.name)), never from the model-supplied name. An operator alias such as Claude Code's WebSearch is therefore recorded as web_search.
  • Failures. A call that reports a failure, returns an error, has no handler, or times out is a failed stage, error.type=tool. A client disconnect while a call runs records cancelled, because the stage timer's drop handles it.
  • Refused calls. A call refused at admission (spent max_uses budget, or undispatchable arguments) records neither a span nor a sample.
  • Plumbing. messages_tools::run now delegates the dispatch to dispatch, which carries #[tracing::instrument]. Both loops pass &exec_ctx.metrics into execute_gateway_calls.
  • web_fetch value. stages::tool_type already mapped WebFetch to web_fetch, but nothing emitted that value until now. It is added to the documented values and to both test allowlists, execution_metrics/harness.rs and execution_traces/attributes.rs. The new web_fetch test failed on the metrics allowlist before this addition.
  • Docs. docs/deploying/observability.md drops "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 to execute_gateway_calls and its callers, so a trial merge conflicts mechanically in 4 files:

  • messages_tools.rs
  • messages_loop.rs
  • messages_stream.rs
  • messages_stream/blocks.rs

The resolution keeps both parameters. #437's binding lookup, permit wait and binding.execute move into dispatch, so the span and timer also cover the permit wait. Responses' run_one already 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.
    • Native web_search under max_uses: 1, with two calls.
    • Checks for exactly one agentic.tool.execute span with type web_search, parented to agentic.execute and placed between round 0 and round 1.
    • The stream is drained from an unrelated task.
    • The model's queries never appear on a span.
  • execution_metrics_test.rs, each in both stream modes unless noted:
    • messages_gateway_tool_times_only_the_admitted_call: one tool sample of type web_search, no failure.
    • messages_gateway_tool_failure_is_a_failed_tool_stage: the search backend returns 500, giving error.type=tool, and the execution still completes.
    • messages_aliased_gateway_tool_is_typed_by_the_executor_that_serves_it: WebSearch is recorded as web_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, giving error.type=cancelled.

Results:

  • RED on 634899a. The trace tests fail because agentic.tool.execute never closes, although both rounds ran. The metrics tests see 0 tool samples.

  • GREEN with this change.

  • Negative controls. Each regression below was applied to the fix and was caught:

    Regression Caught by
    Type taken from the model-supplied name Alias test
    Refused call timed Admitted-call test and failure test
    Refused call traced Both trace tests
    Failure not labelled Failure test
    Timer started after the dispatch Cancellation test

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: 2348 passed, 1 failed. The failure is tool::web_fetch::http::tests::the_deadline_bounds_a_slow_origin. It also fails on unmodified 634899a on 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.

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]>
@Zheng-Lu
Zheng-Lu force-pushed the feat/449-messages-tool-telemetry branch from 69fab19 to 5acc487 Compare October 16, 2026 08:58
&mut context(),
&no_op_registry().await,
&tool_seam::GatewayToolMap::default(),
&crate::executor::telemetry::metrics::ExecutorMetrics::from_global(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: use on top file import for crate::executor::telemetry::metrics:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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<()>) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in f3d9c85. Search/search_server now live in tests/support, and both older copies are gone:

  • the Responses test in execution_metrics_test.rs now uses search_server(Search::Answers);
  • execution_trace/stages.rs had 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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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]>
@Zheng-Lu
Zheng-Lu requested a review from maralbahari October 19, 2026 16:45
@maralbahari
maralbahari merged commit c48c9f1 into vllm-project:main Oct 20, 2026
17 checks passed
@Zheng-Lu
Zheng-Lu deleted the feat/449-messages-tool-telemetry branch October 20, 2026 20:07
StevenWang-CY added a commit to StevenWang-CY/agentic-api that referenced this pull request Oct 22, 2026
…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]>
maralbahari pushed a commit that referenced this pull request Oct 22, 2026
## 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]>
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.

feat(telemetry): trace and time gateway-executed built-in tools on the Messages path

2 participants