Skip to content

feat(load_test): add --session-mode for progressively growing prompts - #131

Open
nithiyn wants to merge 1 commit into
mainfrom
cursor/load-test-session-mode-0883
Open

feat(load_test): add --session-mode for progressively growing prompts#131
nithiyn wants to merge 1 commit into
mainfrom
cursor/load-test-session-mode-0883

Conversation

@nithiyn

@nithiyn nithiyn commented Jul 26, 2026

Copy link
Copy Markdown

The default workload re-sends one fixed prefix, so a prompt cache is either warm for that whole block or not warm at all. Agent traffic instead grows a single conversation a turn at a time, and DeepSeek-V4 only serves a cheap hit when a request is an exact continuation of the previous one, so the two patterns produce very different TTFT.

In session mode each Locust user owns one conversation. A turn appends (-p minus -pcml) tokens of fresh dataset text plus the previous response, and the conversation restarts once the prompt passes 2x -p, which keeps the average request at the requested -p. -pcml only sizes the turns here and is no longer sent to the server, since capping the cacheable prefix at -pcml would leave the later turns re-prefilling what they just cached. Every request in a session carries the same user id so consecutive turns land on the same generator.


Note

Low Risk
Benchmark-only changes with unit tests; default workload is unchanged unless --session-mode is enabled.

Overview
Adds --session-mode to llm_bench so each Locust user runs one growing chat conversation instead of repeating a fixed prompt prefix—closer to agent clients and to cache behavior that only hits on exact continuation (e.g. DSv4).

Each turn sends prior messages plus a new user chunk sized as -p minus -pcml, echoes visible assistant content only (not reasoning) into history, reuses a stable user id for Fireworks session affinity, and resets the thread once estimated prompt size reaches -p. -pcml is not sent to Fireworks in this mode (it only sizes turns). Dataset drawing drops the shared prefix; session_turn is recorded as a metric.

README documents usage; test_session_mode.py covers limits, growth, restart, failed-turn rollback, and session id stability.

Reviewed by Cursor Bugbot for commit dd35067. Bugbot is set up for automated code reviews on this repo. Configure here.

The default workload re-sends one fixed prefix, so a prompt cache is either
warm for that whole block or not warm at all. Agent traffic instead grows a
single conversation a turn at a time, and DeepSeek-V4 only serves a cheap hit
when a request is an exact continuation of the previous one, so the two
patterns produce very different TTFT.

In session mode each Locust user owns one conversation. A turn appends
(-p minus -pcml) tokens of fresh dataset text plus the previous response, and
the conversation restarts once the prompt passes 2x -p, which keeps the average
request at the requested -p. -pcml only sizes the turns here and is no longer
sent to the server, since capping the cacheable prefix at -pcml would leave the
later turns re-prefilling what they just cached. Every request in a session
carries the same user id so consecutive turns land on the same generator.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit dd35067. Configure here.

Comment thread llm_bench/load_test.py
# Prefer the server's prompt count so the estimate re-syncs every turn instead
# of drifting on per-message chat template overhead.
served_prompt_tokens = prompt_tokens or self._history_tokens + self._pending_user_tokens
self._history_tokens = served_prompt_tokens + (completion_tokens or 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

History counts reasoning tokens

Medium Severity

complete_turn grows _history_tokens by full completion_tokens / num_tokens, but the committed assistant message is only assistant_content (visible text, reasoning stripped). On reasoning models those totals include thinking tokens that never enter messages, so sessions hit the 2 * -p restart threshold too early and average prompt length drifts below -p.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit dd35067. Configure here.

@cursor
cursor Bot requested review from divchenko and ishaan-shivhare July 26, 2026 20:14

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Risk: low. Not approving: Cursor Bugbot completed as skipped, and there is an unresolved finding on reasoning-token counting in session history. Assigned reviewers for human review.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

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