From 7f735b4db2967849d935ef4b03bd6933107e48ff Mon Sep 17 00:00:00 2001 From: vominh1919 Date: Tue, 28 Apr 2026 20:31:02 +0700 Subject: [PATCH] fix: return effective session_id after context compression (#16938) When context compression rotates the agent's session_id to a new child session, the API server was still returning the stale parent session_id in the X-Hermes-Session-Id response header. This caused external clients to keep sending the old session_id, loading uncompressed parent history instead of the compressed continuation. Fix: _run_agent() now includes the effective session_id in its result dict, and the response header uses it instead of the original provided session_id. --- gateway/platforms/api_server.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gateway/platforms/api_server.py b/gateway/platforms/api_server.py index d3beb1d1d2..200006b745 100644 --- a/gateway/platforms/api_server.py +++ b/gateway/platforms/api_server.py @@ -1209,7 +1209,9 @@ class APIServerAdapter(BasePlatformAdapter): }, } - response_headers = {"X-Hermes-Session-Id": session_id} + response_headers = { + "X-Hermes-Session-Id": result.get("session_id", session_id), + } if gateway_session_key: response_headers["X-Hermes-Session-Key"] = gateway_session_key return web.json_response(response_data, headers=response_headers) @@ -2483,6 +2485,10 @@ class APIServerAdapter(BasePlatformAdapter): "output_tokens": getattr(agent, "session_completion_tokens", 0) or 0, "total_tokens": getattr(agent, "session_total_tokens", 0) or 0, } + # Include the effective session ID in the result so callers + # (e.g. X-Hermes-Session-Id header) can track compression- + # triggered session rotations. (#16938) + result["session_id"] = getattr(agent, "session_id", session_id) return result, usage return await loop.run_in_executor(None, _run)