Skip to content

fix: apply shared tool scheduling limits to Messages - #437

Merged
maralbahari merged 3 commits into
vllm-project:mainfrom
StevenWang-CY:codex/bound-messages-tool-scheduling
Oct 22, 2026
Merged

maralbahari merged 3 commits into
vllm-project:mainfrom
StevenWang-CY:codex/bound-messages-tool-scheduling

Conversation

@StevenWang-CY

@StevenWang-CY StevenWang-CY commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

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.

@maralbahari maralbahari left a comment

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.

Thanks for the fix. I added inline comments

maralbahari pushed a commit that referenced this pull request Oct 20, 2026
## 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.

---------

Signed-off-by: Zheng Lu <[email protected]>
@maralbahari

Copy link
Copy Markdown
Collaborator

@StevenWang-CY are you still maintaining this PR?

…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]>
- Rename GatewaySchedulerPolicy::execution_slots to
  new_round_execution_slots, so both callers show that each inference
  round gets a fresh execution window.
- Describe the materialization permit as shared by the policy and its
  clones; separately constructed policies have independent pools.
- Name the paused-clock test's permit-wait stages with a WaitStage enum
  and include the stage in every assertion message.
- The scheduling harness task returns (); the JSON and SSE assertions
  stay inside their branches.
- README: max_concurrent_gateway_calls bounds Messages rounds as well as
  Responses rounds.

Signed-off-by: Chuyue Wang <[email protected]>
@StevenWang-CY

Copy link
Copy Markdown
Contributor Author

Yes. The branch now merges cleanly with main, and the review comments are addressed:

  • bc168fc merges main (2bbb3cc). The conflicts came from feat: trace and time gateway tools on the Messages path #453, which added a metrics argument to the Messages gateway dispatch where this PR added the scheduling policy; the dispatch now takes both. The traced dispatch resolves the binding, acquires the permits, and then starts the execution timeout, so on Messages the tool stage and the agentic.tool.execute span include permit waits, as they already do on Responses.
  • c80f2af covers the four inline comments: new_round_execution_slots(), the WaitStage enum, JoinHandle<()>, and the materialization-permit doc. It also updates the README comment that limited max_concurrent_gateway_calls to Responses rounds.

On unmodified main the four full-loop scheduling tests fail; on this head the workspace tests, clippy, fmt, and pre-commit pass, and CI is green.

@maralbahari
maralbahari merged commit 65ce386 into vllm-project:main Oct 22, 2026
17 checks passed
haoshan98 added a commit to EmbeddedLLM/agentic-api that referenced this pull request Oct 22, 2026
Brings in vllm-project#437 (shared tool scheduling limits for Messages). The conflict in
GatewayScheduler::execute_all keeps this branch's ordered results and uses
vllm-project#437's GatewaySchedulerPolicy::new_round_execution_slots for the round's
execution slots, here and in gateway/lifecycle.rs, replacing the branch's own
execution_slots helper.

Signed-off-by: haoshan98 <[email protected]>
maralbahari added a commit that referenced this pull request Oct 27, 2026
## Summary

Share JSON/SSE round decisions (continue gateway execution, return
client calls, finish, and client-call `end_turn` correction) and
completed `MessagesToolCall` data with typed argument errors. Parse
streamed arguments once for history and dispatch while keeping malformed
input non-executable.

Rebased on current main (`a7dc7b5`). Reuse its registry bindings and
`GatewaySchedulerPolicy` (#437), preserving model-order budget
admission, permit acquisition/concurrency limits, timeout after permits,
tool-stage timing/error status, and cancellation. Existing ingestion
validation, live delivery, opaque history and usage remain intact.

Follow-up to #431, tracked by #418 ([split
plan](#418 (comment))).
MCP-specific projection and pending-call continuation remain in #425.
Kept as draft for review of this independent refactor.

## Test Plan

- 14 shared synthetic scenarios on JSON and SSE cover
named/client/mixed/truncated rounds, stop reasons, escaped/Unicode
arguments, history and usage.
- Messages unit tests: 71 passed, including all 8 existing
scheduling/lifecycle tests. JSON/SSE, web-fetch and execution-trace
integration targets: 86 passed, including live delivery, cancellation,
invalid streams/arguments and typed tool stages.
- `cargo test --workspace --locked --no-fail-fast`: 2,723 passed, 0
failed, 18 ignored; includes existing HTTP budget/ownership tests and
cassette replays.
- `cargo clippy --workspace --all-targets --locked -- -D warnings`,
formatting, diff checks and all pre-commit 4.4.0 hooks passed.

The first sandboxed unit run could not bind localhost for 4 mock-server
tests; the rerun with local-port access passed all 71. No new recordings
were added. Feature-enabled Linux and PostgreSQL coverage runs in
repository CI.

Signed-off-by: zitian.zhao <[email protected]>
Co-authored-by: Maral <[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.

2 participants