fix(gateway): carry WebUI delivery context on gateway-backed path too (Codex MUST-FIX on #3324)

#3324 moved the WebUI session/delivery context from a prefill user message into
_webui_ephemeral_system_prompt, but the gateway-backed WebUI chat path built its
own system message from the bare _WEBUI_PROGRESS_PROMPT + prefill helper — which
now returns only recall prefill. That silently dropped connected platforms, home
channels, delivery hints, and session framing on Gateway-routed WebUI chats
(same #3278 data-drop class, on the path the author missed). Build the gateway
request's system message with _webui_ephemeral_system_prompt(surface_context,
config_data=cfg) so the context is preserved. Regression test asserts the
delivery context is present in the gateway system message.
This commit is contained in:
nesquena-hermes committed 2026-06-02 19:42:14 +00:00
1 parent 1630fb8d95
commit 8ad0db5dbe
2 files changed
+30 -7

No files matched your search

+17 -2
View File
@@ -247,15 +247,30 @@ def _run_gateway_chat_streaming(
cfg = get_config()
try:
from api.streaming import (
_WEBUI_PROGRESS_PROMPT,
_load_webui_prefill_context,
_prefill_messages_with_webui_context,
_public_prefill_context_status,
_webui_ephemeral_system_prompt,
)
prefill_context = _load_webui_prefill_context(cfg)
# #3324: the WebUI session/delivery context (connected platforms,
# home channels, delivery hints, session framing) is now carried in
# the ephemeral system prompt rather than a prefill `user` message.
# The gateway-backed path must build the SAME system prompt so that
# context is not silently dropped on Gateway-routed WebUI chats.
_gateway_system_prompt = _webui_ephemeral_system_prompt(
None,
surface_context={
"source": "webui",
"session_id": session_id,
"profile": getattr(s, "profile", None),
"workspace": s.workspace if s is not None else str(workspace),
},
config_data=cfg,
)
prefill_messages = [
{"role": "system", "content": _WEBUI_PROGRESS_PROMPT},
{"role": "system", "content": _gateway_system_prompt},
*_prefill_messages_with_webui_context(prefill_context, cfg),
]
put_gateway_event("context_status", {
+13 -5
View File
@@ -285,15 +285,23 @@ def test_gateway_chat_worker_translates_sse_and_persists_session(tmp_path, monke
assert captured["headers"]["X-hermes-session-key"] == f"webui:{s.session_id}"
assert '"stream": true' in captured["body"]
payload = json.loads(captured["body"])
assert [m["content"] for m in payload["messages"]] == [
streaming._WEBUI_PROGRESS_PROMPT,
# #3324: the gateway path's first system message is now the full WebUI
# ephemeral system prompt (progress prompt + session/delivery context),
# NOT the bare _WEBUI_PROGRESS_PROMPT — otherwise the delivery/session
# context is silently dropped on Gateway-routed WebUI chats.
system_msg = payload["messages"][0]
assert system_msg["role"] == "system"
assert "Final visible assistant replies" in system_msg["content"]
assert "Need script" in system_msg["content"]
# The moved session/delivery context must be present in the system prompt.
assert "Connected Platforms:" in system_msg["content"]
assert "Delivery options for scheduled tasks:" in system_msg["content"]
# The recall prefill + the actual user turn follow the system message.
assert [m["content"] for m in payload["messages"][1:]] == [
"prefill",
"webui session context",
"Say hello",
]
assert payload["messages"][0]["role"] == "system"
assert "Final visible assistant replies" in payload["messages"][0]["content"]
assert "Need script" in payload["messages"][0]["content"]
events = []
while not subscriber.empty():
events.append(subscriber.get_nowait())