perf: avoid broad message prep deepcopies - #40632
Closed
pedrommaiaa wants to merge 1 commit into
Closed
Conversation
kshitijk4poor
added a commit
to kshitijk4poor/hermes-agent
that referenced
this pull request
Jul 9, 2026
…rite sites Trim the salvaged commit to its two still-valid conversions: - ChatCompletionsTransport.convert_messages (copy-on-write sanitize) - QwenProfile.prepare_messages (copy-on-write normalize + cache_control) Dropped from the original PR: - agent/prompt_caching.py selective-copy: superseded by NousResearch#57229 which already rewrites apply_anthropic_cache_control on current main. - Gemma extra_content narrowing (_model_consumes_thought_signature 'gemini or gemma' -> 'gemini' only) + its two tests: unrelated behavior change reverting deliberate e8c3ac2; belongs in its own PR with its own justification if pursued. Conflict resolution: preserved main's newer timestamp-stripping (NousResearch#47868) inside the copy-on-write path.
kshitijk4poor
added a commit
to kshitijk4poor/hermes-agent
that referenced
this pull request
Jul 9, 2026
Review finding: PR NousResearch#40632's branch had silently dropped gemma-3-27b from the keep-extra_content test loop (part of its Gemma narrowing, which this salvage reverts). Restore main's original coverage so a future narrowing back to Gemini-only fails loudly.
kshitijk4poor
added a commit
that referenced
this pull request
Jul 9, 2026
Trim the salvaged commit to its two still-valid conversions: - ChatCompletionsTransport.convert_messages (copy-on-write sanitize) - QwenProfile.prepare_messages (copy-on-write normalize + cache_control) Dropped from the original PR: - agent/prompt_caching.py selective-copy: superseded by #57229 which already rewrites apply_anthropic_cache_control on current main. - Gemma extra_content narrowing (_model_consumes_thought_signature 'gemini or gemma' -> 'gemini' only) + its two tests: unrelated behavior change reverting deliberate e8c3ac2; belongs in its own PR with its own justification if pursued. Conflict resolution: preserved main's newer timestamp-stripping (#47868) inside the copy-on-write path.
kshitijk4poor
added a commit
that referenced
this pull request
Jul 9, 2026
Review finding: PR #40632's branch had silently dropped gemma-3-27b from the keep-extra_content test loop (part of its Gemma narrowing, which this salvage reverts). Restore main's original coverage so a future narrowing back to Gemini-only fails loudly.
Collaborator
|
Merged via #61133 — your commit was cherry-picked onto current main with your authorship preserved (now 724ab90 on main). Thanks for the contribution! The copy-on-write conversions for Two pieces of this branch were intentionally scoped out (see #61133 for details): the |
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
…rite sites Trim the salvaged commit to its two still-valid conversions: - ChatCompletionsTransport.convert_messages (copy-on-write sanitize) - QwenProfile.prepare_messages (copy-on-write normalize + cache_control) Dropped from the original PR: - agent/prompt_caching.py selective-copy: superseded by NousResearch#57229 which already rewrites apply_anthropic_cache_control on current main. - Gemma extra_content narrowing (_model_consumes_thought_signature 'gemini or gemma' -> 'gemini' only) + its two tests: unrelated behavior change reverting deliberate c1b7532; belongs in its own PR with its own justification if pursued. Conflict resolution: preserved main's newer timestamp-stripping (NousResearch#47868) inside the copy-on-write path.
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
Review finding: PR NousResearch#40632's branch had silently dropped gemma-3-27b from the keep-extra_content test loop (part of its Gemma narrowing, which this salvage reverts). Restore main's original coverage so a future narrowing back to Gemini-only fails loudly.
justemu
pushed a commit
to justemu/hermes-agent
that referenced
this pull request
Jul 18, 2026
…rite sites Trim the salvaged commit to its two still-valid conversions: - ChatCompletionsTransport.convert_messages (copy-on-write sanitize) - QwenProfile.prepare_messages (copy-on-write normalize + cache_control) Dropped from the original PR: - agent/prompt_caching.py selective-copy: superseded by NousResearch#57229 which already rewrites apply_anthropic_cache_control on current main. - Gemma extra_content narrowing (_model_consumes_thought_signature 'gemini or gemma' -> 'gemini' only) + its two tests: unrelated behavior change reverting deliberate e8c3ac2; belongs in its own PR with its own justification if pursued. Conflict resolution: preserved main's newer timestamp-stripping (NousResearch#47868) inside the copy-on-write path.
justemu
pushed a commit
to justemu/hermes-agent
that referenced
this pull request
Jul 18, 2026
Review finding: PR NousResearch#40632's branch had silently dropped gemma-3-27b from the keep-extra_content test loop (part of its Gemma narrowing, which this salvage reverts). Restore main's original coverage so a future narrowing back to Gemini-only fails loudly.
3 tasks
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
…rite sites Trim the salvaged commit to its two still-valid conversions: - ChatCompletionsTransport.convert_messages (copy-on-write sanitize) - QwenProfile.prepare_messages (copy-on-write normalize + cache_control) Dropped from the original PR: - agent/prompt_caching.py selective-copy: superseded by NousResearch#57229 which already rewrites apply_anthropic_cache_control on current main. - Gemma extra_content narrowing (_model_consumes_thought_signature 'gemini or gemma' -> 'gemini' only) + its two tests: unrelated behavior change reverting deliberate e8c3ac2; belongs in its own PR with its own justification if pursued. Conflict resolution: preserved main's newer timestamp-stripping (NousResearch#47868) inside the copy-on-write path.
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
Review finding: PR NousResearch#40632's branch had silently dropped gemma-3-27b from the keep-extra_content test loop (part of its Gemma narrowing, which this salvage reverts). Restore main's original coverage so a future narrowing back to Gemini-only fails loudly.
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
…rite sites Trim the salvaged commit to its two still-valid conversions: - ChatCompletionsTransport.convert_messages (copy-on-write sanitize) - QwenProfile.prepare_messages (copy-on-write normalize + cache_control) Dropped from the original PR: - agent/prompt_caching.py selective-copy: superseded by NousResearch#57229 which already rewrites apply_anthropic_cache_control on current main. - Gemma extra_content narrowing (_model_consumes_thought_signature 'gemini or gemma' -> 'gemini' only) + its two tests: unrelated behavior change reverting deliberate e8c3ac2; belongs in its own PR with its own justification if pursued. Conflict resolution: preserved main's newer timestamp-stripping (NousResearch#47868) inside the copy-on-write path.
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
Review finding: PR NousResearch#40632's branch had silently dropped gemma-3-27b from the keep-extra_content test loop (part of its Gemma narrowing, which this salvage reverts). Restore main's original coverage so a future narrowing back to Gemini-only fails loudly.
randlee
pushed a commit
to randlee/hermes-agent
that referenced
this pull request
Aug 11, 2026
…rite sites Trim the salvaged commit to its two still-valid conversions: - ChatCompletionsTransport.convert_messages (copy-on-write sanitize) - QwenProfile.prepare_messages (copy-on-write normalize + cache_control) Dropped from the original PR: - agent/prompt_caching.py selective-copy: superseded by NousResearch#57229 which already rewrites apply_anthropic_cache_control on current main. - Gemma extra_content narrowing (_model_consumes_thought_signature 'gemini or gemma' -> 'gemini' only) + its two tests: unrelated behavior change reverting deliberate 6d43d01; belongs in its own PR with its own justification if pursued. Conflict resolution: preserved main's newer timestamp-stripping (NousResearch#47868) inside the copy-on-write path.
randlee
pushed a commit
to randlee/hermes-agent
that referenced
this pull request
Aug 11, 2026
Review finding: PR NousResearch#40632's branch had silently dropped gemma-3-27b from the keep-extra_content test loop (part of its Gemma narrowing, which this salvage reverts). Restore main's original coverage so a future narrowing back to Gemini-only fails loudly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This reduces request-prep overhead by replacing broad message-history
deepcopy()calls with targeted copy-on-write behavior.The changed paths only mutate small parts of the outgoing request: provider-only tool call fields, prompt-cache markers, Qwen content normalization, and nested image payloads used during retry recovery. Copying the full message history in those cases is unnecessary, especially in long sessions with tool calls, reasoning metadata, and images.
Local request-prep benchmarks using Hermes-shaped payloads:
9.699ms -> 0.963ms(10.1x faster)0.517ms -> 0.072ms(7.1x faster)1.185ms -> 0.126ms(9.4x faster)This also tightens provider-switch safety:
extra_contentcache_controldoes not leak into shared historyType of Change
Changes Made
agent/transports/chat_completions.py.deepcopy()with targeted request-container copies inagent/prompt_caching.py.deepcopy()with targeted normalization copies inplugins/model-providers/qwen-oauth/__init__.py.How to Test
Result:
270 passedResult:
367 passedResult: passed