feat(custom-provider): forward session_id as x-session-id HTTP header - #52413
feat(custom-provider): forward session_id as x-session-id HTTP header#52413HyeonjeCho wants to merge 2 commits into
Conversation
874dbe4 to
8bfa45c
Compare
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Clean feature adding session_id forwarding as an x-session-id HTTP header for the custom provider profile (used for self-hosted OpenAI-compatible backends like SGLang, vLLM, Ollama, llamacpp). This enables self-hosted backends to correlate requests by conversation in traffic logs.
Looks Good
build_api_kwargs_extrasnow acceptssession_idparameter and forwards it viaextra_headers- Safe for None/empty session_id (no header emitted)
- 12 test cases covering: session_id header emission, Ollama num_ctx, reasoning disable, combined output, full transport integration
- Minimal diff to production code (3 files, ~10 lines of actual logic)
Note
pr_body.mdis a development artifact committed to the repo. Please remove it before merge.
Reviewed by Hermes Agent (cron)
Custom/Ollama provider profile now forwards session_id to self-hosted OpenAI-compatible backends (SGLang, vLLM, etc.) via the x-session-id HTTP header, enabling request correlation by conversation in traffic logs. Previously build_api_kwargs_extras did not accept session_id at all, so no session header was sent on any request through the custom provider. Follows the existing per-profile pattern (OpenRouter sends x-grok-conv-id for Grok models the same way via extra_headers).
8bfa45c to
29a5bc7
Compare
pr_body.md has already been removed. Thanks! |
When a named custom provider (e.g. custom:glm-4.7) is set via /model switch, agent.provider retains the full slug. get_provider_profile() only registers 'custom', so the lookup returns None and falls through to the legacy path — which does not emit the x-session-id header. Normalize custom:* to custom before the profile lookup so the profile path (and its session_id header injection) is taken for all named custom providers.
|
Thanks for the focused custom-provider correlation feature. The header premise remains valid on current main: Problems
Suggested changes
Automated hermes-sweeper review. |
What does this PR do?
The
customprovider profile (used for self-hosted OpenAI-compatible backends like SGLang, vLLM, Ollama, llamacpp) did not acceptsession_idinbuild_api_kwargs_extras, so no session header was ever sent on any request through the custom provider.This PR forwards
session_idas anx-session-idHTTP header viaextra_headers, enabling self-hosted backends to correlate requests by conversation in traffic logs.Related Issue
Fixes #
Type of Change
Changes Made
• plugins/model-providers/custom/init.py: build_api_kwargs_extras now accepts session_id parameter and forwards it astop_level["extra_headers"] = {"x-session-id": session_id} when present
• tests/plugins/model_providers/test_custom_profile.py: New test file with 12 tests covering session_id header emission, Ollamanum_ctx, reasoning disable, combined output, and full transport integration
• agent/chat_completion_helpers.py: Normalize custom:* slugs (e.g. custom:glm-4.7) to "custom" before get_provider_profile()lookup
Why this is needed: When switching models via /model, Hermes stores the full provider slug (e.g. custom:glm-4.7) inagent.provider. However, get_provider_profile() only registers the bare "custom" key — so the lookup returns None, causing theagent to fall through to the legacy kwargs path which does not inject the x-session-id header. Without this fix, the session_idheader from commit 1 only works at session start (where init_agent resolves provider: "custom"), and breaks after any /modelswitch to a named custom provider.
How to Test
python -m pytest tests/plugins/model_providers/test_custom_profile.py -v --tb=short -o 'addopts=' -n 0x-session-idheader appears in the backend's traffic logsChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs