Skip to content

The agent that grows with you

fix(gateway): retain alternate and parent source identities

Teknium97fb4756fc1b
diff --git a/gateway/run_busy.py b/gateway/run_busy.py
index 496fa2fc3a8..54d613efe04 100644
--- a/gateway/run_busy.py
+++ b/gateway/run_busy.py
@@ -346,9 +346,11 @@ class GatewayBusySessionMixin:
origin = {
"platform": source.platform.value,
**{key: getattr(source, key) for key in (
- "chat_id", "thread_id", "chat_type", "user_id", "scope_id", "profile"
+ "chat_id", "thread_id", "chat_type", "user_id", "scope_id", "profile",
+ "parent_chat_id", "chat_id_alt", "user_id_alt", "prospective_thread_id",
)},
"message_id": event.message_id,
+ "source_message_id": source.message_id,
}
origin = {key: value for key, value in origin.items() if value not in (None, "")}
# JSON preserves identifiers exactly (including colons/whitespace) instead of
diff --git a/tests/gateway/test_busy_steer_origin.py b/tests/gateway/test_busy_steer_origin.py
index 6019196c800..8705fe6ff41 100644
--- a/tests/gateway/test_busy_steer_origin.py
+++ b/tests/gateway/test_busy_steer_origin.py
@@ -14,7 +14,12 @@ from gateway.session import SessionSource
@pytest.mark.parametrize("route", ["explicit", "priority", "normal", "redirect", "priority_redirect"])
async def test_busy_injection_preserves_original_routing_fields(route):
runner = GatewayRunner(config=GatewayConfig())
- source = SessionSource(platform=Platform.TELEGRAM, chat_id="chat", thread_id="thread", user_id="user")
+ source = SessionSource(
+ platform=Platform.TELEGRAM, chat_id="chat", thread_id="thread", user_id="user",
+ chat_type="group", scope_id="scope", profile="profile", parent_chat_id="parent",
+ chat_id_alt="chat-alt", user_id_alt="user-alt", prospective_thread_id="future-thread",
+ message_id="source-message",
+ )
event = MessageEvent(text="/steer request" if route == "explicit" else "request", source=source, message_id="message")
class Receiver:
@@ -42,6 +47,9 @@ async def test_busy_injection_preserves_original_routing_fields(route):
assert {key: origin[key] for key in ("platform", "chat_id", "thread_id", "user_id", "message_id")} == {
"platform": "telegram", "chat_id": "chat", "thread_id": "thread", "user_id": "user", "message_id": "message",
}
+ for field in ("chat_type", "scope_id", "profile", "parent_chat_id", "chat_id_alt", "user_id_alt", "prospective_thread_id"):
+ assert origin[field] == getattr(source, field)
+ assert origin["source_message_id"] == source.message_id
assert event.text == ("/steer request" if route == "explicit" else "request")