Skip to content

feat(mesh): charge non-streaming single-worker prefill, release on the KV event - #3861

Open
MengqingCao wants to merge 1 commit into
mengqing/mesh-prefill-streaming-chargefrom
mengqing/mesh-prefill-nonstreaming-charge
Open

MengqingCao wants to merge 1 commit into
mengqing/mesh-prefill-streaming-chargefrom
mengqing/mesh-prefill-nonstreaming-charge

Conversation

@MengqingCao

Copy link
Copy Markdown
Contributor

Motivation

A non-streaming single-worker request charged no prefill: the router sees no end of prefill before the response, which comes after decoding. A worker prefilling a 32K-token prompt for such a request looked idle to agentic. Second of the two follow-ups promised in #3481 (Jasen2201's review); the release follows llm-d-router#3975 rather than polling atom:dp_queued_prefill_tokens.

Summary

  • The planner charges a single-worker prompt whether or not it streams.
  • KvEventMonitor::watch_prefill registers a non-streaming request's charge on the selected url@rank's KV event lane, keyed by the router's prefix hash of the prompt's last full block (ATOM's BlockStored carries no request id). HTTP, ext-proc and gRPC register it.
  • The index writer releases one watch per stored block, oldest first, and skips charges the first byte already released. A released lane drops its watches; the sweep prunes watches whose guard is gone; registration holds the subscription's map entry, so a lane cannot be released and reused mid-register.
  • The first byte stays the fallback: a cached repeat, a prompt shorter than a block, a rank the engine chose, a media prompt, a worker with no KV event subscription. gRPC single workers have none today (FollowKvEventsStep follows HTTP workers), so their non-streaming requests release at the response.
  • docs/agentic_cost.md and the metric help no longer list an uncharged single-worker path.

Known limits, not covered by tests: a queued older event or a decode block with the same key can release a watch early, and a longer in-flight prompt sharing the watched block can release a shorter prompt's watch.

Requires the previous PR (ext-proc and gRPC streaming charge).

Test plan

  • cargo fmt --check; cargo test --lib --features atom-engine (1442 passed); cargo check --features ext-proc --tests; cargo test --tests; mocker test_atomesh_harness; cargo +1.94.0 test --lib (1435 passed)
  • cargo test --lib --features atom-engine,ext-proc -- prefill (85 passed); cargo test --features ext-proc --test ext_proc_tests -- prefill (2 passed)
  • KV-event release, first-byte fallback and error release per path (HTTP, ext-proc, gRPC); new tests fail with the watch calls, the released-charge skip or the lane cleanup reverted
  • Python harnesses (tests/test_atomesh_*, 6 modules) pass
  • MI355X DPA run with agentic prefill and non-streaming traffic

🤖 Generated with Claude Code

@MengqingCao
MengqingCao added this pull request to stack #3569 November 25, 2026 14:43
…e KV event

A non-streaming single-worker request charged no prefill, so agentic saw a
worker prefilling a long prompt as idle until the response ended.

- The planner charges a single-worker prompt whether or not it streams.
- KvEventMonitor::watch_prefill registers a non-streaming request's charge on
  the selected rank's lane, keyed by the prefix hash of the prompt's last full
  block; called on HTTP, ext-proc and gRPC.
- The index writer releases one watch per stored block, oldest first, and
  skips charges the first byte already released; a released lane drops its
  watches and the sweep prunes watches whose guard is gone. Registration holds
  the subscription's map entry, so a lane cannot be released and reused
  mid-register.
- The first byte stays the fallback: cached repeats, sub-block prompts and
  workers without a KV event subscription (gRPC single workers today).
- docs/agentic_cost.md and the mesh_worker_prefill_tokens help no longer list
  an uncharged single-worker path.

Co-Authored-By: Claude <noreply@anthropic.com>
@MengqingCao
MengqingCao removed this pull request from stack #3569 November 27, 2026 01:51
@MengqingCao
MengqingCao force-pushed the mengqing/mesh-prefill-nonstreaming-charge branch from f347684 to dfa18d5 Compare November 27, 2026 01:51
@MengqingCao
MengqingCao added this pull request to stack #3917 November 27, 2026 01:51

This branch has not been deployed

No deployments
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.

1 participant