[GH-ISSUE #4596] [Engine] replicas: several agents with the same system prompt all queue on one card and the other idles #2081

Closed
opened 2026-11-04 01:56:30 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @liangzelong on GitHub (Oct 29, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4596

Area

[Engine] (speed, kernels, models, the server and API)

Desktop app, Terminal or source?

Source (START-HERE.bat, setup.sh or a build)

Strata version

0.2.7 (engine 0.1.53, source checkout at 46c152a1)

Graphics card, memory and system

2x NVIDIA GeForce RTX 4090 (24 GB each), 197 GiB RAM, Linux 6.18.33.1-microsoft-standard-WSL2 (WSL2), Intel Xeon Platinum 8370C (64 cores, 128 threads)

Model, size and settings

Qwen3.8-Flash-Next UD-Q4_K_XL (unsloth), 262,144-token context, images on

What happened

Several agents at once — a multi-agent task, or two sessions of the same agent framework — send the same system prompt
and the same tool schemas, so their prompts share a long prefix. With "replicas" they all end up on the same card: the
requests queue there one after another, and the other card stays at 0% and never answers them.

The two ways we hit it:

  • A multi-agent task. The captain and its members run with the same system prompt and the same tools, so every
    member's request wants the same card.
  • Two separate sessions of the same framework. The sessions differ in the message, not in the system prompt and
    the tools: two sessions that ask for very little ("a pelican riding a bicycle" and "a pelican riding a motorcycle")
    have prompts that differ only in their last few tokens, so their requests want the same card again.

The replica is chosen when the request arrives, and the request then waits on that card's lock. The cost that decides
it is

cost(card) = (prompt tokens the card would have to read again) + LOAD_TOKENS * (requests running on that card)

The first term is counted in prompt tokens and the second in requests, and the shared system prompt of an agent session
is around 19,500 tokens. The prefix bookkeeping credits the replica that served a prompt, and a prompt's prefix is
hashed from its first token, so the shared part of every session is credited to one card and to no other.

Two requests then behave like this:

  • While the other card is free, the second one goes there only when LOAD_TOKENS is larger than the shared prefix
    (19,500): with the default 3,000 the prefix wins and the request queues on the card that holds it. A larger constant
    does move it, but only while the other card is free.
  • When both cards are busy, the load term is the same on both and the prefix decides again, so the requests queue on
    the card that holds the prefix whatever the constant is.

So no constant fixes it: the decision is made once, when the request arrives, and is not made again.

On our box the second request had its whole prompt already cached (544 tokens read) and still waited 60 seconds for its
first token, because it was queued behind the other agent's turn on that card.

Smallest steps or command that reproduce it

  1. A run config with "replicas": 2, "parallel": 1, "gpu": [0, 1].
  2. Two sessions of one agent framework, in the same workspace. Give one a short message ("a pelican riding a
    bicycle") and the other another ("a pelican riding a motorcycle"), and send both at the same time. The two prompts
    differ only in their last few tokens; the system prompt and the tools are the same.
    A multi-agent task of the same framework does the same on its own, with the captain and every member.
  3. GET /metrics and read live.replicas: the routed counts are lopsided and one card stays at 0%.

Reproduction status

Reproduced locally

Evidence

GET /metrics:

"replicas": [
  {"replica": 0, "alive": true, "running": 2, "routed": 12, "batch": 0},
  {"replica": 1, "alive": true, "running": 0, "routed": 1, "batch": 0}
]

The two cards, same moment: GPU0 at 96% (163 W), GPU1 at 0% (18 W).

One request from that window:

total=19491  reused=18947  read=544  first_engine_token_s=59.974  duration_s=129.1  finish=stop

Its prompt was already cached (544 tokens read, about a second of prefill) and it still waited 60 seconds for the
first token: it was queued behind the other agent's turn on that card. The engine log of the card it waited on shows
that turn running for the same time.

Note on the shared prefix

The engine already tells the shared part of a prompt from a conversation's own part: deepseek_shared_start
(serve/server.py) counts the leading system and developer messages and pins a checkpoint there, and strata_prefix
lets a client declare a shared read-only prefix that the engine keeps pinned. The replica router sees only token ids
and hashes the prompt from its first token, so it cannot tell the two apart.

A fix is in progress; the approach and a pull request will follow in this thread.

Originally created by @liangzelong on GitHub (Oct 29, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4596 ### Area [Engine] (speed, kernels, models, the server and API) ### Desktop app, Terminal or source? Source (START-HERE.bat, setup.sh or a build) ### Strata version 0.2.7 (engine 0.1.53, source checkout at 46c152a1) ### Graphics card, memory and system 2x NVIDIA GeForce RTX 4090 (24 GB each), 197 GiB RAM, Linux 6.18.33.1-microsoft-standard-WSL2 (WSL2), Intel Xeon Platinum 8370C (64 cores, 128 threads) ### Model, size and settings Qwen3.8-Flash-Next UD-Q4_K_XL (unsloth), 262,144-token context, images on ### What happened Several agents at once — a multi-agent task, or two sessions of the same agent framework — send the same system prompt and the same tool schemas, so their prompts share a long prefix. With `"replicas"` they all end up on the same card: the requests queue there one after another, and the other card stays at 0% and never answers them. The two ways we hit it: - **A multi-agent task.** The captain and its members run with the same system prompt and the same tools, so every member's request wants the same card. - **Two separate sessions of the same framework.** The sessions differ in the message, not in the system prompt and the tools: two sessions that ask for very little ("a pelican riding a bicycle" and "a pelican riding a motorcycle") have prompts that differ only in their last few tokens, so their requests want the same card again. The replica is chosen when the request arrives, and the request then waits on that card's lock. The cost that decides it is cost(card) = (prompt tokens the card would have to read again) + LOAD_TOKENS * (requests running on that card) The first term is counted in prompt tokens and the second in requests, and the shared system prompt of an agent session is around 19,500 tokens. The prefix bookkeeping credits the replica that served a prompt, and a prompt's prefix is hashed from its first token, so the shared part of every session is credited to one card and to no other. Two requests then behave like this: - While the other card is free, the second one goes there only when `LOAD_TOKENS` is larger than the shared prefix (19,500): with the default 3,000 the prefix wins and the request queues on the card that holds it. A larger constant does move it, but only while the other card is free. - When both cards are busy, the load term is the same on both and the prefix decides again, so the requests queue on the card that holds the prefix whatever the constant is. So no constant fixes it: the decision is made once, when the request arrives, and is not made again. On our box the second request had its whole prompt already cached (544 tokens read) and still waited 60 seconds for its first token, because it was queued behind the other agent's turn on that card. ### Smallest steps or command that reproduce it 1. A run config with `"replicas": 2, "parallel": 1, "gpu": [0, 1]`. 2. Two sessions of one agent framework, in the same workspace. Give one a short message ("a pelican riding a bicycle") and the other another ("a pelican riding a motorcycle"), and send both at the same time. The two prompts differ only in their last few tokens; the system prompt and the tools are the same. A multi-agent task of the same framework does the same on its own, with the captain and every member. 3. `GET /metrics` and read `live.replicas`: the `routed` counts are lopsided and one card stays at 0%. ### Reproduction status Reproduced locally ### Evidence `GET /metrics`: ```json "replicas": [ {"replica": 0, "alive": true, "running": 2, "routed": 12, "batch": 0}, {"replica": 1, "alive": true, "running": 0, "routed": 1, "batch": 0} ] ``` The two cards, same moment: GPU0 at 96% (163 W), GPU1 at 0% (18 W). One request from that window: ``` total=19491 reused=18947 read=544 first_engine_token_s=59.974 duration_s=129.1 finish=stop ``` Its prompt was already cached (544 tokens read, about a second of prefill) and it still waited 60 seconds for the first token: it was queued behind the other agent's turn on that card. The engine log of the card it waited on shows that turn running for the same time. ### Note on the shared prefix The engine already tells the shared part of a prompt from a conversation's own part: `deepseek_shared_start` (`serve/server.py`) counts the leading system and developer messages and pins a checkpoint there, and `strata_prefix` lets a client declare a shared read-only prefix that the engine keeps pinned. The replica router sees only token ids and hashes the prompt from its first token, so it cannot tell the two apart. A fix is in progress; the approach and a pull request will follow in this thread.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 29, 2026):

Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:

  • Fill in "Area".
  • Fill in "Strata version".
  • Fill in "Graphics card, memory and system".

Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment /reopen.

Details: CONTRIBUTING.md

<!-- gh-comment-id:6494730107 --> @github-actions[bot] commented on GitHub (Oct 29, 2026): Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing: - [ ] Fill in "Area". - [ ] Fill in "Strata version". - [ ] Fill in "Graphics card, memory and system". Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`. Details: [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@github-actions[bot] commented on GitHub (Oct 29, 2026):

Thanks, this follows the format now.

<!-- gh-comment-id:6494829363 --> @github-actions[bot] commented on GitHub (Oct 29, 2026): Thanks, this follows the format now.
Author
Owner

@liangzelong commented on GitHub (Oct 29, 2026):

My view: the two modes want opposite things

The replica router copies the split one, and I think that is the root of it.

A layer split puts one model over several cards and the cards cooperate on one stream. The conversation's KV is
spread over them by layer, so there the router's job is to keep a conversation on the same cards and to read as little
of it again as possible: the reuse comes first.

Replicas run a complete model on every card, and every card serves its own conversations. The shared part of a
prompt — the system instructions and the tool schemas — can be copied to every card, and a conversation's own history
is kept on the one card that holds it. So here the order is the other way round: use every card first, and keep the
reuse inside a card.

A router that pins every request of a framework to the replica that first read its shared prefix leaves one card doing
the work and the others idle. That is the split behaviour with more overhead, not the data-parallel one: the cards are
not spread over the conversations, they are waiting for them.

Copying the shared part to a second card costs one more read there. It buys two cards working at the same time, and
the conversations of a framework spread over both.

What I would do: hand out a card when it has a free slot

Give a request to a replica when it has a free slot instead of when it arrives, and let the re-read cost decide the
order among the requests that wait.

The router would keep one pending pool. When a replica frees a slot, it takes the waiting request that would read the
fewest prompt tokens again on that replica (the prefix bookkeeping is read at that moment, not at arrival). A request
that has waited longer than 60 seconds goes first whatever it costs, so one whose prompt is cached nowhere cannot wait
forever. A request that was given a card then runs as before.

This is opt-in ("replica_pull": true), so the default path stays as it is.

Tradeoffs

  • A request that was given a card keeps it: it is not moved when the other card frees up later.
  • A conversation that changes card reads its own history again. The shared part of a prompt is counted for the card
    that holds it, so a session whose prompt is cached on no card pays a full read on the card it is given. Deciding that
    the shared part is shared is a separate change and needs the session identity or a client-declared strata_prefix.
  • The first request on a card is slower: its experts are not in that card's VRAM yet and have to be fetched over PCIe.
  • The pool is bounded by the server's admission cap (max_queue), not by the pull scheduler.
  • queue_timeout is not checked on this path; it is only checked on the single-slot queue.

Measured on the same box, same build

2x RTX 4090 (Linux, WSL2), engine 0.1.53, Qwen3.8-Flash-Next UD-Q4_K_XL, 262,144-token context,
"replicas": 2, "parallel": 1, two client sessions sending the same ~19,500-token system prompt:

one card at a time with the pull order
cards busy one at 96%, the other at 0-1% both at 97-99%
a second request with the same 19,500-token prompt prefix cached (544 tokens read), first token after 60 s the two requests ran on the two cards; the one that found no free slot waited 16.8 s for one, then started
output tokens per second, both cards 60 90-130

A controlled run with two requests that share a 26,987-token prefix and differ only in their last word, sent at the
same time: without the pull order both requests go to one card and the second one waits for the first one's whole turn
(first token after 5.6 s); with it they go to the two cards (first token after 1.5 s).

The pull request

PR #4601 — serve/replicas.py (the scheduler),
serve/server.py (the two config keys, a start-up line, live.replica_pending in /metrics),
serve/test_replicas.py (six tests; the old order is left as it was) and the two documentation pages.

The change is opt-in and the default path is byte-identical: without "replica_pull" a request is still given a card on
arrival and waits there.

I would like to know whether this is the direction you want before it goes further, in particular whether the shared
prefix should also stop counting as affinity in the same change (that needs the session identity, so it may be a
separate one).

<!-- gh-comment-id:6495971044 --> @liangzelong commented on GitHub (Oct 29, 2026): ### My view: the two modes want opposite things The replica router copies the split one, and I think that is the root of it. A **layer split** puts one model over several cards and the cards cooperate on one stream. The conversation's KV is spread over them by layer, so there the router's job is to keep a conversation on the same cards and to read as little of it again as possible: **the reuse comes first**. **Replicas** run a complete model on every card, and every card serves its own conversations. The shared part of a prompt — the system instructions and the tool schemas — can be copied to every card, and a conversation's own history is kept on the one card that holds it. So here the order is the other way round: **use every card first, and keep the reuse inside a card.** A router that pins every request of a framework to the replica that first read its shared prefix leaves one card doing the work and the others idle. That is the split behaviour with more overhead, not the data-parallel one: the cards are not spread over the conversations, they are waiting for them. Copying the shared part to a second card costs one more read there. It buys two cards working at the same time, and the conversations of a framework spread over both. ### What I would do: hand out a card when it has a free slot Give a request to a replica **when it has a free slot** instead of when it arrives, and let the re-read cost decide the order among the requests that wait. The router would keep one pending pool. When a replica frees a slot, it takes the waiting request that would read the fewest prompt tokens again on that replica (the prefix bookkeeping is read at that moment, not at arrival). A request that has waited longer than 60 seconds goes first whatever it costs, so one whose prompt is cached nowhere cannot wait forever. A request that was given a card then runs as before. This is opt-in (`"replica_pull": true`), so the default path stays as it is. **Tradeoffs** - A request that was given a card keeps it: it is not moved when the other card frees up later. - A conversation that changes card reads its own history again. The shared part of a prompt is counted for the card that holds it, so a session whose prompt is cached on no card pays a full read on the card it is given. Deciding that the shared part is shared is a separate change and needs the session identity or a client-declared `strata_prefix`. - The first request on a card is slower: its experts are not in that card's VRAM yet and have to be fetched over PCIe. - The pool is bounded by the server's admission cap (`max_queue`), not by the pull scheduler. - `queue_timeout` is not checked on this path; it is only checked on the single-slot queue. ### Measured on the same box, same build 2x RTX 4090 (Linux, WSL2), engine 0.1.53, Qwen3.8-Flash-Next UD-Q4_K_XL, 262,144-token context, `"replicas": 2`, `"parallel": 1`, two client sessions sending the same ~19,500-token system prompt: | | one card at a time | with the pull order | | --- | --- | --- | | cards busy | one at 96%, the other at 0-1% | both at 97-99% | | a second request with the same 19,500-token prompt | prefix cached (544 tokens read), first token after 60 s | the two requests ran on the two cards; the one that found no free slot waited 16.8 s for one, then started | | output tokens per second, both cards | 60 | 90-130 | A controlled run with two requests that share a 26,987-token prefix and differ only in their last word, sent at the same time: without the pull order both requests go to one card and the second one waits for the first one's whole turn (first token after 5.6 s); with it they go to the two cards (first token after 1.5 s). ### The pull request [PR #4601](https://github.com/Niko1221/Strata/pull/4601) — `serve/replicas.py` (the scheduler), `serve/server.py` (the two config keys, a start-up line, `live.replica_pending` in `/metrics`), `serve/test_replicas.py` (six tests; the old order is left as it was) and the two documentation pages. The change is opt-in and the default path is byte-identical: without `"replica_pull"` a request is still given a card on arrival and waits there. I would like to know whether this is the direction you want before it goes further, in particular whether the shared prefix should also stop counting as affinity in the same change (that needs the session identity, so it may be a separate one).
Author
Owner

@Niko1221 commented on GitHub (Nov 5, 2026):

Thanks for taking the time to report this.

Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.11. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6660760923 --> @Niko1221 commented on GitHub (Nov 5, 2026): Thanks for taking the time to report this. Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.11. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2081
No description provided.