mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #4596] [Engine] replicas: several agents with the same system prompt all queue on one card and the other idles #2081
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2081
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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: therequests queue there one after another, and the other card stays at 0% and never answers them.
The two ways we hit it:
member's request wants the same card.
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
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:
LOAD_TOKENSis 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.
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
"replicas": 2, "parallel": 1, "gpu": [0, 1].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.
GET /metricsand readlive.replicas: theroutedcounts are lopsided and one card stays at 0%.Reproduction status
Reproduced locally
Evidence
GET /metrics:The two cards, same moment: GPU0 at 96% (163 W), GPU1 at 0% (18 W).
One request from that window:
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, andstrata_prefixlets 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.
@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:
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
@github-actions[bot] commented on GitHub (Oct 29, 2026):
Thanks, this follows the format now.
@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
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.max_queue), not by the pull scheduler.queue_timeoutis 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: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_pendingin/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 onarrival 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).
@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:
/reopen. A check runs and either reopens the issue or lists what is still missing.The rules are in CONTRIBUTING.md.